TypeError: can only concatenate str (not "list") to str

Varun Reddy picture Varun Reddy · Nov 29, 2018 · Viewed 8.6k times · Source

when i try the following line of code

 print(self.exchange3.privateGetPosition([{'currentQty'}]))

i get the the following error

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

when I print to see the available nested dict, i get the following

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}]

Anybody know what I am doing wrong, I am trying the get the currentQty value? This is python37

Answer

Igor Kroitor picture Igor Kroitor · Nov 30, 2018

The proper way to do it:

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

More about it: