1

我正在使用IbPy读取当前订单。返回以使用EWrapper 方法处理的响应消息具有一些似乎属于错误类型的属性。

首先,这是我的订单相关消息处理程序。它旨在捕获由于调用reqAllOpenOrders().

from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.ext.OrderState import OrderState

_order_resp = dict(openOrderEnd=False, openOrder=[], openStatus=[])

def order_handler(msg):
    """ Update our global Order data response dict
    """
    global _order_resp
    if msg.typeName in ['openStatus', 'openOrder']:
        d = dict()
        for i in msg.items():
            if isinstance(i[1], (Contract, Order, OrderState)):
                d[i[0]] = i[1].__dict__
            else:
                d[i[0]] = i[1]
        _order_resp[msg.typeName].append(d.copy())
    elif msg.typeName == 'openOrderEnd':
        _order_resp['openOrderEnd'] = True
    log.info('ORDER: {})'.format(msg))

在上面的代码中,我将所有对象及其属性加载到 dict 中,然后将其附加到_order_resp.

日志输出行显示与 IB 的健康交互:

25-Jan-16 14:57:04 INFO      ORDER: <openOrder orderId=1, contract=<ib.ext.Contract.Contract object at 0x102a98150>, order=<ib.ext.Order.Order object at 0x102a98210>, orderState=<ib.ext.OrderState.OrderState object at 0x102a98350>>)
25-Jan-16 14:57:04 INFO      ORDER: <orderStatus orderId=1, status=PreSubmitted, filled=0, remaining=100, avgFillPrice=0.0, permId=1114012437, parentId=0, lastFillPrice=0.0, clientId=0, whyHeld=None>)
25-Jan-16 14:57:04 INFO      ORDER: <openOrderEnd>)

但是当查看放入_order_resp字典的数据时,看起来有些数字是关闭的:

    {
        "contract": {
            "m_comboLegsDescrip": null,
            "m_conId": 265598,
            "m_currency": "USD",
            "m_exchange": "SMART",
...
        },
        "order": {
            "m_account": "DU12345",
            "m_action": "SELL",
            "m_activeStartTime": "",
            "m_activeStopTime": "",
            "m_algoStrategy": null,
            "m_allOrNone": false,
            "m_auctionStrategy": 0,
            "m_auxPrice": 0.0,
            "m_basisPoints": 9223372036854775807,
            "m_basisPointsType": 9223372036854775807,
...
        },
        "orderId": 1,
        "orderState": {
            "m_commission": 9223372036854775807,
            "m_commissionCurrency": null,
            "m_equityWithLoan": "1.7976931348623157E308",
            "m_initMargin": "1.7976931348623157E308",
            "m_maintMargin": "1.7976931348623157E308",
            "m_maxCommission": 9223372036854775807,
            "m_minCommission": 9223372036854775807,
...
        }
    }
],
"openOrderEnd": true,

在源代码中,我们看到它m_maxCommission是 a float(),但它的值看起来像一个 int,并且比大多数人喜欢支付的佣金要大得多。

其他一些键像m_equityWithLoan具有字符串类型值,但源代码说这是正确的。

如何解决我得到大整数而不是浮点数的情况?是否可以从内存中读取值并将其重新解释为浮点数?这是盈透证券 API 问题吗?

4

0 回答 0