Ejemplo n.º 1
0
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"))

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',  
Ejemplo n.º 2
0
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']

    except:
Ejemplo n.º 3
0
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"))

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': [
Ejemplo n.º 4
0
symb = 'BTC'                                       # BTC ETF ---- BTC_CW, BTC_NW, BTC_CQ , ...  
type = 'quarter'


print('>>>>>>>>>>>>>>>>>>>>>>转账>>>>>>>>>>>>>>>>>>>>>>')
## 法币交易购买USDT,币币交易购买BTC/USDT,BTC由币币账户转入合约账户
## 法币交易购买BTC,BTC由币币账户转入合约账户
initial_eqt = 0.1    # 初始转入0.1颗币


print('>>>>>>>>>>>>>>>>>>>>>>参数设置>>>>>>>>>>>>>>>>>>>>>>')
path = 'G:/BTC/python_huobi/REST_Python35_demo/github_files/'   # 数据保存路径
params = {'w1':50,'w2':5,'w3':20,'stop_loss':1,'big_float':np.inf,'draw_back':np.inf,'add':0.5,'max_add_times':2,'risk_ratio':0.005}
lvg = 5
wait_num = 5
freq = '15min'


print('>>>>>>>>>>>>>>>>>>>>>>开始交易>>>>>>>>>>>>>>>>>>>>>>')
contract_codes = []
pnls = []
contract_code,pnl = main(dm,symb,type,params,initial_eqt=initial_eqt,lvg=lvg,wait_num=wait_num,freq=freq)
contract_codes.append(contract_code)
pnls.append(pnl)
while 1:
    """ 两次循环间隔1个季度 """
    account_info = dm.get_contract_account_info(symbol=symb)  # 账户信息
    account_info = account_info['data'][0]
    asset = account_info['margin_balance']                    # 账户权益
    contract_code,pnl = main(dm,symb,type,params,initial_eqt=asset,lvg=lvg,wait_num=wait_num,freq=freq)