Example #1
0
void Exchange_BitCurex::secondSlot()
{
    static int sendCounter=0;
    switch(sendCounter)
    {
    case 0:
        if(!isReplayPending(103))sendToApi(103,baseValues.currentPair.currBStrLow.toLatin1()+"/ticker",false);
        break;
    case 1:
        if(!isReplayPending(202))sendToApi(202,"balance/",true,"nonce="+QByteArray::number(++privateNonce));
        break;
    case 2:
        if(!isReplayPending(109))sendToApi(109,baseValues.currentPair.currBStrLow.toLatin1()+'/'+QByteArray::number(lastTradesDate)+"/trades",false);
        break;
    case 3:
        if(!tickerOnly&&!isReplayPending(204))sendToApi(204,"offers/",true,"nonce="+QByteArray::number(++privateNonce));
        break;
    case 4:
        if(isDepthEnabled()&&(forceDepthLoad||!isReplayPending(111)))
        {
            emit depthRequested();
            sendToApi(111,baseValues.currentPair.currBStrLow.toLatin1()+"/"+baseValues.depthCountLimitStr+"/orderbook",false);
            forceDepthLoad=false;
        }
        break;
    case 5:
        if(lastHistory.isEmpty())getHistory(false);
        break;
    default: break;
    }
    if(sendCounter++>=5)sendCounter=0;

	Exchange::secondSlot();
}
void Exchange_BTCChina::getHistory(bool force)
{
	if(tickerOnly)return;
	if(force)lastHistory.clear();
	if(!isReplayPending(208))
	{
		if(historyLastDate.isEmpty())
			sendToApi(208,"getTransactions",true,true,"\"all\",100");
		else
            sendToApi(208,"getTransactions",true,true,"\"all\",1000,0,"+historyLastDate);
	}
}
void Exchange_Cryptsy::secondSlot()
{
	static int infoCounter=0;
	if(userInfoTime.elapsed()>(lastInfoReceived?10000:1000)&&!isReplayPending(202))
	{
		userInfoTime.restart();
		sendToApi(202,baseValues.currentPair.currRequestPair+"/money/info",true,baseValues.httpSplitPackets);
	}

	if(!tickerOnly&&!isReplayPending(204))sendToApi(204,baseValues.currentPair.currRequestPair+"/money/orders",true,baseValues.httpSplitPackets);

	if(depthEnabled&&(forceDepthLoad||/*infoCounter==3&&*/!isReplayPending(111)))
	{
		emit depthRequested();
		sendToApi(111,baseValues.currentPair.currRequestPair+"/money/depth/fetch",false,baseValues.httpSplitPackets);
		forceDepthLoad=false;
	}

	if(!isReplayPending(101))sendToApi(101,baseValues.currentPair.currRequestPair+"/money/order/lag",false,baseValues.httpSplitPackets);
	if((infoCounter==1)&&!isReplayPending(103))sendToApi(103,baseValues.currentPair.currRequestPair+"/money/ticker",false,baseValues.httpSplitPackets);
	if(!isReplayPending(104))sendToApi(104,baseValues.currentPair.currRequestPair+"/money/ticker_fast",false,baseValues.httpSplitPackets);

	if(!isReplayPending(109))sendToApi(109,baseValues.currentPair.currRequestPair+"/money/trades/fetch?since="+lastTradesDateCache,false,baseValues.httpSplitPackets);
	if(lastHistory.isEmpty())
		if(!isReplayPending(208))sendToApi(208,"money/wallet/history",true,baseValues.httpSplitPackets,"&currency=BTC");
	if(!baseValues.httpSplitPackets&&ShibeHttp)ShibeHttp->prepareDataSend();

	if(++infoCounter>9)
	{
		infoCounter=0;
		quint32 syncNonce=(static_cast<quint32>(time(NULL))-1371854884)*10;
		if(privateNonce<syncNonce)privateNonce=syncNonce;
	}
	Exchange::secondSlot();
}
void Exchange_Cryptsy::sell(double apiBtcToSell, double apiPriceToSell)
{
	if(tickerOnly)return;
	QByteArray params="&type=ask&amount_int="+QByteArray::number(apiBtcToSell*qPow(10,baseValues.currentPair.currADecimals),'f',0)+"&price_int="+QByteArray::number(apiPriceToSell*qPow(10,baseValues.currentPair.priceDecimals),'f',0);
	if(debugLevel)logThread->writeLog("Sell: "+params,2);
	sendToApi(307,baseValues.currentPair.currRequestPair+"/money/order/add",true,true,params);
}
void Exchange_Bitstamp::cancelOrder(QByteArray order)
{
	if(tickerOnly)return;
	cancelingOrderIDs<<order;
	if(debugLevel)logThread->writeLog("Cancel order: "+order,2);
	sendToApi(305,"cancel_order/",true,true,"id="+order);
}
void Exchange_Bitstamp::sell(double apiBtcToSell, double apiPriceToSell)
{
	if(tickerOnly)return;
	QByteArray params="amount="+QByteArray::number(apiBtcToSell,'f',baseValues.currentPair.currADecimals)+"&price="+QByteArray::number(apiPriceToSell,'f',baseValues.currentPair.priceDecimals);
	if(debugLevel)logThread->writeLog("Sell: "+params,2);
	sendToApi(307,"sell/",true,true,params);
}