Skip to content

Commit

Permalink
Merge pull request #400 from movy/fix-perc-diff-math
Browse files Browse the repository at this point in the history
fix percentage difference calculation math
  • Loading branch information
saleh-mir committed May 19, 2023
2 parents a05a0ed + 1cc4704 commit 955a86b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jesse/services/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def reduce_position_at(self, qty: float, price: float, current_price: float) ->

# MARKET order
# if the price difference is bellow 0.01% of the current price, then we submit a market order
if abs(price - current_price) < 0.0001:
if abs(1 - (price / current_price)) < 0.0001:
return self.api.market_order(
self.exchange,
self.symbol,
Expand Down
4 changes: 2 additions & 2 deletions jesse/strategies/Strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _submit_buy_orders(self) -> None:

for o in self._buy:
# MARKET order
if abs(o[1] - price_to_compare) < 0.0001:
if abs(1 - (o[1] / price_to_compare)) < 0.0001:
self.broker.buy_at_market(o[0])
# STOP order
elif o[1] > price_to_compare:
Expand All @@ -259,7 +259,7 @@ def _submit_sell_orders(self) -> None:

for o in self._sell:
# MARKET order
if abs(o[1] - price_to_compare) < 0.0001:
if abs(1 - (o[1] / price_to_compare)) < 0.0001:
self.broker.sell_at_market(o[0])
# STOP order
elif o[1] < price_to_compare:
Expand Down

0 comments on commit 955a86b

Please sign in to comment.