Skip to content

Commit

Permalink
exchange/exchange add param taker_or_maker to add_dry_order_fee
Browse files Browse the repository at this point in the history
  • Loading branch information
samgermain committed May 4, 2022
1 parent 2705096 commit e880347
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,26 @@ def _get_stake_amount_considering_leverage(self, stake_amount: float, leverage:

# Dry-run methods

def taker_or_maker(
self,
order_reason: Literal['entry', 'exit', 'stoploss'], # TODO: stoploss
):
order_type = self._config['order_types'][order_reason]
if order_type == 'market' or order_reason == 'stoploss':
return 'taker'
else:
return (
'maker' if (
(
order_reason == 'entry' and
self._config['entry_pricing']['price_side'] == 'same'
) or (
order_reason == 'exit' and
self._config['exit_pricing']['price_side'] == 'same'
)
) else 'taker'
)

def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
rate: float, leverage: float, params: Dict = {},
stop_loss: bool = False) -> Dict[str, Any]:
Expand Down Expand Up @@ -824,20 +844,25 @@ def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: flo
'filled': _amount,
'cost': (dry_order['amount'] * average) / leverage
})
dry_order = self.add_dry_order_fee(pair, dry_order)
dry_order = self.add_dry_order_fee(pair, dry_order, self.taker_or_maker('entry'))

dry_order = self.check_dry_limit_order_filled(dry_order)

self._dry_run_open_orders[dry_order["id"]] = dry_order
# Copy order and close it - so the returned order is open unless it's a market order
return dry_order

def add_dry_order_fee(self, pair: str, dry_order: Dict[str, Any]) -> Dict[str, Any]:
def add_dry_order_fee(
self,
pair: str,
dry_order: Dict[str, Any],
taker_or_maker: Literal['taker', 'maker'],
) -> Dict[str, Any]:
dry_order.update({
'fee': {
'currency': self.get_pair_quote_currency(pair),
'cost': dry_order['cost'] * self.get_fee(pair),
'rate': self.get_fee(pair)
'cost': dry_order['cost'] * self.get_fee(pair, taker_or_maker=taker_or_maker),
'rate': self.get_fee(pair, taker_or_maker=taker_or_maker)
}
})
return dry_order
Expand Down Expand Up @@ -917,7 +942,16 @@ def check_dry_limit_order_filled(self, order: Dict[str, Any]) -> Dict[str, Any]:
'filled': order['amount'],
'remaining': 0,
})
self.add_dry_order_fee(pair, order)
enter_long = not order['is_short'] and order['side'] == 'buy'
enter_short = order['is_short'] and order['side'] == 'sell'
entry_or_exit: Literal['entry', 'exit'] = (
'entry' if (enter_short or enter_long) else 'exit'
)
self.add_dry_order_fee(
pair,
order,
self.taker_or_maker(entry_or_exit)
)

return order

Expand Down

0 comments on commit e880347

Please sign in to comment.