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

Dev merge #2828

Merged
merged 17 commits into from
Dec 16, 2024
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
5 changes: 4 additions & 1 deletion additional_tests/exchanges_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_name(self):
async def get_authenticated_exchange_manager(
exchange_name, exchange_tentacle_name, config=None,
credentials_exchange_name=None, market_filter=None,
use_invalid_creds=False
use_invalid_creds=False, http_proxy_callback_factory=None
):
credentials_exchange_name = credentials_exchange_name or exchange_name
_load_exchange_creds_env_variables_if_necessary()
Expand All @@ -89,6 +89,9 @@ async def get_authenticated_exchange_manager(
.enable_storage(False) \
.disable_trading_mode() \
.is_exchange_only()
if http_proxy_callback_factory:
proxy_callback = http_proxy_callback_factory(exchange_builder.exchange_manager)
exchange_builder.set_proxy_config(exchanges.ProxyConfig(http_proxy_callback=proxy_callback))
exchange_manager_instance = await exchange_builder.build()
# create trader afterwards to init exchange personal data
exchange_manager_instance.trader.is_enabled = True
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,25 @@ async def test_get_empty_linear_and_inverse_positions(self):
await self.inner_test_get_empty_linear_and_inverse_positions()

async def inner_test_get_empty_linear_and_inverse_positions(self):
if self.exchange_manager.exchange.SUPPORTS_SET_MARGIN_TYPE:
await self.set_margin_type(trading_enums.MarginType.ISOLATED)
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
trading_enums.MarginType.ISOLATED
)
await self.set_margin_type(trading_enums.MarginType.CROSS)
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
trading_enums.MarginType.CROSS
)
else:
await self._inner_test_get_empty_linear_and_inverse_positions_for_margin_type(None)

async def _inner_test_get_empty_linear_and_inverse_positions_for_margin_type(
self, margin_type: trading_enums.MarginType
):
positions = await self.get_positions()
self._check_positions_content(positions)
position = await self.get_position(self.SYMBOL)
self._check_position_content(position, self.SYMBOL)
self._check_position_content(position, self.SYMBOL, margin_type=margin_type)
for contract_type in (trading_enums.FutureContractType.LINEAR_PERPETUAL,
trading_enums.FutureContractType.INVERSE_PERPETUAL):
if not self.has_empty_position(self.get_filtered_positions(positions, contract_type)):
Expand Down Expand Up @@ -134,11 +149,13 @@ def _check_positions_content(self, positions):
for position in positions:
self._check_position_content(position, None)

def _check_position_content(self, position, symbol, position_mode=None):
def _check_position_content(self, position, symbol, position_mode=None, margin_type=None):
if symbol:
assert position[trading_enums.ExchangeConstantsPositionColumns.SYMBOL.value] == symbol
else:
assert position[trading_enums.ExchangeConstantsPositionColumns.SYMBOL.value]
if margin_type:
assert position[trading_enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value] == margin_type
leverage = position[trading_enums.ExchangeConstantsPositionColumns.LEVERAGE.value]
assert isinstance(leverage, decimal.Decimal)
# should not be 0 in octobot
Expand All @@ -149,11 +166,28 @@ def _check_position_content(self, position, symbol, position_mode=None):
assert position[trading_enums.ExchangeConstantsPositionColumns.POSITION_MODE.value] is position_mode

async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
if self.exchange_manager.exchange.SUPPORTS_SET_MARGIN_TYPE:
await self.set_margin_type(trading_enums.MarginType.ISOLATED)
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
symbol=symbol, settlement_currency=settlement_currency, margin_type=trading_enums.MarginType.ISOLATED
)
await self.set_margin_type(trading_enums.MarginType.CROSS)
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
symbol=symbol, settlement_currency=settlement_currency, margin_type=trading_enums.MarginType.CROSS
)
else:
await self._inner_test_create_and_cancel_limit_orders_for_margin_type(
symbol=symbol, settlement_currency=settlement_currency, margin_type=None
)

