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')) print (u' 获取K线数据 ') pprint (dm.get_contract_kline(symbol='BTC_CW', period='60min', size=20)) print (u' 获取聚合行情 ') pprint (dm.get_contract_market_merged('BTC_CW')) print (u' 获取市场最近成交记录 ') pprint (dm.get_contract_trade('BTC_CW')) print (u' 批量获取最近的交易记录 ') pprint (dm.get_contract_batch_trade(symbol='BTC_CW', size=3)) #%% 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"))
#### input huobi dm url URL = 'https://api.btcgateway.pro' #### 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' 获取市场价格 ') priceInfo = dm.get_contract_trade(symbol="XRP_CQ") pprint(priceInfo) if priceInfo['status'] != "ok": print("get price failed") exit(2) currPrice = float(priceInfo['tick']['data'][0]['price']) if currPrice is None or currPrice < 0: print("price invalid") exit(0) print("current price is %s" % currPrice) step = currPrice / 100