Esempio n. 1
0
double DepthModel::getVolumeByPrice(double price, bool isAsk)
{
    if (priceList.count() == 0)
        return 0.0;

    int currentIndex;
    int outside = 1;

    if (isAsk)
    {
        currentIndex = qUpperBound(priceList.begin(), priceList.end(), price) - priceList.begin();
        --currentIndex;

        if (currentIndex < 0)
            return 0.0;

        if (currentIndex >= priceList.count() - 1 && price > priceList.last())
            outside = -1;
    }
    else
    {
        currentIndex = qLowerBound(priceList.begin(), priceList.end(), price) - priceList.begin();

        if (currentIndex >= priceList.count())
            return 0.0;

        if (currentIndex == 0 && price < priceList[0])
            outside = -1;
    }

    return sizeListAt(currentIndex) * outside;
}
Esempio n. 2
0
double DepthModel::rowSize(int row)
{
	if(grouped&&row<2)return 0.0;
	row-=grouped;
	if(!originalIsAsk)row=priceList.count()-row-1;
	if(row<0||row>=priceList.count())return 0.0;
    return sizeListAt(row);
}
Esempio n. 3
0
double DepthModel::getVolumeByPrice(double price)
{
    if(priceList.count()==0)return 0.0;
    int currentIndex=qUpperBound(priceList.begin(),priceList.end(),price)-priceList.begin();
    if(currentIndex<0)return 0.0;
    if(currentIndex>=priceList.count())currentIndex=priceList.count()-1;
    return sizeListAt(currentIndex)*(currentIndex==priceList.count()-1?-1:1)*(currentIndex==0?-1:1);
}
Esempio n. 4
0
void DepthModel::depthUpdateOrder(DepthItem item)
{
    double price=item.price;
    double volume=item.volume;
	if(price==0.0)return;
	int currentIndex=qLowerBound(priceList.begin(),priceList.end(),price)-priceList.begin();
	bool matchListRang=currentIndex>-1&&priceList.count()>currentIndex;

	if(volume==0.0)
	{//Remove item
		if(matchListRang)
		{
			beginRemoveRows(QModelIndex(), currentIndex+grouped, currentIndex+grouped);
			directionList.removeAt(currentIndex);
			priceList.removeAt(currentIndex);
			volumeList.removeAt(currentIndex);
            sizeListRemoveAt(currentIndex);
            sizePriceList.removeAt(currentIndex);
			priceListStr.removeAt(currentIndex);
			volumeListStr.removeAt(currentIndex);
			sizeListStr.removeAt(currentIndex);
			endRemoveRows();
			somethingChanged=true;
		}
		return;
	}
	if(matchListRang&&priceList.at(currentIndex)==price)
	{//Update
		if(volumeList.at(currentIndex)==volume)return;
		directionList[currentIndex]=volumeList.at(currentIndex)<volume?1:-1;
		volumeList[currentIndex]=volume;
        sizeListAt(currentIndex)=0.0;
        sizePriceList[currentIndex]=0.0;
		priceListStr[currentIndex]=item.priceStr;
		volumeListStr[currentIndex]=item.volumeStr;
		sizeListStr[currentIndex]="0.0";
		somethingChanged=true;
		emit dataChanged(index(currentIndex+grouped,0),index(currentIndex+grouped,columnsCount-1));
	}
	else
	{//Insert
		beginInsertRows(QModelIndex(), currentIndex+grouped, currentIndex+grouped);
		priceList.insert(currentIndex,price);
		volumeList.insert(currentIndex,volume);
		sizeList.insert(currentIndex,volume);
        sizePriceList.insert(currentIndex,volume*price);
		directionList.insert(currentIndex,0);
		priceListStr.insert(currentIndex,item.priceStr);
		volumeListStr.insert(currentIndex,item.volumeStr);
		sizeListStr.insert(currentIndex,item.volumeStr);
		endInsertRows();
		somethingChanged=true;
	}
}
Esempio n. 5
0
void DepthModel::calculateSize()
{
    if (!somethingChanged)
        return;

    somethingChanged = true;

    double maxPrice = 0.0;
    double maxVolume = 0.0;
    double maxTotal = 0.0;

    double totalSize = 0.0;
    double totalPrice = 0.0;

    if (originalIsAsk)
    {
        for (int n = 0; n < priceList.count(); n++)
        {
            int currentRow = n;

            if (!originalIsAsk)
                currentRow = priceList.count() - currentRow - 1;

            totalSize += volumeList.at(currentRow);
            totalPrice += volumeList.at(currentRow) * priceList.at(currentRow);

            sizeListAt(currentRow) = totalSize;
            sizePriceList[currentRow] = totalPrice;
            sizeListStr[currentRow] = JulyMath::textFromDouble(totalSize, qMin(baseValues.currentPair.currADecimals,
                                      baseValues.decimalsTotalOrderBook));

            maxPrice = qMax(maxPrice, priceList.at(currentRow));
            maxVolume = qMax(maxVolume, volumeList.at(currentRow));
            maxTotal = qMax(maxTotal, sizeListAt(currentRow));
        }
    }
    else
    {
        for (int n = priceList.count() - 1; n >= 0; n--)
        {
            int currentRow = n;

            if (originalIsAsk)
                currentRow = priceList.count() - currentRow - 1;

            totalSize += volumeList.at(currentRow);
            totalPrice += volumeList.at(currentRow) * priceList.at(currentRow);
            sizeListAt(currentRow) = totalSize;
            sizePriceList[currentRow] = totalPrice;
            sizeListStr[currentRow] = JulyMath::textFromDouble(totalSize, qMin(baseValues.currentPair.currADecimals,
                                      baseValues.decimalsTotalOrderBook));

            maxPrice = qMax(maxPrice, priceList.at(currentRow));
            maxVolume = qMax(maxVolume, volumeList.at(currentRow));
            maxTotal = qMax(maxTotal, sizeListAt(currentRow));
        }
    }

    widthPrice = 10 + textFontWidth(JulyMath::textFromDouble(maxPrice, baseValues.currentPair.priceDecimals));
    widthVolume = 10 + textFontWidth(JulyMath::textFromDouble(maxVolume, baseValues.currentPair.currADecimals));
    widthSize = 10 + textFontWidth(JulyMath::textFromDouble(maxTotal, baseValues.currentPair.currADecimals));

    widthPrice = qMax(widthPrice, widthPriceTitle);
    widthVolume = qMax(widthVolume, widthVolumeTitle);
    widthSize = qMax(widthSize, widthSizeTitle);

    int sizeColumn = 2;

    if (isAsk)
        sizeColumn = 1;

    emit dataChanged(index(0, sizeColumn), index(priceList.count() - 1, sizeColumn));
}