【发布时间】:2018-11-29 22:53:37
【问题描述】:
当我尝试以下代码行时
print(self.exchange3.privateGetPosition([{'currentQty'}]))
我收到以下错误
File "c:/Users/User2/sample_market_maker/SAMPLE/botv2.py", line 130, in place_orders
print(self.exchange3.privateGetPosition([{"currentQty"}]))
File "C:\Users\User2\.virtualenvs\sample_market_maker-9Hdi4SL0\lib\site-packages\ccxt\base\exchange.py", line 364, in request
return self.fetch2(path, api, method, params, headers, body)
File "C:\Users\User2\.virtualenvs\sample_market_maker-9Hdi4SL0\lib\site-packages\ccxt\base\exchange.py", line 360, in fetch2
request = self.sign(path, api, method, params, headers, body)
File "C:\Users\User2\.virtualenvs\sample_market_maker-9Hdi4SL0\lib\site-packages\ccxt\bitmex.py", line 577, in sign
query += '?' + self.urlencode(params)
TypeError: can only concatenate str (not "list") to str
当我打印查看可用的嵌套字典时,我得到以下内容
print(self.exchange3.privateGetPosition())
[{'account': 108879, 'symbol': 'XBTUSD', 'currency': 'XBt', 'underlying':
'XBT', 'quoteCurrency': 'USD', 'commission': 0.00075, 'initMarginReq': 0.04,
'maintMarginReq': 0.005, 'riskLimit': 20000000000, 'leverage': 25,
'crossMargin': False, 'deleveragePercentile': None, 'rebalancedPnl': 0,
'prevRealisedPnl': -18679, 'prevUnrealisedPnl': 0, 'prevClosePrice':
4348.84, 'openingTimestamp': '2018-11-29T20:00:00.000Z', 'openingQty': 0,
'openingCost': 0, 'openingComm': 0, 'openOrderBuyQty': 0,
'openOrderBuyCost': 0, 'openOrderBuyPremium': 0, 'openOrderSellQty': 0,
'openOrderSellCost': 0, 'openOrderSellPremium': 0, 'execBuyQty':
0, 'execBuyCost': 0, 'execSellQty': 0, 'execSellCost': 0, 'execQty': 0,
'execCost': 0, 'execComm': 0, 'currentTimestamp': '2018-11-
29T20:00:00.369Z', 'currentQty': 0, 'currentCost': 0, 'currentComm': 0,
'realisedCost': 0, 'unrealisedCost': 0, 'grossOpenCost': 0,
'grossOpenPremium': 0, 'grossExecCost': 0, 'isOpen': False, 'markPrice':
None, 'markValue': 0, 'riskValue': 0, 'homeNotional': 0, 'foreignNotional':
0, 'posState': '', 'posCost': 0, 'posCost2': 0, 'posCross': 0, 'posInit': 0,
'posComm': 0, 'posLoss': 0, 'posMargin': 0, 'posMaint': 0, 'posAllowance':
0, 'taxableMargin': 0, 'initMargin': 0, 'maintMargin': 0, 'sessionMargin':
0, 'targetExcessMargin': 0, 'varMargin': 0, 'realisedGrossPnl': 0,
'realisedTax': 0, 'realisedPnl': 0, 'unrealisedGrossPnl': 0, 'longBankrupt':
0, 'shortBankrupt': 0, 'taxBase': 0, 'indicativeTaxRate': 0,
'indicativeTax': 0, 'unrealisedTax': 0, 'unrealisedPnl': 0,
'unrealisedPnlPcnt': 0, 'unrealisedRoePcnt': 0, 'simpleQty': None,
'simpleCost': None, 'simpleValue': None, 'simplePnl': None, 'simplePnlPcnt':
None, 'avgCostPrice': None, 'avgEntryPrice': None,
'breakEvenPrice': None, 'marginCallPrice': None, 'liquidationPrice': None,
'bankruptPrice': None, 'timestamp': '2018-11-29T20:00:00.369Z', 'lastPrice':
None, 'lastValue': 0}]
有人知道我做错了什么,我正在尝试获取 currentQty 值吗? 这是python37
【问题讨论】:
-
您的方法需要一个字符串而不是列表。
print(self.exchange3.privateGetPosition([{'currentQty'}])发送一个列表,其中包含一组包含您需要的字符串。你应该试试print(self.exchange3.privateGetPosition("currentQty")。但是如果没有看到有问题的方法,很难确定 -
我仍然得到上面打印的完整列表
-
print(str(self.exchange3.privateGetPosition()[0]['currentQty']))怎么样? -
欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确描述问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您描述的问题。
-
@Srini 解释了错误消息。如果没有支持代码,我们只能猜测底层数据结构。
标签: python python-3.x algorithm bitmex ccxt