Ejemplo n.º 1
0
def doWork():
    period_window = 14
    standard_deviation_range = 2
    bbands_opt_width_m = 60
    prices = np.array(HuobiService.get4hHistoryPrice(COINTYPE_LTC, period_window + bbands_opt_width_m), dtype=float)
    if len(prices) < period_window + bbands_opt_width_m:
        print("bar的数量不足,等待下一根bar...")
        return
    upper, middle, lower = talib.BBANDS(prices, timeperiod=period_window, nbdevup=standard_deviation_range, nbdevdn=standard_deviation_range, matype=talib.MA_Type.SMA)
    current_price = HuobiService.getCurrentPrice(COINTYPE_LTC)
    print("当前价格为:%s,上轨为:%s,下轨为:%s" % (current_price, upper[-1], lower[-1]))
    if current_price < lower[-1]:
        print("价格穿越下轨,产生卖出信号")
        account_info = HuobiService.getAccountInfo(ACCOUNT_INFO)
        if float(account_info['available_ltc_display']) > MIN_UNIT_LTC:
            print("正在卖出,卖出数量为%s" % account_info['available_ltc_display'].encode("utf-8"))
            print HuobiService.sellMarket(COINTYPE_LTC, account_info['available_ltc_display'], None, None, SELL_MARKET)
        else:
            print("仓位不足,无法卖出")
    elif current_price > upper[-1]:
        print("价格穿越上轨,产生买入信号")
        account_info = HuobiService.getAccountInfo(ACCOUNT_INFO)
        if float(account_info['available_cny_display']) > MIN_UNIT_LTC * current_price:
            print("正在买入,下单金额为%s元" % account_info['available_cny_display'].encode("utf-8"))
            print HuobiService.buyMarket(COINTYPE_LTC, account_info['available_cny_display'], None, None, BUY_MARKET)
        else:
            print("现金不足,无法下单")
    else:
        print("无交易信号,进入下一根bar")
Ejemplo n.º 2
0
# coding=utf-8
'''
本程序在 Python 3.3.0 环境下测试成功
使用方法:python HuobiMain.py
'''
from huobi import HuobiService
from .Util import *

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))
Ejemplo n.º 3
0
#coding=utf-8

from huobi.Util import *
from huobi 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)