round exiting orders to be MARKET orders if the price diff is very tiny

This commit is contained in:
Saleh Mir
2021-10-23 21:24:23 +02:00
parent 7cb101649f
commit 183557e4b1
2 changed files with 8 additions and 1 deletions

View File

@@ -95,7 +95,7 @@ class Broker:
side = jh.opposite_side(jh.type_to_side(self.position.type))
if price == self.position.current_price:
if abs(price - self.position.current_price) < 0.0001:
return self.api.market_order(
self.exchange,
self.symbol,

View File

@@ -5,6 +5,9 @@ class TestMarketOrderForLowPriceDifference(Strategy):
def on_open_position(self, order):
assert order.type == 'MARKET'
def on_close_position(self, order) -> None:
assert order.type == 'MARKET'
def should_long(self) -> bool:
return self.index == 0
@@ -15,6 +18,10 @@ class TestMarketOrderForLowPriceDifference(Strategy):
# current-price: 1
self.buy = 1, 1.00001
def update_position(self) -> None:
# submit a take-profit order that has a low difference with the current price
self.take_profit = self.position.qty, self.price + 0.00001
def go_short(self):
pass