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

Fut rights #70

Merged
merged 2 commits into from
Jan 9, 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).

## [1.2.31] - 2025-01-09
### Updated
- [Binance] handle futures trading rights

## [1.2.30] - 2024-12-02
### Updated
- [Binance] handle sandbox
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# trading-backend [1.2.30](https://github.com/Drakkar-Software/trading-backend/tree/master/CHANGELOG.md)
# trading-backend [1.2.31](https://github.com/Drakkar-Software/trading-backend/tree/master/CHANGELOG.md)
[![PyPI](https://img.shields.io/pypi/v/trading-backend.svg)](https://pypi.python.org/pypi/trading-backend/)
[![Downloads](https://pepy.tech/badge/trading-backend/month)](https://pepy.tech/project/trading-backend)
[![Github-Action-CI](https://github.com/Drakkar-Software/trading-backend/workflows/trading-backend-CI/badge.svg)](https://github.com/Drakkar-Software/trading-backend/actions)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from setuptools import find_packages
from setuptools import setup

VERSION = "1.2.30"
VERSION = "1.2.31"
PROJECT_NAME = "trading-backend"

PACKAGES = find_packages(exclude=["tests"])
Expand Down
6 changes: 3 additions & 3 deletions tests/exchanges/test_binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ async def test_get_api_key_rights(binance_exchange):
exchange = exchanges.Binance(binance_exchange)
with mock.patch.object(
exchange._exchange.connector.client, "sapi_get_account_apirestrictions",
mock.AsyncMock(return_value={"enableReading": True, "enableSpotAndMarginTrading": False, "enableWithdrawals": False})
mock.AsyncMock(return_value={"enableReading": True, "enableSpotAndMarginTrading": False, "enableFutures": True, "enableWithdrawals": False})
) as sapi_get_account_apirestrictions_mock:
assert await exchange._get_api_key_rights() == [
trading_backend.enums.APIKeyRights.READING
trading_backend.enums.APIKeyRights.READING,
trading_backend.enums.APIKeyRights.FUTURES_TRADING,
]
sapi_get_account_apirestrictions_mock.assert_awaited_once()
with mock.patch.object(
Expand All @@ -60,7 +61,6 @@ async def test_get_api_key_rights(binance_exchange):
trading_backend.enums.APIKeyRights.READING,
trading_backend.enums.APIKeyRights.SPOT_TRADING,
trading_backend.enums.APIKeyRights.MARGIN_TRADING,
trading_backend.enums.APIKeyRights.FUTURES_TRADING,
trading_backend.enums.APIKeyRights.WITHDRAWALS
]
sapi_get_account_apirestrictions_mock.assert_awaited_once()
Expand Down
1 change: 1 addition & 0 deletions trading_backend/exchanges/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def _get_api_key_rights(self) -> list[trading_backend.enums.APIKeyRights]:
if restrictions.get('enableSpotAndMarginTrading'):
rights.append(trading_backend.enums.APIKeyRights.SPOT_TRADING)
rights.append(trading_backend.enums.APIKeyRights.MARGIN_TRADING)
if restrictions.get('enableFutures'):
rights.append(trading_backend.enums.APIKeyRights.FUTURES_TRADING)
if restrictions.get('enableWithdrawals'):
rights.append(trading_backend.enums.APIKeyRights.WITHDRAWALS)
Expand Down
2 changes: 1 addition & 1 deletion trading_backend/exchanges/bingx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_name(cls):
async def _inner_cancel_order(self):
# use client api to avoid any ccxt call wrapping and error handling
try:
await self._exchange.connector.client.cancel_order("12345", symbol="BTC/USDT")
await self._exchange.connector.client.cancel_order("12345", symbol=self._get_symbol())
except ccxt.ExchangeError as err:
# ('bingx {"code":100413,"msg":"Incorrect apiKey","timestamp":1718551786654}',)
if "Incorrect apiKey".lower() in str(err).lower():
Expand Down
7 changes: 6 additions & 1 deletion trading_backend/exchanges/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ def get_orders_parameters(self, params=None) -> dict:
def _allow_withdrawal_right(self) -> bool:
return trading_backend.constants.ALLOW_WITHDRAWAL_KEYS

def _get_symbol(self):
if self._exchange.exchange_manager.is_future:
return "BTC/USDT:USDT"
return "BTC/USDT"

async def _inner_cancel_order(self):
# use client api to avoid any ccxt call wrapping and error handling
await self._exchange.connector.client.cancel_order("12345", symbol="BTC/USDT")
await self._exchange.connector.client.cancel_order("12345", symbol=self._get_symbol())

async def _get_api_key_rights_using_order(self) -> list[trading_backend.enums.APIKeyRights]:
rights = [trading_backend.enums.APIKeyRights.READING]
Expand Down
Loading