def get(): global text global stage global way global method global numvar global offset global amounttp global amount global comment global trading while(1): newchar=getch() if newchar=='=': newchar='+' if newchar.encode('utf')!=b'\x7f': if newchar.isdigit() or newchar.isalpha() or newchar==' ' or newchar=='.' or newchar=='+' or newchar=='-' : newchar=newchar.upper() if stage!=8: if len(text)>=3: if stage==3: if newchar.isdigit(): text=text+newchar offsetnum=eval(text[3:len(text)]) offset=round(pfix*offsetnum/100,2) if len(text)==2: if newchar=='+' or newchar=='-': if newchar=='+': pfix=1 if newchar=='-': pfix=-1 text=text+newchar stage=3 offset=0 if len(text)==1: if newchar=='M': text=text+newchar method=newchar if text[0]=='B': numvar=sell if text[0]=='S': numvar=buy stage=2 if newchar=='H': text=text+newchar method=newchar stage=2 numvar=round(((sell+buy)/2),2) if newchar=='B': text=text+newchar method=newchar if text[0]=='B': numvar=buy if text[0]=='S': numvar=sell stage=2 if stage==8: if newchar.isdigit(): text=text+newchar amounttp=float(text[1:len(text)]) if len(text)==0: if newchar=='S' or newchar=='B' : text=text+newchar way=newchar stage=1 if newchar=='A': text=text+newchar way=newchar stage=8 if newchar.encode('utf')==b'\x03': text='QUIT' quit() if newchar.encode('utf')==b'\n': if stage==8 and len(text)>1: amount=round(amounttp/1000,3) if stage==2 or stage==3: p=round(offset+numvar,2) if way=='S': print(HuobiService.sell(1,str(p),amount,PASSWORD,None,SELL)) comment=comment+'\n Sell'+str(amount)+'BTC at'+str(p)+'...' if way=='B': print(HuobiService.buy(1,str(p),amount,PASSWORD,None,BUY)) comment=comment+'\n Buy'+str(amount)+'BTC at'+str(p)+'...' trading=1 offset=0 text='' stage=0 method='' numvar=0 way='' ###Execution else: text=text[0:len(text)-1] if len(text)==0: stage=0 method='' numvar=0 way='' offset=0 if stage!=8: if len(text)==1: stage=1 method='' numvar=0 offset=0 if len(text)==2: stage=2 offset=0 if len(text)>3 and stage==3: offsetnum=eval(text[3:len(text)]) offset=round(pfix*offsetnum/100,2) if len(text)==3 and stage==3: offset=0 if stage==8: if len(text)==1: amounttp=0 else: amounttp=float(text[1:len(text)]) show(text,sell,buy,stage,way,method,numvar,amounttp,offset,comment) #b'\x7f'
import HuobiService import json if __name__ == "__main__": while (True): res = HuobiService.getDepth() res = json.loads(res)['tick'] print('buy :%.2f' % res['bids'][0][0]) print('sell :%.2f' % res['asks'][0][0]) time.sleep(1) 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))
ordType=ordFeedback[0]['type'] print (HuobiService.cancelOrder(1,ordFeedback[0]['id'],CANCEL_ORDER)) if ordType==1: print (HuobiService.buy(1,str(sellat),amount,Trade_Pass,None,BUY)) else: print (HuobiService.sell(1,str(buyat),amount,Trade_Pass,None,SELL)) ''' else: c=0 else: print(ordStatus) ping=ping+1 if ping>=10: print('CANCEL') ping=0 ordFeedback=eval(ordStatus) if len(ordFeedback)==2: print('取消买卖订单') print (HuobiService.cancelOrder(1,ordFeedback[0]['id'],CANCEL_ORDER)) print (HuobiService.cancelOrder(1,ordFeedback[1]['id'],CANCEL_ORDER)) if len(ordFeedback)==1: ordType=ordFeedback[0]['type'] print (HuobiService.cancelOrder(1,ordFeedback[0]['id'],CANCEL_ORDER)) if ordType==1: print (HuobiService.buy(1,str(buyat),amount,Trade_Pass,None,BUY)) else: print (HuobiService.sell(1,str(sellat),amount,Trade_Pass,None,SELL))
def sellit(sellat): print ("限价卖出:"+str(sellat)) print (HuobiService.sell(1,str(sellat),amount,Trade_Pass,None,SELL))
本程序在 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))