Skip to content

Conversation

@luceCoding
Copy link
Contributor

@luceCoding luceCoding commented Jun 28, 2025

First step in converting all string comparisons into proper Enums.

Current repo is littered with unsafe/slow string comparisons. Converting them into Enums will speed up the comparisons by 10-30%.

Enums were renamed to PEP 8 standards which requires the Jesse Live Plugin to be updated. Unless you would like to revert the names back to their old ones. The "Exchange" enum seems to be the only thing that needs to be updated.

In the future, please avoid using string comparisons and instead pass the enums directly.

class Side(Enum):
    BUY = 'buy'
    SELL = 'sell'

Slow 👎:

def is_buy(s: str) -> bool:
    return s == Side.BUY.value
    
is_buy("sell")

Fast and Pythonic 👍:

def is_buy(s: Side) -> bool:
    return s == Side.BUY
    
is_buy(Side.SELL)

@luceCoding luceCoding marked this pull request as ready for review June 28, 2025 20:44
@saleh-mir
Copy link
Member

Hey man, I really appreciate your effort, but I'm afraid I prefer not to merge this because the code in the LiveTrade plugin doesn't have unit tests. This is simply because of how difficult it is to test WebSocket code.

I'm afraid that if I make this change, it's going to break that. I might miss some parts and cause some issues. I've had this kind of issue and made mistakes in the past, and I don't want to break stability for a little performance boost.

That .value in the end is the part that worries me.

@saleh-mir saleh-mir closed this Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants