Python Forum
While Loop Variable Freezing?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While Loop Variable Freezing?
#7
It looks like you're using the Interactive Brokers' api. I happen to know, from previously working with it, that the IB client pushes constant streams of data to you. So try to think of what you want to do at that specific point in time.

def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL):
        print("UnrealizedPnL:", round(unrealizedPnL))
        if unrealizedPnL < -100:
            print("Step 1", unrealizedPnL)
            if unrealizedPnL < -50:
                print("Step 1.5", unrealizedPnL)
            else:
                print("Step 2, Worked", unrealizedPnL)
Looks like you're trying to do something as the p&l increases over time. In that case, maybe you should keep track of the values as you see them, and compare them with new values as you see them.

Maybe like this?
def __init__(self):
    self.unrealized_pnl = []

def pnl(self, reqId, dailyPnL, unrealizedPnL, realizedPnL):
    if not self.unrealized_pnl:
        # this is the first time we've received data
        pass
    else:
        min_value = min(self.unrealized_pnl)
        if min_value < -100:
            print("Step 1", unrealizedPnL)
            if unrealizedPnL < -50:
                print("Step 1.5", unrealizedPnL)
    self.unrealized_pnl.append(unrealizedPnL)
Reply


Messages In This Thread
While Loop Variable Freezing? - by stylingpat - Feb-19-2021, 11:48 PM
RE: While Loop Variable Freezing? - by bowlofred - Feb-20-2021, 12:01 AM
RE: While Loop Variable Freezing? - by stylingpat - Feb-20-2021, 12:04 AM
RE: While Loop Variable Freezing? - by bowlofred - Feb-20-2021, 12:44 AM
RE: While Loop Variable Freezing? - by stylingpat - Feb-20-2021, 12:10 AM
RE: While Loop Variable Freezing? - by stylingpat - Feb-20-2021, 03:40 AM
RE: While Loop Variable Freezing? - by nilamo - Feb-23-2021, 10:57 PM
RE: While Loop Variable Freezing? - by stylingpat - Feb-24-2021, 12:35 AM
RE: While Loop Variable Freezing? - by bowlofred - Feb-24-2021, 12:39 AM
RE: While Loop Variable Freezing? - by nilamo - Feb-24-2021, 04:32 PM
RE: While Loop Variable Freezing? - by stylingpat - Feb-24-2021, 06:10 PM
RE: While Loop Variable Freezing? - by nilamo - Feb-24-2021, 06:55 PM
RE: While Loop Variable Freezing? - by stylingpat - Feb-24-2021, 10:51 PM
RE: While Loop Variable Freezing? - by Abdullah - Feb-25-2021, 10:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 505 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,960 Nov-07-2023, 09:49 AM
Last Post: buran
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,682 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,183 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Multiple Loop Statements in a Variable Dexty 1 1,242 May-23-2022, 08:53 AM
Last Post: bowlofred
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,218 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to save specific variable in for loop in to the database? ilknurg 1 1,190 Mar-09-2022, 10:32 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,495 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  Using Excel Cell As A Variable In A Loop knight2000 7 4,258 Aug-25-2021, 12:43 PM
Last Post: snippsat
  Using Excel Cell As A Variable In A Loop knight2000 7 5,131 Jul-18-2021, 10:52 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020