コード例 #1
0


#%% trade / account api  ===============

print (u' 获取用户账户信息 ')
pprint (dm.get_contract_account_info())
pprint (dm.get_contract_account_info("BTC"))

print (u' 获取用户持仓信息 ')
pprint (dm.get_contract_position_info())
pprint (dm.get_contract_position_info("BTC"))

print (u' 合约下单 ')
pprint(dm.send_contract_order(symbol='', contract_type='', contract_code='BTC181228', 
                        client_order_id='', price=10000, volume=1, direction='sell',
                        offset='open', lever_rate=5, order_price_type='limit'))


print (u' 合约批量下单 ')
orders_data = {'orders_data': [
               {'symbol': 'BTC', 'contract_type': 'quarter',  
                'contract_code':'BTC181228',  'client_order_id':'', 
                'price':10000, 'volume':1, 'direction':'sell', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'},
               {'symbol': 'BTC','contract_type': 'quarter', 
                'contract_code':'BTC181228', 'client_order_id':'', 
                'price':20000, 'volume':2, 'direction':'sell', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'}]}
pprint(dm.send_contract_batchorder(orders_data))
コード例 #2
0
ファイル: main.py プロジェクト: leoli321/huobi-auto-python
            MA_EMA = MA[len(MA) - 1] > EEMA[len(EEMA) - 1]
        else:
            MA_EMA = MA[len(MA) - 1] <= EEMA[len(EEMA) - 1]

        logger.info('BuyOpen%s%s%s' % (BuyOpen, '购买时机:', MA_EMA))

        print('BuyOpen', BuyOpen, '购买时机:', MA_EMA)
        if MA_EMA:
            # 建立订单 价格:MA[int(size) - 1]
            print(symbol_type, contract_type, int(volume), direction, offset,
                  lever_rate, order_price_type)
            Order = dm.send_contract_order(symbol=symbol_type,
                                           contract_type=contract_type,
                                           contract_code='',
                                           client_order_id='',
                                           price=price,
                                           volume=int(volume),
                                           direction=direction,
                                           offset=offset,
                                           lever_rate=lever_rate,
                                           order_price_type=order_price_type)
            # 打印订单信息
            logger.info("下单返回信息:", Order)
            pprint(Order)
            # 判断订单是否成功
            if Order['status'] == 'error':
                logger.error("下单失败:%s" % Order['err_msg'])
                print(Order['err_msg'])
                break
            elif Order['status'] == 'ok':
                BTC_Trade = True
                Already_Judged = True
コード例 #3
0
class RestClient:
    def __init__(self):
        self.__client = HuobiDM('https://api.hbdm.com',
                                'f2643261-4cfd9d14-ca908a0f-dbye2sf5t7',
                                '34ae74a1-853da993-eac728aa-f812f')

    # 季度合约K线数据
    def get_contract_kline(self, period, start, end, size=150):
        """
        :param symbol  BTC_CW, BTC_NW, BTC_CQ , ...
        :param period: 可选值:{1min, 5min, 15min, 30min, 60min, 4hour, 1day, 1week, 1mon }
        :param size: [1,2000]
        :return:
        """
        params = {
            'symbol': 'BTC_CQ',
            'period': period,
            'start': start,
            'end': end
        }
        if size:
            params['size'] = size

        url = self.__url + '/market/history/kline'
        resp = self.__client.http_get_request(url, params)

        return resp['data']

    # 合约下单
    def send_contract_order(self, price, volume, direction, offset):
        """ 当季合约下单, 
            Args:
            price: 价格.
            volume: 委托数量(张).
            direction: "buy":买 "sell":卖.
            offset: "open":开 "close":平
            order_price_type: 订单报价类型 "limit":限价; "opponent":对手价

            Returns:
            下单结果.
        """
        print(u' 合约下单BTC ', " price =", price, " volume =", volume,
              " direction =", direction, " offset =", offset)
        symbol = 'BTC'
        contract_type = 'quarter'
        client_order_id = ''
        contract_code = ''
        #client_order_id=''
        # direction='buy'
        #offset='open'

        resp = self.__client.send_contract_order(symbol,
                                                 contract_type,
                                                 contract_code,
                                                 client_order_id,
                                                 price,
                                                 volume,
                                                 direction,
                                                 offset,
                                                 lever_rate=5,
                                                 order_price_type='limit')
        return resp['data']

    # 获取用户持仓信息
    def get_contract_position_info(self):
        resp = self.__client.get_contract_position_info('BTC')
        return resp['data']

    # 获取基差数据
    def get_history_base(self):
        resp = self.__client.get_history_base()
        return resp['data']
コード例 #4
0


#%% trade / account api  ===============

print (u' 获取用户账户信息 ')
pprint (dm.get_contract_account_info())
pprint (dm.get_contract_account_info("BTC"))

print (u' 获取用户持仓信息 ')
pprint (dm.get_contract_position_info())
pprint (dm.get_contract_position_info("BTC"))

print (u' 合约下单 ')
pprint(dm.send_contract_order(symbol='', contract_type='', contract_code='BTC181228', 
                        client_order_id='', price=50, volume=1, direction='buy',
                        offset='open', lever_rate=5, order_price_type='limit'))

# {'data': {'order_id': 42652161}, 'status': 'ok', 'ts': 1537270256575}

print (u' 合约批量下单 ')
orders_data = {'orders_data': [
               {'symbol': 'BTC', 'contract_type': 'quarter',  
                'contract_code':'BTC181228',  'client_order_id':'', 
                'price':1, 'volume':1, 'direction':'buy', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'},
               {'symbol': 'BTC','contract_type': 'quarter', 
                'contract_code':'BTC181228', 'client_order_id':'', 
                'price':2, 'volume':2, 'direction':'buy', 'offset':'open', 
                'leverRate':5, 'orderPriceType':'limit'}]}
pprint(dm.send_contract_batchorder(orders_data))