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

Back symbol market #1160

Merged
merged 3 commits into from
Jan 10, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.144] - 2025-01-10
### Fixed
[Backtesting] fix default market status + adapter issues

## [2.4.143] - 2025-01-08
### Fixed
[Orders] properly handle trigger above
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OctoBot-Trading [2.4.143](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
# OctoBot-Trading [2.4.144](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/903b6b22bceb4661b608a86fea655f69)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Trading?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Trading&utm_campaign=Badge_Grade_Dashboard)
[![PyPI](https://img.shields.io/pypi/v/OctoBot-Trading.svg)](https://pypi.python.org/pypi/OctoBot-Trading/)
[![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Trading/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Trading?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion octobot_trading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# License along with this library.

PROJECT_NAME = "OctoBot-Trading"
VERSION = "2.4.143" # major.minor.revision
VERSION = "2.4.144" # major.minor.revision
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_market_status(self, symbol, price_example=0, with_fixer=True):
return util.ExchangeMarketStatusFixer(
self._forced_market_statuses[symbol], price_example
).market_status
return self._forced_market_statuses[symbol]
return self._forced_market_statuses[symbol], True
except KeyError:
self._missing_market_statuses.add(symbol)
if len(self._missing_market_statuses) >= len(self.symbols) - 1:
Expand All @@ -168,7 +168,7 @@ def get_market_status(self, symbol, price_example=0, with_fixer=True):
)
else:
self.logger.warning(f"Missing cached market status for {symbol}: using default market status")
return self._get_default_market_status()
return self._get_default_market_status(), False

def _get_default_market_status(self):
return {
Expand Down
38 changes: 38 additions & 0 deletions octobot_trading/exchanges/implementations/exchange_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import typing
import copy

import octobot_trading.constants as constants
import octobot_trading.exchanges.util as exchange_util
Expand Down Expand Up @@ -115,6 +116,43 @@ def get_current_future_candles(self):
def get_backtesting_data_files(self):
return self.connector.get_backtesting_data_files()

def get_market_status(self, symbol, price_example=None, with_fixer=True):
"""
Override of the RESTExchange get_fixed_market_status to handle different get_market_status return values
"""
if self._should_fix_market_status():
return self.get_fixed_market_status(
symbol,
price_example=price_example,
with_fixer=with_fixer,
remove_price_limits=self._should_remove_market_status_limits(),
adapt_for_contract_size=self._should_adapt_market_status_for_contract_size()
)
market_status, _ = self.connector.get_market_status(
symbol, price_example=price_example, with_fixer=with_fixer
)
return market_status

def get_fixed_market_status(self, symbol, price_example=None, with_fixer=True, remove_price_limits=False,
adapt_for_contract_size=False):
"""
Override of the RESTExchange get_fixed_market_status to call adapt_market_status only on fetch market statuses
(should not be call on default market status)
"""
market_status, is_real = self.connector.get_market_status(symbol, with_fixer=False)
market_status = copy.deepcopy(market_status)
if is_real:
# only use adapter on real market status (not default simulator values)
market_status = self.connector.adapter.adapt_market_status(
market_status,
remove_price_limits=remove_price_limits
)
if adapt_for_contract_size and self.exchange_manager.is_future:
self._adapt_market_status_for_contract_size(market_status, self.get_contract_size(symbol))
if with_fixer:
return exchange_util.ExchangeMarketStatusFixer(market_status, price_example).market_status
return market_status

async def load_pair_future_contract(self, pair: str):
"""
Create a new FutureContract for the pair
Expand Down
10 changes: 6 additions & 4 deletions tests/personal_data/orders/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ async def test_trigger_chained_orders(trader_simulator):
# with chained orders
order_mock_1 = mock.Mock(
update_price_if_outdated=mock.AsyncMock(),
update_quantity_with_order_fees=mock.AsyncMock(return_value=True),
update_quantity_with_order_fees=mock.Mock(return_value=True),
should_be_created=mock.Mock(return_value=True),
is_cleared=mock.Mock(return_value=False)
)
order_mock_2 = mock.Mock(
update_price_if_outdated=mock.AsyncMock(),
update_quantity_with_order_fees=mock.AsyncMock(return_value=True),
update_quantity_with_order_fees=mock.Mock(return_value=True),
should_be_created=mock.Mock(return_value=False),
is_cleared=mock.Mock(return_value=False)
)
Expand Down Expand Up @@ -399,7 +399,7 @@ async def test_create_triggered_chained_order_mock(trader_simulator):
base_order = personal_data.Order(trader_inst)
eq_chained_order_1 = mock.Mock(get_name=mock.Mock(return_value="plop"))
chained_order_1 = personal_data.Order(trader_inst)
chained_order_1.create_triggered_equivalent_order=mock.AsyncMock(return_value=eq_chained_order_1)
chained_order_1.create_triggered_equivalent_order = mock.AsyncMock(return_value=eq_chained_order_1)

# normal call
with mock.patch.object(order_util, "create_as_chained_order", mock.AsyncMock()) as create_as_chained_order_mock:
Expand Down Expand Up @@ -443,7 +443,9 @@ async def _create_as_chained_order(*_):
with mock.patch.object(
order_util, "create_as_chained_order", mock.AsyncMock(side_effect=_create_as_chained_order)
) as create_as_chained_order_mock, mock.patch.object(
chained_order_1, "create_on_filled_artificial_order", mock.AsyncMock()
chained_order_1, "create_on_filled_artificial_order", mock.AsyncMock(
return_value=mock.Mock(get_name=mock.Mock(return_value="plop"))
)
) as create_on_filled_artificial_order_mock:
await base_order._create_triggered_chained_order(chained_order_1, True)
create_as_chained_order_mock.assert_called_once_with(chained_order_1)
Expand Down
Loading