I am building a stock trading bot that can trade stocks for me based on my strategies. Right now I am just setting up the stock picking feature.
I keep getting "TypeError: the JSON object must be str, bytes or bytearray, not 'dict'"
or "TypeError: string indices must be integers"
when I try json.loads or json.dumps
I would like to pull just the "lastPrice" from this json response. In this case lastPrice would be 135.87
This is what I got:
data = content.json()
Json Data (pulled from broker's api)
{'WBC': {'assetType': 'EQUITY', 'assetMainType': 'EQUITY', 'cusip': '92927K102', 'symbol': 'WBC', 'description': 'Wabco Holdings Inc. Common Stock', 'bidPrice': 135.76, 'bidSize': 100, 'bidId': 'K', 'askPrice': 136.1, 'askSize': 2000, 'askId': 'P', 'lastPrice': 135.87, 'lastSize': 66100, 'lastId': 'N', 'openPrice': 135.77, 'highPrice': 135.95, 'lowPrice': 135.77, 'bidTick': ' ', 'closePrice': 135.79, 'netChange': 0.08, 'totalVolume': 482625, 'quoteTimeInLong': 1579903320193, 'tradeTimeInLong': 1579908600006, 'mark': 135.87, 'exchange': 'n', 'exchangeName': 'NYSE', 'marginable': True, 'shortable': True, 'volatility': 0.006, 'digits': 2, '52WkHigh': 146.675, '52WkLow': 108.09, 'nAV': 0.0, 'peRatio': 21.29, 'divAmount': 0.0, 'divYield': 0.0, 'divDate': '', 'securityStatus': 'Normal', 'regularMarketLastPrice': 135.87, 'regularMarketLastSize': 661, 'regularMarketNetChange': 0.08, 'regularMarketTradeTimeInLong': 1579908600006, 'netPercentChangeInDouble': 0.0589, 'markChangeInDouble': 0.08, 'markPercentChangeInDouble': 0.0589, 'regularMarketPercentChangeInDouble': 0.0589, 'delayed': True}}
trying to print just 135.87
val = json.loads(data)
print(val['lastPrice'])