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
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
# 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
def get_dry_market_fill_price(
self, pair: str, side: str, amount: float, rate: float,
ob: Optional[OrderBook]) -> float:
def get_dry_market_fill_price(self, pair: str, side: str, amount: float, rate: float,
orderbook: Optional[OrderBook]) -> float:
"""
Get the market order fill price based on orderbook interpolation
"""
if self.exchange_has('fetchL2OrderBook'):
if not ob:
ob = self.fetch_l2_order_book(pair, 20)
if not orderbook:
orderbook = self.fetch_l2_order_book(pair, 20)
ob_type: OBLiteral = 'asks' if side == 'buy' else 'bids'
slippage = 0.05
max_slippage_val = rate * ((1 + slippage) if side == 'buy' else (1 - slippage))
@ -914,7 +914,7 @@ class Exchange:
remaining_amount = amount
filled_amount = 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_coin_volume = book_entry[1]
if remaining_amount > 0:
@ -942,20 +942,20 @@ class Exchange:
return rate
def _is_dry_limit_order_filled(
self, pair: str, side: str, limit: float, ob: Optional[OrderBook] = None) -> bool:
def _is_dry_limit_order_filled(self, pair: str, side: str, limit: float,
orderbook: Optional[OrderBook] = None) -> bool:
if not self.exchange_has('fetchL2OrderBook'):
return True
if not ob:
ob = self.fetch_l2_order_book(pair, 1)
if not orderbook:
orderbook = self.fetch_l2_order_book(pair, 1)
try:
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}")
if limit >= price:
return True
else:
price = ob['bids'][0][0]
price = orderbook['bids'][0][0]
logger.debug(f"{pair} checking dry sell-order: price={price}, limit={limit}")
if limit <= price:
return True
@ -966,7 +966,7 @@ class Exchange:
def check_dry_limit_order_filled(
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).
"""
@ -974,7 +974,7 @@ class Exchange:
and order['type'] in ["limit"]
and not order.get('ft_order_type')):
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({
'status': 'closed',
'filled': order['amount'],