def say():
	while(1):
		global k
		global sell
		global buy
		global numvar
		global trading
		price=HuobiService.getPrice()

		price=eval(price)
		ticker=price['ticker']
		sell=round(ticker['sell'],2)
		buy=round(ticker['buy'],2)
		if stage==2 or stage==3:
			if text[1]=='M':
				if text[0]=='B':
					numvar=sell
				if text[0]=='S':
					numvar=buy
			if text[1]=='H':
				numvar=round(((sell+buy)/2),2)
			if text[1]=='B':
				if text[0]=='B':
					numvar=buy
				if text[0]=='S':
					numvar=sell
		global comment
		ordStatus=HuobiService.getOrders(1,GET_ORDERS)
		k=k+1
		if str(ordStatus)=='[]' and trading==1 and k>=6:
			k=0
			trading=0
			comment=comment+'Done!'
		show(text,sell,buy,stage,way,method,numvar,amounttp,offset,comment)
		sleep(0.5)
Exemple #2
0
#coding=utf-8

from Util import *
import HuobiService

if __name__ == "__main__":
    print "提交限价单接口"
    #print HuobiService.buy(1,"2355","0.01",None,None,BUY)
    print "提交市价单接口"
    #print HuobiService.buyMarket(2,"30",None,None,BUY_MARKET)
    print "取消订单接口"
    #print HuobiService.cancelOrder(1,68278313,CANCEL_ORDER)
    print "获取账号详情"
    print HuobiService.getAccountInfo(ACCOUNT_INFO)
    print "查询个人最新10条成交订单"
    print HuobiService.getNewDealOrders(1, NEW_DEAL_ORDERS)
    print "根据trade_id查询order_id"
    #print HuobiService.getOrderIdByTradeId(1,274424,ORDER_ID_BY_TRADE_ID)
    print "获取所有正在进行的委托"
    print HuobiService.getOrders(1, GET_ORDERS)
    print "获取订单详情"
    #print HuobiService.getOrderInfo(1,68278313,ORDER_INFO)
    print "限价卖出"
    #print HuobiService.sell(2,"22.1","0.2",None,None,SELL)
    print "市价卖出"
    #print HuobiService.sellMarket(2,"1.3452",None,None,SELL_MARKET)
amount="0.005"
c=0
ping=0
canned=0

Trade_Pass='******'
def sellit(sellat):
    print ("限价卖出:"+str(sellat))
    print (HuobiService.sell(1,str(sellat),amount,Trade_Pass,None,SELL))
def buyit(buyat):
    print ("限价买入:"+str(buyat))
    print (HuobiService.buy(1,str(buyat),amount,Trade_Pass,None,BUY))

if __name__ == "__main__":
    #print("获取所有正在进行的委托")
    print(HuobiService.getOrders(1,GET_ORDERS))
    while(1):
        sleep(0.3)
        price=HuobiService.getPrice()
        price=eval(price)
        ticker=price['ticker']
        sell=round(ticker['sell'],2)
        buy=round(ticker['buy'],2)
        print('Ask:'+str(sell))
        print('Bid:'+str(buy))
        sellat=round(sell-0.02,2)
        buyat=round(buy+0.02,2)
        spread=(sell*100-buy*100)/100
        print('Spread:'+str(spread))
        ordStatus=HuobiService.getOrders(1,GET_ORDERS)
        if(str(ordStatus)=='[]'):
#coding=utf-8

'''
本程序在 Python 3.3.0 环境下测试成功
使用方法:python HuobiMain.py
'''

from Util import *
import HuobiService

if __name__ == "__main__":
    print ("获取账号详情")
    print (HuobiService.getAccountInfo(ACCOUNT_INFO))
    print ("获取所有正在进行的委托")
    print (HuobiService.getOrders(1,GET_ORDERS))
    print ("获取订单详情")
    print (HuobiService.getOrderInfo(1,68278313,ORDER_INFO))
    print ("限价买入")
    print (HuobiService.buy(1,"1","0.01",None,None,BUY))
    print ("限价卖出")
    print (HuobiService.sell(2,"100","0.2",None,None,SELL))
    print ("市价买入")
    print (HuobiService.buyMarket(2,"30",None,None,BUY_MARKET))
    print ("市价卖出")
    print (HuobiService.sellMarket(2,"1.3452",None,None,SELL_MARKET))
    print ("查询个人最新10条成交订单")
    print (HuobiService.getNewDealOrders(1,NEW_DEAL_ORDERS))
    print ("根据trade_id查询order_id")
    print (HuobiService.getOrderIdByTradeId(1,274424,ORDER_ID_BY_TRADE_ID))
    print ("取消订单接口")
    print (HuobiService.cancelOrder(1,68278313,CANCEL_ORDER))