老虎证券开放api期货合约建立

目前老虎证券开放api有比较方便的股票和期权的contract建立方法,详见官网接入文档。期货的contract需要自己建立,目前实测不能交易,只能建立order,不能place order。
下面是买入一手微黄金的代码

    future='MGC'
    contract = quote_client.get_current_future_contract(future)
    contract = future_contract(future, contract.currency[0], contract.last_trading_date[0], multiplier=contract.multiplier[0])
    order = openapi_client.create_order(client_config.account, contract, 'BUY', 'LMT', 1, limit_price=0.1)
    openapi_client.place_order(order)

下面是返回信息,账号隐去

Order({'order_time': None, 'account': '********', 'filled': 0, 'action': 'BUY', 'parent_id': None, 'reason': None, 'contract': MGC/FUT/USD, 
    'order_id': 121, 'time_in_force': None, 'remaining': 1, 'quantity': 1, 'avg_fill_price': 0, 'status': 'NEW',
     'id': None, 'aux_price': None, 'trail_stop_price': None, 'trailing_percent': None,
     'percent_offset': None, 'trade_time': None, 'limit_price': 0.1, 'realized_pnl': None, 'order_type': 'LMT', 'outside_rth': None, 'commission': None})
INFO [7695ec70-5489-11e9-9fb2-000c298838ac]request:https://openapi.itiger.com/gateway?biz_content={"account":"********","action":"BUY",
     "currency":"USD","expiry":"20190626","limit_price":0.1,"multiplier":10.0,
      "order_id":121,"order_type":"LMT","sec_type":"FUT","symbol":"MGC","total_quantity":1}
response:{"code":20013,"data":"{\"id\":158967014791581696,\"orderId\":121}",
      "message":"trade system not available"

终端报异常信息:

Traceback (most recent call last):
  File "strategy.py", line 265, in <module>
    future_apis()
  File "strategy.py", line 238, in future_apis
    openapi_client.place_order(order)
  File "/home/han/miniconda2/envs/python35/lib/python3.5/site-packages/tigeropen/trade/trade_client.py", line 257, in place_order
    raise ApiException(response.code, response.message)
tigeropen.common.exceptions.ApiException: code=20013 msg=trade system not available

最新期货合约投放进展,原来不是不行,用环球账户就可以

from tigeropen.trade.domain.contract import Contract
    future='MGC'
    contract = quote_client.get_current_future_contract(future)
    print(contract)
    fut_contract = Contract(symbol=future, currency=contract.currency[0], sec_type = 'FUT' ,expiry=contract.last_trading_date[0],\
                        multiplier=contract.multiplier[0],exchange=contract.exchange[0])
    order = openapi_client.create_order(account, fut_contract, 'BUY', 'MKT', 1)
    openapi_client.place_order(order)
   # print(order)
    #new_order = openapi_client.get_orders(account=account)
   # print(new_order[:5])

使用上面的代码可以下单成功,这里需要注意的是contract要从底层开始获取来建立contract,sec_type要明确指定,否则它回去买一个名字叫‘MGC’的股票。
如果剩余的资金不够,那么会报一个提交订单被拒的错误

‘status’: ‘REJECTED’,‘reason’: ‘201:Order rejected - Reason: YOUR COMMODITY ACCOUNT LIQUIDATION VALUE PLUS EXCESS EQUITY MUST BE AT LEAST 2000.00USD (OR EQUIVALENT IN OTHER CURRENCIES) TO EXECUTE THIS ORDER. YOU CAN ONLY CLOSEOUT Y’

对于上面的商品期货的理解,我去问了老虎量化的技术指导,得知:商品期货账户不是指老虎期货的账户,环球账户因为合规原因,会区分虚拟的证券账户和商品账户,每个虚拟账户有各自的风控要求。
比较坑的是使用老虎环球账户下单买一手MGC,盈透后台可以看到手续费是5.21刀,而如果直接在老虎期货上买只需要3刀多一点,另外结算下来好像老虎证券手续费不止5.21刀,从我粗略计算可能高达10刀,而且是双向的。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值