Rename ob variable to orderbook

This commit is contained in:
Matthias 2023-02-15 07:21:18 +01:00
parent de7d274fcf
commit 8ef110cc5f

View File

@ -876,7 +876,8 @@ class Exchange:
# market orders will always incurr taker fees # market orders will always incurr taker fees
dry_order = self.add_dry_order_fee(pair, dry_order, 'taker') dry_order = self.add_dry_order_fee(pair, dry_order, 'taker')
dry_order = self.check_dry_limit_order_filled(dry_order, immediate=True, ob=orderbook) dry_order = self.check_dry_limit_order_filled(
dry_order, immediate=True, orderbook=orderbook)
self._dry_run_open_orders[dry_order["id"]] = 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 # Copy order and close it - so the returned order is open unless it's a market order
@ -898,15 +899,14 @@ class Exchange:
}) })
return dry_order return dry_order
def get_dry_market_fill_price( def get_dry_market_fill_price(self, pair: str, side: str, amount: float, rate: float,
self, pair: str, side: str, amount: float, rate: float, orderbook: Optional[OrderBook]) -> float:
ob: Optional[OrderBook]) -> float:
""" """
Get the market order fill price based on orderbook interpolation Get the market order fill price based on orderbook interpolation
""" """
if self.exchange_has('fetchL2OrderBook'): if self.exchange_has('fetchL2OrderBook'):
if not ob: if not orderbook:
ob = self.fetch_l2_order_book(pair, 20) orderbook = self.fetch_l2_order_book(pair, 20)
ob_type: OBLiteral = 'asks' if side == 'buy' else 'bids' ob_type: OBLiteral = 'asks' if side == 'buy' else 'bids'
slippage = 0.05 slippage = 0.05
max_slippage_val = rate * ((1 + slippage) if side == 'buy' else (1 - slippage)) max_slippage_val = rate * ((1 + slippage) if side == 'buy' else (1 - slippage))
@ -914,7 +914,7 @@ class Exchange:
remaining_amount = amount remaining_amount = amount
filled_amount = 0.0 filled_amount = 0.0
book_entry_price = 0.0 book_entry_price = 0.0
for book_entry in ob[ob_type]: for book_entry in orderbook[ob_type]:
book_entry_price = book_entry[0] book_entry_price = book_entry[0]
book_entry_coin_volume = book_entry[1] book_entry_coin_volume = book_entry[1]
if remaining_amount > 0: if remaining_amount > 0:
@ -942,20 +942,20 @@ class Exchange:
return rate return rate
def _is_dry_limit_order_filled( def _is_dry_limit_order_filled(self, pair: str, side: str, limit: float,
self, pair: str, side: str, limit: float, ob: Optional[OrderBook] = None) -> bool: orderbook: Optional[OrderBook] = None) -> bool:
if not self.exchange_has('fetchL2OrderBook'): if not self.exchange_has('fetchL2OrderBook'):
return True return True
if not ob: if not orderbook:
ob = self.fetch_l2_order_book(pair, 1) orderbook = self.fetch_l2_order_book(pair, 1)
try: try:
if side == 'buy': if side == 'buy':
price = ob['asks'][0][0] price = orderbook['asks'][0][0]
logger.debug(f"{pair} checking dry buy-order: price={price}, limit={limit}") logger.debug(f"{pair} checking dry buy-order: price={price}, limit={limit}")
if limit >= price: if limit >= price:
return True return True
else: else:
price = ob['bids'][0][0] price = orderbook['bids'][0][0]
logger.debug(f"{pair} checking dry sell-order: price={price}, limit={limit}") logger.debug(f"{pair} checking dry sell-order: price={price}, limit={limit}")
if limit <= price: if limit <= price:
return True return True
@ -966,7 +966,7 @@ class Exchange:
def check_dry_limit_order_filled( def check_dry_limit_order_filled(
self, order: Dict[str, Any], immediate: bool = False, self, order: Dict[str, Any], immediate: bool = False,
ob: Optional[OrderBook] = None) -> Dict[str, Any]: orderbook: Optional[OrderBook] = None) -> Dict[str, Any]:
""" """
Check dry-run limit order fill and update fee (if it filled). Check dry-run limit order fill and update fee (if it filled).
""" """
@ -974,7 +974,7 @@ class Exchange:
and order['type'] in ["limit"] and order['type'] in ["limit"]
and not order.get('ft_order_type')): and not order.get('ft_order_type')):
pair = order['symbol'] pair = order['symbol']
if self._is_dry_limit_order_filled(pair, order['side'], order['price'], ob): if self._is_dry_limit_order_filled(pair, order['side'], order['price'], orderbook):
order.update({ order.update({
'status': 'closed', 'status': 'closed',
'filled': order['amount'], 'filled': order['amount'],