async def _inner_test_create_and_cancel_limit_orders_for_margin_type(
self, symbol=None, settlement_currency=None, margin_type=None
):
# test with linear symbol
await super().inner_test_create_and_cancel_limit_orders()
await super().inner_test_create_and_cancel_limit_orders(margin_type=margin_type)
# test with inverse symbol
await super().inner_test_create_and_cancel_limit_orders(
symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY
symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY, margin_type=margin_type
)

async def inner_test_create_and_fill_market_orders(self):
Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_ascendex.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -57,6 +60,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
12 changes: 10 additions & 2 deletions additional_tests/exchanges_tests/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class TestBinanceAuthenticatedExchange(
'7457313043',
'7457370420',
]
IS_BROKER_ENABLED_ACCOUNT = False
IS_AUTHENTICATED_REQUEST_CHECK_AVAILABLE = True # set True when is_authenticated_request is implemented


async def test_get_portfolio(self):
await super().test_get_portfolio()
Expand All @@ -48,6 +51,9 @@ async def test_get_portfolio_with_market_filter(self):
async def test_get_account_id(self):
await super().test_get_account_id()

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -60,6 +66,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand All @@ -76,8 +85,7 @@ async def test_get_cancelled_orders(self):
await super().test_get_cancelled_orders()

async def test_create_and_cancel_stop_orders(self):
# pass if not implemented
pass
await super().test_create_and_cancel_stop_orders()

