예제 #1
0
####  input your access_key and secret_key below:
ACCESS_KEY = ''
SECRET_KEY = ''

dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY)

#### another account:
#dm2 = HuobiDM(URL, "ANOTHER ACCOUNT's ACCESS_KEY", "ANOTHER ACCOUNT's SECRET_KEY")




#%%  market data api ===============

print (u' 获取合约信息 ')
pprint (dm.get_contract_info(symbol="BTC", contract_type="quarter"))
pprint (dm.get_contract_info(contract_code="BTC181228"))

print (u' 获取合约指数信息 ')
pprint (dm.get_contract_index("BTC"))

print (u' 获取合约最高限价和最低限价 ')
pprint (dm.get_contract_price_limit(symbol='BTC', contract_type='quarter'))
pprint (dm.get_contract_price_limit(contract_code='BTC181228'))

print (u' 获取当前可用合约总持仓量 ')
pprint (dm.get_contract_open_interest(symbol='BTC', contract_type='quarter'))
pprint (dm.get_contract_open_interest(contract_code='BTC181228'))

print (u' 获取行情深度数据 ')
pprint (dm.get_contract_depth(symbol='BTC_CW', type='step0'))
ACCESS_KEY = ''
SECRET_KEY = ''


dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY)

#### another account:
#dm2 = HuobiDM(URL, "ANOTHER ACCOUNT's ACCESS_KEY", "ANOTHER ACCOUNT's SECRET_KEY")




#%%  market data api ===============

print (u' 获取合约信息 ')
pprint (dm.get_contract_info(symbol="BTC", contract_type="quarter"))
pprint (dm.get_contract_info(contract_code="BTC181228"))

print (u' 获取合约指数信息 ')
pprint (dm.get_contract_index("BTC"))

print (u' 获取合约最高限价和最低限价 ')
pprint (dm.get_contract_price_limit(symbol='BTC', contract_type='quarter'))
pprint (dm.get_contract_price_limit(contract_code='BTC181228'))

print (u' 获取当前可用合约总持仓量 ')
pprint (dm.get_contract_open_interest(symbol='BTC', contract_type='quarter'))
pprint (dm.get_contract_open_interest(contract_code='BTC181228'))

print (u' 获取行情深度数据 ')
pprint (dm.get_contract_depth(symbol='BTC_CW', type='step0'))
예제 #3
0
URL = 'https://api.btcgateway.pro'
ACCESS_KEY = ''
SECRET_KEY = ''
count = 0
retryCount = 0

id_30 = 0

while (1):
    try:
        dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY)
        kline_30min = (dm.get_contract_kline(symbol='ETH_CQ',
                                             period='30min',
                                             size=300))['data']

        contract_info = dm.get_contract_info(symbol="ETH",
                                             contract_type="quarter")['data']
        contract_size = contract_info[0]['contract_size']
        contract_account_info = dm.get_contract_account_info("ETH")['data']
        account_info['margin_available'] = contract_account_info[0][
            'margin_available']
        account_info['margin_frozen'] = contract_account_info[0][
            'margin_position']
        contract_position_info = dm.get_contract_position_info("ETH")['data']
        if contract_position_info == []:
            account_info['volume'] = 0
            account_info['direction'] = 0
            last_price = kline_30min[-1]['close']
        else:
            account_info['volume'] = contract_position_info[0]['available']
            account_info['direction'] = contract_position_info[0]['direction']
            last_price = contract_position_info[0]['last_price']