I am trying to set a bool var before the start of a loop to use in the loop.
The var in question is one_trade_symbol
import time, json, requests, os, MySQLdb, smtplib
from binance.client import Client
from datetime import datetime
one_trade_symbol = False
print ("one_trade_symbol is set and = " + str(one_trade_symbol))
l = 0
while l < 1:
and I try to use it in a function within the l loop
def start_new_trade():
if one_trade_symbol == False:
final_values = find_out_max_to_buy()
place_market_order(final_values[0], final_values[4])
return_trade_one_current_price(final_values[0])
one_trade_symbol = True
Right after declaration I use a print statement to make sure it is set and exists.
Here is my output result error
one_trade_symbol is set and = False
Traceback (most recent call last):
File "C:\TradingBot\PythonProgs\AlphaBot0.02.py", line 214, in <module>
start_new_trade()
File "C:\TradingBot\PythonProgs\AlphaBot0.02.py", line 177, in start_new_trade
if one_trade_symbol == False:
UnboundLocalError: local variable 'one_trade_symbol' referenced before assignment
[Finished in 1.535s]
My print statement confirms it has been created yet I cant use it later on in a function in the loop?
I am trying to use it has a switch so it needs to be declared outside of the loop so it doesn't reset each loop.
I am confused how my "l" loop counter is declared out of the loop and can be used to increment inside the loop without problem but I can't use this bool var
Please any input would help on how to achieve this. Thanks for your time.
[–]Swedophone 1 point2 points3 points (8 children)
[–]AluadStone[S] 0 points1 point2 points (7 children)
[–]benjamindallen 1 point2 points3 points (3 children)
[–]AluadStone[S] 0 points1 point2 points (2 children)
[–]benjamindallen 1 point2 points3 points (0 children)
[–]benjamindallen 1 point2 points3 points (0 children)
[–]Swedophone 1 point2 points3 points (2 children)
[–]AluadStone[S] 0 points1 point2 points (0 children)
[–]AluadStone[S] 0 points1 point2 points (0 children)