async def test_edit_limit_order(self):
# pass if not implemented
Expand Down
24 changes: 18 additions & 6 deletions additional_tests/exchanges_tests/test_binance_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ class TestBinanceFuturesAuthenticatedExchange(
EXCHANGE_NAME = "binance"
CREDENTIALS_EXCHANGE_NAME = "BINANCE_FUTURES"
ORDER_CURRENCY = "BTC"
SETTLEMENT_CURRENCY = "USDT"
SETTLEMENT_CURRENCY = "USDC"
SYMBOL = f"{ORDER_CURRENCY}/{SETTLEMENT_CURRENCY}:{SETTLEMENT_CURRENCY}"
INVERSE_SYMBOL = f"{ORDER_CURRENCY}/USD:{ORDER_CURRENCY}"
ORDER_SIZE = 10 # % of portfolio to include in test orders
ORDER_SIZE = 30 # % of portfolio to include in test orders
DUPLICATE_TRADES_RATIO = 0.1 # allow 10% duplicate in trades (due to trade id set to order id)
IS_ACCOUNT_ID_AVAILABLE = False # set False when get_account_id is not available and should be checked
VALID_ORDER_ID = "26408108410"
EXPECTED_QUOTE_MIN_ORDER_SIZE = 200 # min quote value of orders to create (used to check market status parsing)
IS_AUTHENTICATED_REQUEST_CHECK_AVAILABLE = True # set True when is_authenticated_request is implemented

async def _set_account_types(self, account_types):
# todo remove this and use both types when exchange-side multi portfolio is enabled
Expand All @@ -51,6 +52,9 @@ async def test_get_portfolio_with_market_filter(self):
async def test_get_account_id(self):
await super().test_get_account_id()

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand Down Expand Up @@ -81,21 +85,29 @@ async def test_get_and_set_margin_type(self):
async def test_get_and_set_leverage(self):
await super().test_get_and_set_leverage()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

async def inner_test_create_and_cancel_limit_orders(self, symbol=None, settlement_currency=None):
async def _inner_test_create_and_cancel_limit_orders_for_margin_type(
self, symbol=None, settlement_currency=None, margin_type=None
):
# todo remove this and use both types when exchange-side multi portfolio is enabled
# test with linear symbol
await self._set_account_types(
[self.exchange_manager.exchange.LINEAR_TYPE]
)
await abstract_authenticated_exchange_tester.AbstractAuthenticatedExchangeTester\
.inner_test_create_and_cancel_limit_orders(self)
.inner_test_create_and_cancel_limit_orders(self, margin_type=margin_type)
# test with inverse symbol
await self._set_account_types(
[self.exchange_manager.exchange.INVERSE_TYPE]
)
await abstract_authenticated_exchange_tester.AbstractAuthenticatedExchangeTester\
.inner_test_create_and_cancel_limit_orders(
self, symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY
self, symbol=self.INVERSE_SYMBOL, settlement_currency=self.ORDER_CURRENCY, margin_type=margin_type
)

async def test_create_and_fill_market_orders(self):
Expand Down
10 changes: 8 additions & 2 deletions additional_tests/exchanges_tests/test_bingx.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestBingxAuthenticatedExchange(
IGNORE_EXCHANGE_TRADE_ID = True
USE_ORDER_OPERATION_TO_CHECK_API_KEY_RIGHTS = True
EXPECT_MISSING_FEE_IN_CANCELLED_ORDERS = False
IS_AUTHENTICATED_REQUEST_CHECK_AVAILABLE = True # set True when is_authenticated_request is implemented

VALID_ORDER_ID = "1812980957928929280"

Expand All @@ -46,6 +47,9 @@ async def test_get_portfolio_with_market_filter(self):
async def test_get_account_id(self):
await super().test_get_account_id()

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -58,6 +62,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand All @@ -74,8 +81,7 @@ async def test_get_cancelled_orders(self):
await super().test_get_cancelled_orders()

async def test_create_and_cancel_stop_orders(self):
# pass if not implemented
pass
await super().test_create_and_cancel_stop_orders()

async def test_edit_limit_order(self):
# pass if not implemented
Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_bitget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -59,6 +62,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_bitmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -57,6 +60,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_bybit.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -61,6 +64,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_bybit_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -73,6 +76,9 @@ async def test_get_and_set_margin_type(self):
async def test_get_and_set_leverage(self):
await super().test_get_and_set_leverage()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
11 changes: 9 additions & 2 deletions additional_tests/exchanges_tests/test_coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TestCoinbaseAuthenticatedExchange(
VALID_ORDER_ID = "8bb80a81-27f7-4415-aa50-911ea46d841c"
USE_ORDER_OPERATION_TO_CHECK_API_KEY_RIGHTS = True # set True when api key rights can't be checked using a
EXPECT_MISSING_FEE_IN_CANCELLED_ORDERS = False
IS_BROKER_ENABLED_ACCOUNT = False
IS_AUTHENTICATED_REQUEST_CHECK_AVAILABLE = True # set True when is_authenticated_request is implemented

async def test_get_portfolio(self):
await super().test_get_portfolio()
Expand All @@ -44,6 +46,9 @@ async def test_get_portfolio_with_market_filter(self):
async def test_get_account_id(self):
await super().test_get_account_id()

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -56,6 +61,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand All @@ -72,8 +80,7 @@ async def test_get_cancelled_orders(self):
await super().test_get_cancelled_orders()

async def test_create_and_cancel_stop_orders(self):
# pass if not implemented
pass
await super().test_create_and_cancel_stop_orders()

async def test_edit_limit_order(self):
# pass if not implemented
Expand Down
6 changes: 6 additions & 0 deletions additional_tests/exchanges_tests/test_coinex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ async def test_get_account_id(self):
# pass if not implemented
pass

async def test_is_authenticated_request(self):
await super().test_is_authenticated_request()

async def test_invalid_api_key_error(self):
await super().test_invalid_api_key_error()

Expand All @@ -56,6 +59,9 @@ async def test_missing_trading_api_key_permissions(self):
async def test_get_not_found_order(self):
await super().test_get_not_found_order()

async def test_is_valid_account(self):
await super().test_is_valid_account()

async def test_create_and_cancel_limit_orders(self):
await super().test_create_and_cancel_limit_orders()

Expand Down
Loading
Loading