class tradesReport():
def saveBuyٍSelltrade(collection, ticker, buy, sell):
collection= db[collection]
newBuyTrade= {'Symbol': ticker, 'Buy': buy}
buytrade=collection.insert_one(newBuyTrade)
newSelltrade={'Symbol':ticker ,'Sell':sell}
selltrade=collection.insert_one(newSelltrade)
def BUYtrade(collection,ticker,buy):
collection= db[collection]
newBuyTrade= {'Symbol': ticker, 'Buy': buy}
buytrade=collection.insert_one(newBuyTrade)
return buytrade
def Selltrade(collection,ticker,sell):
collection= db[collection]
newSellTrade= {'Symbol': ticker, 'Sell': sell}
selltrade=collection.insert_one(newSellTrade)
return selltrade
def findAllBuyTrades(collection):
tickers= {}
collection= db[collection]
data= collection.find({})
for dt in data:
tickers[dt['Symbol']]= [dt['Symbol'],dt['Buy']]
return tickers
The error is:
tickers[dt['Symbol']]= [dt['Symbol'],dt['buy']]
KeyError: 'buy'
mongodb data
source https://stackoverflow.com/questions/71273715/how-to-fix-keyerror-in-pymongo
Comments
Post a Comment