Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update-active-orders another get-active-orders + use numba to ac… #467

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions jesse/models/FuturesExchange.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import numpy as np
from numba import njit

import jesse.helpers as jh
import jesse.services.logger as logger
from jesse.enums import sides, order_types
Expand Down Expand Up @@ -150,18 +152,15 @@ def on_order_cancellation(self, order: Order) -> None:
base_asset = jh.base_asset(order.symbol)

self.available_assets[base_asset] -= order.qty
# self.available_assets[quote_asset] += order.qty * order.price
if not order.reduce_only:
order_array = np.array([order.qty, order.price])
if order.side == sides.BUY:
item_index = np.where(np.all(self.buy_orders[base_asset].array == order_array, axis=1))[0]
if len(item_index) > 0:
index = item_index[0]
index = find_order_index(self.buy_orders[base_asset].array, order_array)
if index != -1:
self.buy_orders[base_asset].delete(index, axis=0)
else:
item_index = np.where(np.all(self.sell_orders[base_asset].array == order_array, axis=1))[0]
if len(item_index) > 0:
index = item_index[0]
index = find_order_index(self.sell_orders[base_asset].array, order_array)
if index != -1:
self.sell_orders[base_asset].delete(index, axis=0)

def update_from_stream(self, data: dict) -> None:
Expand All @@ -175,3 +174,11 @@ def update_from_stream(self, data: dict) -> None:
self._wallet_balance = data['wallet_balance']
if self._started_balance == 0:
self._started_balance = self._wallet_balance


@njit(cache=True)
def find_order_index(orders, order_array):
for i in range(len(orders)):
if np.all(orders[i] == order_array):
return i
return -1
2 changes: 1 addition & 1 deletion jesse/modes/backtest_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def _execute_market_orders():


def _get_executing_orders(exchange, symbol, real_candle):
orders = store.orders.get_orders(exchange, symbol)
orders = store.orders.get_active_orders(exchange, symbol)
return [
order
for order in orders
Expand Down
Loading