
To enhance and simplify your code, you can eliminate redundancy and improve readability. Here’s a more concise version:
funding_rate_float = round(float(funding_rate), 3)
self.funding_rate_signal = 'SELL' if funding_rate_float > 0 else 'BUY'
This version achieves the same functionality:
- Rounds
funding_rate_float
to three decimal points. - Sets
self.funding_rate_signal
to'SELL'
iffunding_rate_float
is positive, and'BUY'
if it’s negative or zero.
If you want to treat zero as neutral (i.e., no signal), you could add a condition for zero:
funding_rate_float = round(float(funding_rate), 3)
self.funding_rate_signal = 'SELL' if funding_rate_float > 0 else 'BUY' if funding_rate_float < 0 else 'NEUTRAL'
