1

模块:https ://github.com/yanagisawa-kentaro-777/pybitmex/blob/master/pybitmex/bitmex.py

我正在使用ws_open_order_objects_of_account()它,我可以访问:

open_orders = bitmex.ws_open_order_objects_of_account()
for open_bid in open_orders.bids:
    print(open_bid.price)

但我想要open_bid.orderID并且我已经尝试过open_bid['orderID']不可下标的。我是否正在阅读它只返回价格的功能?

4

2 回答 2

3

当您遇到这样的情况时,我建议您使用 Python 内省工具,例如dir(open_bid)type(open_bid)来找出您正在查看的内容!

基于对源代码的快速阅读,我怀疑您正在查看

class OpenOrder:

    def __init__(self, order_id, client_order_id, side, quantity, price, timestamp):
        self.order_id = order_id
        self.client_order_id = client_order_id
        self.side = side
        self.quantity = quantity
        self.price = price
        self.timestamp = timestamp

    def __str__(self):
        return "Side: {}; Quantity: {:d}; Price: {:.1f}; OrderID: {}; ClOrdID: {}; Timestamp: {}; ".format(
            self.side, self.quantity, self.price, self.order_id, self.client_order_id,
            self.timestamp.strftime("%Y%m%d_%H%M%S")
        )

所以你可能想要open_bid.order_id

https://github.com/yanagisawa-kentaro-777/pybitmex/blob/08e6c4e7ae7bbadd5208ec01fd8d361c3a0ce992/pybitmex/models.py#L33

有关内省 P​​ython 中发生的事情的方法的更多信息:

于 2019-09-10T20:44:26.560 回答
0

查看函数的文档字符串:

        """
        [{'orderID': '57180f5f-d16a-62d6-ff8d-d1430637a8d9',
        'clOrdID': '', 'clOrdLinkID': '',
        'account': XXXXX, 'symbol': 'XBTUSD', 'side': 'Sell',
        'simpleOrderQty': None,
        'orderQty': 30, 'price': 3968,
        'displayQty': None, 'stopPx': None, 'pegOffsetValue': None,
        'pegPriceType': '', 'currency': 'USD', 'settlCurrency': 'XBt',
        'ordType': 'Limit', 'timeInForce': 'GoodTillCancel',
        'execInst': 'ParticipateDoNotInitiate', 'contingencyType': '',
        'exDestination': 'XBME', 'ordStatus': 'New', 'triggered': '',
        'workingIndicator': True, 'ordRejReason': '', 'simpleLeavesQty': None,
        'leavesQty': 30, 'simpleCumQty': None, 'cumQty': 0, 'avgPx': None,
        'multiLegReportingType': 'SingleSecurity', 'text': 'Submission from www.bitmex.com',
        'transactTime': '2019-03-25T07:10:34.290Z', 'timestamp': '2019-03-25T07:10:34.290Z'}]
        """

这表明它返回一个字典列表,而不是一个对象。没有bids您需要访问的属性。

open_orders = bitmex.ws_open_order_objects_of_account()
for order in open_orders:
    print(order['price'])
于 2019-09-10T20:47:21.373 回答