簡體   English   中英

TypeError:只能將str(而不是“ list”)連接到str

[英]TypeError: can only concatenate str (not “list”) to str

當我嘗試以下代碼行時

 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

正確的方法是:

positions = self.exchange3.privateGetPosition()
print(positions[0]['currentQty'])

關於它的更多信息:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM