第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Python 中訪問特定屬性時遇到問題

在 Python 中訪問特定屬性時遇到問題

守候你守候我 2022-05-24 09:16:47
模塊: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并且我已經(jīng)嘗試過open_bid['orderID']不可下標的。我是否正在閱讀它只返回價格的功能?
查看完整描述

2 回答

?
郎朗坤

TA貢獻1921條經(jīng)驗 獲得超9個贊

當您遇到這樣的情況時,我建議您使用 Python 內(nèi)省工具,例如dir(open_bid)和type(open_bid)來找出您正在查看的內(nèi)容!


基于對源代碼的快速閱讀,我懷疑您正在查看


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


有關(guān)內(nèi)省 Python 中發(fā)生的事情的方法的更多信息:


https://docs.python.org/3/library/functions.html?highlight=dir#dir

https://docs.python.org/3/library/functions.html?highlight=dir#locals

https://docs.python.org/3/library/functions.html?highlight=dir#globals

https://docs.python.org/3/library/functions.html?highlight=dir#vars

https://docs.python.org/3/library/inspect.html


查看完整回答
反對 回復 2022-05-24
?
慕娘9325324

TA貢獻1783條經(jīng)驗 獲得超4個贊

查看函數(shù)的文檔字符串:


        """

        [{'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'])


查看完整回答
反對 回復 2022-05-24
  • 2 回答
  • 0 關(guān)注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號