I am very unexperienced with Python but I managed to build a full code for what I need. However, what I believe to be my now last step is to solve this issue i am having with the following message: TypeError: 'NoneType' object is not subscriptable the issue here is I am having a key on the JSON file which ceases to have the particular data I am looking for in the other coins. How can i solve this? or drop the corresponding array?
Can you give me any suggestion? :(
def sell_coins():
last_price = get_price()
for coin in coins_bought:
if coins_bought[coin]["status"]=="FILLED":
TP = float(coins_bought[coin]["bought_at"]) + (float(coins_bought[coin]["bought_at"]) * TAKE_PROFIT) / 100
SL = float(coins_bought[coin]["bought_at"]) - (float(coins_bought[coin]["bought_at"]) * STOP_LOSS) / 100
if float(last_price[coin]["lastPrice"]) > TP or float(last_price[coin]["lastPrice"]) < SL:
print("TP or SL reached selling", {coins_bought[coin]["volume"]}, {coin})
sell_limit = client.futures_create_order(
symbol=coin,
side="SELL",
type="MARKET",
quantity=coins_bought[coin]["volume"])
else:
coins_bought[coin] = None
with open(coins_bought_file_path, "w") as file:
json.dump(coins_bought, file, indent=4)
print("No additional coin to buy or to sell")
JSON File: (This is the problem is I am setting this to null/none { "SFPUSDT": null }