From 692bb1cde8b22d42136a9beb010d422a8c59f351 Mon Sep 17 00:00:00 2001 From: Yakir Date: Sun, 1 Sep 2024 17:19:10 +0300 Subject: [PATCH 1/4] enter a position whenever its not in position --- docker_build_helpers/install_ta-lib.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docker_build_helpers/install_ta-lib.sh b/docker_build_helpers/install_ta-lib.sh index bac363df6..77dac74fa 100755 --- a/docker_build_helpers/install_ta-lib.sh +++ b/docker_build_helpers/install_ta-lib.sh @@ -6,12 +6,13 @@ fi echo "Installing to ${INSTALL_LOC}" if [ ! -f "${INSTALL_LOC}/lib/libta_lib.a" ]; then tar zxvf ta-lib-0.4.0-src.tar.gz - cd ta-lib \ - && sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h \ - && ./configure --prefix=${INSTALL_LOC}/ \ - && make \ - && which sudo && sudo make install || make install \ - && echo "export LD_LIBRARY_PATH=/usr/local/lib" >> /root/.bashrc + cd ta-lib + sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h + ./configure --prefix=${INSTALL_LOC}/ + make + which sudo + sudo make install || make install + echo "export LD_LIBRARY_PATH=/usr/local/lib" >> /root/.bashrc else echo "TA-lib already installed, skipping installation" fi From a7981b1b1d5edde5edc6656deefd2a8125bdbb74 Mon Sep 17 00:00:00 2001 From: Yakir Date: Mon, 2 Sep 2024 18:30:05 +0300 Subject: [PATCH 2/4] wip to see the differences --- docker_build_helpers/install_ta-lib.sh | 13 +- jesse/exchanges/sandbox/Sandbox.py | 90 +++++++++----- jesse/models/Order.py | 161 +++++++++++++++---------- jesse/services/migrator.py | 3 +- 4 files changed, 165 insertions(+), 102 deletions(-) diff --git a/docker_build_helpers/install_ta-lib.sh b/docker_build_helpers/install_ta-lib.sh index 77dac74fa..bac363df6 100755 --- a/docker_build_helpers/install_ta-lib.sh +++ b/docker_build_helpers/install_ta-lib.sh @@ -6,13 +6,12 @@ fi echo "Installing to ${INSTALL_LOC}" if [ ! -f "${INSTALL_LOC}/lib/libta_lib.a" ]; then tar zxvf ta-lib-0.4.0-src.tar.gz - cd ta-lib - sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h - ./configure --prefix=${INSTALL_LOC}/ - make - which sudo - sudo make install || make install - echo "export LD_LIBRARY_PATH=/usr/local/lib" >> /root/.bashrc + cd ta-lib \ + && sed -i.bak "s|0.00000001|0.000000000000000001 |g" src/ta_func/ta_utility.h \ + && ./configure --prefix=${INSTALL_LOC}/ \ + && make \ + && which sudo && sudo make install || make install \ + && echo "export LD_LIBRARY_PATH=/usr/local/lib" >> /root/.bashrc else echo "TA-lib already installed, skipping installation" fi diff --git a/jesse/exchanges/sandbox/Sandbox.py b/jesse/exchanges/sandbox/Sandbox.py index cccd34bf9..7b971cd17 100644 --- a/jesse/exchanges/sandbox/Sandbox.py +++ b/jesse/exchanges/sandbox/Sandbox.py @@ -12,16 +12,26 @@ def __init__(self, name='Sandbox'): self.name = name def market_order(self, symbol: str, qty: float, current_price: float, side: str, reduce_only: bool) -> Order: - order = Order({ - 'id': jh.generate_unique_id(), - 'symbol': symbol, - 'exchange': self.name, - 'side': side, - 'type': order_types.MARKET, - 'reduce_only': reduce_only, - 'qty': jh.prepare_qty(qty, side), - 'price': current_price, - }) + # order = Order({ + # 'id': jh.generate_unique_id(), + # 'symbol': symbol, + # 'exchange': self.name, + # 'side': side, + # 'type': order_types.MARKET, + # 'reduce_only': reduce_only, + # 'qty': jh.prepare_qty(qty, side), + # 'price': current_price, + # }) + order = Order( + id=jh.generate_unique_id(), + symbol=symbol, + exchange=self.name, + side=side, + type=order_types.MARKET, + reduce_only=reduce_only, + qty=jh.prepare_qty(qty, side), + price=current_price, + ) store.orders.add_order(order) @@ -30,32 +40,52 @@ def market_order(self, symbol: str, qty: float, current_price: float, side: str, return order def limit_order(self, symbol: str, qty: float, price: float, side: str, reduce_only: bool) -> Order: - order = Order({ - 'id': jh.generate_unique_id(), - 'symbol': symbol, - 'exchange': self.name, - 'side': side, - 'type': order_types.LIMIT, - 'reduce_only': reduce_only, - 'qty': jh.prepare_qty(qty, side), - 'price': price, - }) + # order = Order({ + # 'id': jh.generate_unique_id(), + # 'symbol': symbol, + # 'exchange': self.name, + # 'side': side, + # 'type': order_types.LIMIT, + # 'reduce_only': reduce_only, + # 'qty': jh.prepare_qty(qty, side), + # 'price': price, + # }) + order = Order( + id=jh.generate_unique_id(), + symbol=symbol, + exchange=self.name, + side=side, + type=order_types.LIMIT, + reduce_only=reduce_only, + qty=jh.prepare_qty(qty, side), + price=price, + ) store.orders.add_order(order) return order def stop_order(self, symbol: str, qty: float, price: float, side: str, reduce_only: bool) -> Order: - order = Order({ - 'id': jh.generate_unique_id(), - 'symbol': symbol, - 'exchange': self.name, - 'side': side, - 'type': order_types.STOP, - 'reduce_only': reduce_only, - 'qty': jh.prepare_qty(qty, side), - 'price': price, - }) + # order = Order({ + # 'id': jh.generate_unique_id(), + # 'symbol': symbol, + # 'exchange': self.name, + # 'side': side, + # 'type': order_types.STOP, + # 'reduce_only': reduce_only, + # 'qty': jh.prepare_qty(qty, side), + # 'price': price, + # }) + order = Order( + id=jh.generate_unique_id(), + symbol=symbol, + exchange=self.name, + side=side, + type=order_types.STOP, + reduce_only=reduce_only, + qty=jh.prepare_qty(qty, side), + price=price, + ) store.orders.add_order(order) diff --git a/jesse/models/Order.py b/jesse/models/Order.py index 7b7ac0755..7e810db31 100644 --- a/jesse/models/Order.py +++ b/jesse/models/Order.py @@ -1,3 +1,7 @@ +import time +from dataclasses import dataclass, field, fields +from uuid import UUID + from playhouse.postgres_ext import * import jesse.helpers as jh @@ -8,73 +12,101 @@ from jesse.enums import order_statuses, order_submitted_via from jesse.services.db import database - if database.is_closed(): database.open_connection() -class Order(Model): - # id generated by Jesse for database usage - id = UUIDField(primary_key=True) - trade_id = UUIDField(index=True, null=True) - session_id = UUIDField(index=True) - - # id generated by market, used in live-trade mode - exchange_id = CharField(null=True) - # some exchanges might require even further info - vars = JSONField(default={}) - symbol = CharField() - exchange = CharField() - side = CharField() - type = CharField() - reduce_only = BooleanField() - qty = FloatField() - filled_qty = FloatField(default=0) - price = FloatField(null=True) - status = CharField(default=order_statuses.ACTIVE) - created_at = BigIntegerField() - executed_at = BigIntegerField(null=True) - canceled_at = BigIntegerField(null=True) - - # needed in Jesse, but no need to store in database(?) - submitted_via = None - - class Meta: - from jesse.services.db import database - - database = database.db - indexes = ((('trade_id', 'exchange', 'symbol', 'status', 'created_at'), False),) - - def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: - Model.__init__(self, attributes=attributes, **kwargs) - - if attributes is None: - attributes = {} - - for a, value in attributes.items(): - setattr(self, a, value) - - if self.created_at is None: - self.created_at = jh.now_to_timestamp() - - # if jh.is_live(): - # from jesse.store import store - # self.session_id = store.app.session_id - # self.save(force_insert=True) - - if not should_silent: - if jh.is_live(): - self.notify_submission() - - if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): - txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' - if self.price: - txt += f', ${self.price}' - logger.info(txt) - - # handle exchange balance for ordered asset - e = selectors.get_exchange(self.exchange) - e.on_order_submission(self) +# class Order(Model): +# # id generated by Jesse for database usage +# id = UUIDField(primary_key=True) +# trade_id = UUIDField(index=True, null=True) +# session_id = UUIDField(index=True) +# +# # id generated by market, used in live-trade mode +# exchange_id = CharField(null=True) +# # some exchanges might require even further info +# vars = JSONField(default={}) +# symbol = CharField() +# exchange = CharField() +# side = CharField() +# type = CharField() +# reduce_only = BooleanField() +# qty = FloatField() +# filled_qty = FloatField(default=0) +# price = FloatField(null=True) +# status = CharField(default=order_statuses.ACTIVE) +# created_at = BigIntegerField() +# executed_at = BigIntegerField(null=True) +# canceled_at = BigIntegerField(null=True) +# +# # needed in Jesse, but no need to store in database(?) +# submitted_via = None +# +# class Meta: +# from jesse.services.db import database +# +# database = database.db +# indexes = ((('trade_id', 'exchange', 'symbol', 'status', 'created_at'), False),) +# +# def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: +# Model.__init__(self, attributes=attributes, **kwargs) +# +# if attributes is None: +# attributes = {} +# +# for a, value in attributes.items(): +# setattr(self, a, value) +# +# if self.created_at is None: +# self.created_at = jh.now_to_timestamp() +# +# # if jh.is_live(): +# # from jesse.store import store +# # self.session_id = store.app.session_id +# # self.save(force_insert=True) +# +# if not should_silent: +# if jh.is_live(): +# self.notify_submission() +# +# if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): +# txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' +# if self.price: +# txt += f', ${self.price}' +# logger.info(txt) +# +# # handle exchange balance for ordered asset +# e = selectors.get_exchange(self.exchange) +# e.on_order_submission(self) + +def get_session_id(): + from jesse.store import store + return store.app.session_id + + +@dataclass(slots=True) +class Order: + id: str + symbol: str + exchange: str + side: str + type: str + reduce_only: bool + qty: float + exchange_id: str | None = None + vars: dict = field(default_factory=dict) + filled_qty: float = 0.0 + trade_id: UUID | None = None + price: float | None = None + status: str = field(default='ACTIVE') + session_id: str = field(default_factory=get_session_id) + created_at: int = field(default_factory=lambda: int(time.time())) + executed_at: int | None = None + canceled_at: int | None = None + + # This attribute is not stored in the database, so you can define it + # as an instance variable without the need for a field + submitted_via: str | None = None def notify_submission(self) -> None: if config['env']['notifications']['events']['submitted_orders'] and (self.is_active or self.is_queued): @@ -280,4 +312,5 @@ def execute_partially(self, silent=False) -> None: # if database is open, create the table if database.is_open(): - Order.create_table() + pass + # Order.create_table() diff --git a/jesse/services/migrator.py b/jesse/services/migrator.py index 577049b71..a8340a96a 100644 --- a/jesse/services/migrator.py +++ b/jesse/services/migrator.py @@ -33,7 +33,8 @@ def run(): # create initial tables from jesse.models import Candle, ClosedTrade, Log, Order, Option - database.db.create_tables([Candle, ClosedTrade, Log, Order]) + # database.db.create_tables([Candle, ClosedTrade, Log, Order]) + database.db.create_tables([Candle, ClosedTrade, Log]) database.close_connection() From 7d053d53e0685dd7676ff5ad61787401fca48c1a Mon Sep 17 00:00:00 2001 From: Yakir Date: Mon, 2 Sep 2024 20:00:05 +0300 Subject: [PATCH 3/4] add post init to dataclass --- jesse/models/Order.py | 84 +++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/jesse/models/Order.py b/jesse/models/Order.py index 7e810db31..9a9064cff 100644 --- a/jesse/models/Order.py +++ b/jesse/models/Order.py @@ -48,36 +48,36 @@ # database = database.db # indexes = ((('trade_id', 'exchange', 'symbol', 'status', 'created_at'), False),) # -# def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: -# Model.__init__(self, attributes=attributes, **kwargs) -# -# if attributes is None: -# attributes = {} -# -# for a, value in attributes.items(): -# setattr(self, a, value) -# -# if self.created_at is None: -# self.created_at = jh.now_to_timestamp() -# -# # if jh.is_live(): -# # from jesse.store import store -# # self.session_id = store.app.session_id -# # self.save(force_insert=True) -# -# if not should_silent: -# if jh.is_live(): -# self.notify_submission() -# -# if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): -# txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' -# if self.price: -# txt += f', ${self.price}' -# logger.info(txt) -# -# # handle exchange balance for ordered asset -# e = selectors.get_exchange(self.exchange) -# e.on_order_submission(self) + # def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: + # Model.__init__(self, attributes=attributes, **kwargs) + # + # if attributes is None: + # attributes = {} + # + # for a, value in attributes.items(): + # setattr(self, a, value) + # + # if self.created_at is None: + # self.created_at = jh.now_to_timestamp() + # + # # if jh.is_live(): + # # from jesse.store import store + # # self.session_id = store.app.session_id + # # self.save(force_insert=True) + # + # if not should_silent: + # if jh.is_live(): + # self.notify_submission() + # + # if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): + # txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' + # if self.price: + # txt += f', ${self.price}' + # logger.info(txt) + # + # # handle exchange balance for ordered asset + # e = selectors.get_exchange(self.exchange) + # e.on_order_submission(self) def get_session_id(): from jesse.store import store @@ -107,6 +107,30 @@ class Order: # This attribute is not stored in the database, so you can define it # as an instance variable without the need for a field submitted_via: str | None = None + should_silent: bool = True + + def __post_init__(self) -> None: + if self.created_at is None: + self.created_at = jh.now_to_timestamp() + + # if jh.is_live(): + # from jesse.store import store + # self.session_id = store.app.session_id + # self.save(force_insert=True) + + if not self.should_silent: + if jh.is_live(): + self.notify_submission() + + if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): + txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' + if self.price: + txt += f', ${self.price}' + logger.info(txt) + + # handle exchange balance for ordered asset + e = selectors.get_exchange(self.exchange) + e.on_order_submission(self) def notify_submission(self) -> None: if config['env']['notifications']['events']['submitted_orders'] and (self.is_active or self.is_queued): From cfeda67887caa79ce85f63d70a994e2a83f822d4 Mon Sep 17 00:00:00 2001 From: Yakir Date: Mon, 2 Sep 2024 20:40:04 +0300 Subject: [PATCH 4/4] create order model to make sure I still have to db functionality --- jesse/exchanges/sandbox/Sandbox.py | 30 -------- jesse/factories/order_factory.py | 22 +++--- jesse/models/Order.py | 111 ++++++++++++----------------- jesse/models/__init__.py | 2 +- jesse/models/utils.py | 3 +- jesse/modes/backtest_mode.py | 20 +++--- jesse/services/migrator.py | 5 +- 7 files changed, 72 insertions(+), 121 deletions(-) diff --git a/jesse/exchanges/sandbox/Sandbox.py b/jesse/exchanges/sandbox/Sandbox.py index 7b971cd17..8382b230f 100644 --- a/jesse/exchanges/sandbox/Sandbox.py +++ b/jesse/exchanges/sandbox/Sandbox.py @@ -12,16 +12,6 @@ def __init__(self, name='Sandbox'): self.name = name def market_order(self, symbol: str, qty: float, current_price: float, side: str, reduce_only: bool) -> Order: - # order = Order({ - # 'id': jh.generate_unique_id(), - # 'symbol': symbol, - # 'exchange': self.name, - # 'side': side, - # 'type': order_types.MARKET, - # 'reduce_only': reduce_only, - # 'qty': jh.prepare_qty(qty, side), - # 'price': current_price, - # }) order = Order( id=jh.generate_unique_id(), symbol=symbol, @@ -40,16 +30,6 @@ def market_order(self, symbol: str, qty: float, current_price: float, side: str, return order def limit_order(self, symbol: str, qty: float, price: float, side: str, reduce_only: bool) -> Order: - # order = Order({ - # 'id': jh.generate_unique_id(), - # 'symbol': symbol, - # 'exchange': self.name, - # 'side': side, - # 'type': order_types.LIMIT, - # 'reduce_only': reduce_only, - # 'qty': jh.prepare_qty(qty, side), - # 'price': price, - # }) order = Order( id=jh.generate_unique_id(), symbol=symbol, @@ -66,16 +46,6 @@ def limit_order(self, symbol: str, qty: float, price: float, side: str, reduce_o return order def stop_order(self, symbol: str, qty: float, price: float, side: str, reduce_only: bool) -> Order: - # order = Order({ - # 'id': jh.generate_unique_id(), - # 'symbol': symbol, - # 'exchange': self.name, - # 'side': side, - # 'type': order_types.STOP, - # 'reduce_only': reduce_only, - # 'qty': jh.prepare_qty(qty, side), - # 'price': price, - # }) order = Order( id=jh.generate_unique_id(), symbol=symbol, diff --git a/jesse/factories/order_factory.py b/jesse/factories/order_factory.py index 585fdebe4..bb3f8c9d9 100644 --- a/jesse/factories/order_factory.py +++ b/jesse/factories/order_factory.py @@ -27,14 +27,14 @@ def fake_order(attributes: dict = None) -> Order: status = order_statuses.ACTIVE created_at = first_timestamp - return Order({ - "id": jh.generate_unique_id(), - 'symbol': attributes.get('symbol', symbol), - 'exchange': attributes.get('exchange', exchange), - 'side': attributes.get('side', side), - 'type': attributes.get('type', order_type), - 'qty': attributes.get('qty', qty), - 'price': attributes.get('price', price), - 'status': attributes.get('status', status), - 'created_at': attributes.get('created_at', created_at), - }) + return Order( + id=jh.generate_unique_id(), + symbol=attributes.get('symbol', symbol), + exchange=attributes.get('exchange', exchange), + side=attributes.get('side', side), + type=attributes.get('type', order_type), + qty=attributes.get('qty', qty), + price=attributes.get('price', price), + status=attributes.get('status', status), + created_at=attributes.get('created_at', created_at), + ) diff --git a/jesse/models/Order.py b/jesse/models/Order.py index 9a9064cff..9ce5d333f 100644 --- a/jesse/models/Order.py +++ b/jesse/models/Order.py @@ -16,68 +16,47 @@ database.open_connection() -# class Order(Model): -# # id generated by Jesse for database usage -# id = UUIDField(primary_key=True) -# trade_id = UUIDField(index=True, null=True) -# session_id = UUIDField(index=True) -# -# # id generated by market, used in live-trade mode -# exchange_id = CharField(null=True) -# # some exchanges might require even further info -# vars = JSONField(default={}) -# symbol = CharField() -# exchange = CharField() -# side = CharField() -# type = CharField() -# reduce_only = BooleanField() -# qty = FloatField() -# filled_qty = FloatField(default=0) -# price = FloatField(null=True) -# status = CharField(default=order_statuses.ACTIVE) -# created_at = BigIntegerField() -# executed_at = BigIntegerField(null=True) -# canceled_at = BigIntegerField(null=True) -# -# # needed in Jesse, but no need to store in database(?) -# submitted_via = None -# -# class Meta: -# from jesse.services.db import database -# -# database = database.db -# indexes = ((('trade_id', 'exchange', 'symbol', 'status', 'created_at'), False),) -# - # def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: - # Model.__init__(self, attributes=attributes, **kwargs) - # - # if attributes is None: - # attributes = {} - # - # for a, value in attributes.items(): - # setattr(self, a, value) - # - # if self.created_at is None: - # self.created_at = jh.now_to_timestamp() - # - # # if jh.is_live(): - # # from jesse.store import store - # # self.session_id = store.app.session_id - # # self.save(force_insert=True) - # - # if not should_silent: - # if jh.is_live(): - # self.notify_submission() - # - # if jh.is_debuggable('order_submission') and (self.is_active or self.is_queued): - # txt = f'{"QUEUED" if self.is_queued else "SUBMITTED"} order: {self.symbol}, {self.type}, {self.side}, {self.qty}' - # if self.price: - # txt += f', ${self.price}' - # logger.info(txt) - # - # # handle exchange balance for ordered asset - # e = selectors.get_exchange(self.exchange) - # e.on_order_submission(self) +class OrderModel(Model): + # id generated by Jesse for database usage + id = UUIDField(primary_key=True) + trade_id = UUIDField(index=True, null=True) + session_id = UUIDField(index=True) + + # id generated by market, used in live-trade mode + exchange_id = CharField(null=True) + # some exchanges might require even further info + vars = JSONField(default={}) + symbol = CharField() + exchange = CharField() + side = CharField() + type = CharField() + reduce_only = BooleanField() + qty = FloatField() + filled_qty = FloatField(default=0) + price = FloatField(null=True) + status = CharField(default=order_statuses.ACTIVE) + created_at = BigIntegerField() + executed_at = BigIntegerField(null=True) + canceled_at = BigIntegerField(null=True) + + # needed in Jesse, but no need to store in database(?) + submitted_via = None + + class Meta: + from jesse.services.db import database + + database = database.db + indexes = ((('trade_id', 'exchange', 'symbol', 'status', 'created_at'), False),) + + def __init__(self, attributes: dict = None, should_silent=False, **kwargs) -> None: + Model.__init__(self, attributes=attributes, **kwargs) + + if attributes is None: + attributes = {} + + for a, value in attributes.items(): + setattr(self, a, value) + def get_session_id(): from jesse.store import store @@ -91,8 +70,8 @@ class Order: exchange: str side: str type: str - reduce_only: bool qty: float + reduce_only: bool = False exchange_id: str | None = None vars: dict = field(default_factory=dict) filled_qty: float = 0.0 @@ -333,8 +312,10 @@ def execute_partially(self, silent=False) -> None: if p: p._on_executed_order(self) + def to_model(self) -> OrderModel: + return OrderModel(self.to_dict) + # if database is open, create the table if database.is_open(): - pass - # Order.create_table() + OrderModel.create_table() diff --git a/jesse/models/__init__.py b/jesse/models/__init__.py index 5a4518f12..8d7bd482a 100644 --- a/jesse/models/__init__.py +++ b/jesse/models/__init__.py @@ -2,7 +2,7 @@ from .ClosedTrade import ClosedTrade from .Exchange import Exchange from .FuturesExchange import FuturesExchange -from .Order import Order +from .Order import Order, OrderModel from .Position import Position from .Route import Route from .SpotExchange import SpotExchange diff --git a/jesse/models/utils.py b/jesse/models/utils.py index 4b3d984ac..c7b9116ff 100644 --- a/jesse/models/utils.py +++ b/jesse/models/utils.py @@ -2,6 +2,7 @@ import numpy as np import jesse.helpers as jh +from jesse.models import OrderModel from jesse.services import logger @@ -171,7 +172,7 @@ def store_order_into_db(order) -> None: } def async_save() -> None: - Order.insert(**d).execute() + OrderModel.insert(**d).execute() if jh.is_debugging(): logger.info(f'Stored the executed order record for {order.exchange}-{order.symbol} into database.') diff --git a/jesse/modes/backtest_mode.py b/jesse/modes/backtest_mode.py index 4c6948220..a30b238c7 100644 --- a/jesse/modes/backtest_mode.py +++ b/jesse/modes/backtest_mode.py @@ -588,16 +588,16 @@ def _check_for_liquidations(candle: np.ndarray, exchange: str, symbol: str) -> N closing_order_side = jh.closing_side(p.type) # create the market order that is used as the liquidation order - order = Order({ - 'id': jh.generate_unique_id(), - 'symbol': symbol, - 'exchange': exchange, - 'side': closing_order_side, - 'type': order_types.MARKET, - 'reduce_only': True, - 'qty': jh.prepare_qty(p.qty, closing_order_side), - 'price': p.bankruptcy_price - }) + order = Order( + id=jh.generate_unique_id(), + symbol=symbol, + exchange=exchange, + side=closing_order_side, + type=order_types.MARKET, + reduce_only=True, + qty=jh.prepare_qty(p.qty, closing_order_side), + price=p.bankruptcy_price + ) store.orders.add_order(order) diff --git a/jesse/services/migrator.py b/jesse/services/migrator.py index a8340a96a..01549174c 100644 --- a/jesse/services/migrator.py +++ b/jesse/services/migrator.py @@ -32,9 +32,8 @@ def run(): _exchange_api_keys(migrator) # create initial tables - from jesse.models import Candle, ClosedTrade, Log, Order, Option - # database.db.create_tables([Candle, ClosedTrade, Log, Order]) - database.db.create_tables([Candle, ClosedTrade, Log]) + from jesse.models import Candle, ClosedTrade, Log, OrderModel, Option + database.db.create_tables([Candle, ClosedTrade, Log, OrderModel]) database.close_connection()