-1

I am new to python and learning it in bits and peices from internet. I have been tring to get a volume monitor for binance volumes.

for x in range(len(name)):
    # Code to get the data into panda dataframes for each token in name[] 
    hrlyvol = res1["volume"].iloc[0]
    min_2vol = res1["volume"].iloc[-1]
    actvol = hrlyvol - min_2vol
    voldiff = hrlyvol/actvol
    volch = voldiff-1
    op_price = res1["open"].iloc[0]
    cl_price = res1["close"].iloc[-1]
    price_change = (cl_price-op_price)/op_price
    
    if volch > 0.05 or price_change > 0.02:
    
        print("Volume is up by {:.0%} and Price has changed by {:.0%} in {}".format(
            volch, price_change, name[x]))
        time.sleep(3)

i tried adding i = i+1 but it then adds for all the tokens that satisfy this rule. what i want is for each token to have a separate counter since not all tokens would satisfy the condition. lets say xyz and abc met the condition then token should be xyz = 1 abc = 1 then if in the next iteration only xyz met the condition then xyz = 2 abc = 1 and so on.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
  • can't you just increment your counter in an if statement? it seems like you already have an example of this... – Michael Delgado Sep 21 '22 at 04:39
  • i think you could define `xyz` `abc` equal to `1` before for loop and update values inside conditional by: `xyz, abc = 1, 1 for x in range(len(name)): if volch > 0.05 or price_change > 0.02: xyz=1. abc=1 # update values xyz+=1 abc+=1` – user11717481 Sep 21 '22 at 05:45
  • thanks will try this out and see how it goes. – Prenesh Kp Sep 21 '22 at 08:01
  • wouldnt that change theinitial list where xyz is stored to 1 and then mess up the whole loop? – Prenesh Kp Sep 21 '22 at 08:09
  • i used a list to capture the tokens inside the conditional statement and then used the python counter() to count the number of occurances. will have to clear the list once it gets big enough. – Prenesh Kp Sep 21 '22 at 08:37

1 Answers1

0

I am using the example of odd number or even number to showcase the condition

i=0
j=0
for n in range(100):
    i = i+1 if n%2 == 0 else i+0
    j = j+1 if n%2 == 1 else j+0