-
Notifications
You must be signed in to change notification settings - Fork 85
Futures #1384
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
Merged
Merged
Futures #1384
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eb46410
[Kucoin] warn on fetch position without currencies
GuillaumeDSM 82a7c33
[Binance] simplify position parsing
GuillaumeDSM 61107d9
[Kucoin] handle cross positions parsing
GuillaumeDSM e8b8068
[Kucoin] handle no given symbol balance fetch
GuillaumeDSM c1988a9
[Binance] add futures exchange get_account_id
GuillaumeDSM 03df20c
[Binance] fix position parsing
GuillaumeDSM 3a0e0a6
[TradingView] interrupt signal exec on invalid signal value
GuillaumeDSM db33c99
[ScriptedLib] fix tests
GuillaumeDSM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
Meta/Keywords/scripting_library/tests/orders/position_size/test_amount.py
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,8 @@ class Kucoin(exchanges.RestExchange): | |
| ("order does not exist",), | ||
| ] | ||
|
|
||
| DEFAULT_BALANCE_CURRENCIES_TO_FETCH = ["USDT"] | ||
|
|
||
| @classmethod | ||
| def get_name(cls): | ||
| return 'kucoin' | ||
|
|
@@ -288,9 +290,16 @@ async def get_balance(self, **kwargs: dict): | |
| if self.exchange_manager.is_future: | ||
| # on futures, balance has to be fetched per currency | ||
| # use gather to fetch everything at once (and not allow other requests to get in between) | ||
| currencies = self.exchange_manager.exchange_config.get_all_traded_currencies() | ||
| if not currencies: | ||
| currencies = self.DEFAULT_BALANCE_CURRENCIES_TO_FETCH | ||
| self.logger.warning( | ||
| f"Can't fetch balance on {self.exchange_manager.exchange_name} futures when no traded currencies " | ||
| f"are set, fetching {currencies[0]} balance instead" | ||
| ) | ||
| await asyncio.gather(*( | ||
| self._update_balance(balance, currency, **kwargs) | ||
| for currency in self.exchange_manager.exchange_config.get_all_traded_currencies() | ||
| for currency in currencies | ||
| )) | ||
| return balance | ||
| return await super().get_balance(**kwargs) | ||
|
|
@@ -333,8 +342,21 @@ async def create_order(self, order_type: trading_enums.TraderOrderType, symbol: | |
| side: trading_enums.TradeOrderSide = None, current_price: decimal.Decimal = None, | ||
| reduce_only: bool = False, params: dict = None) -> typing.Optional[dict]: | ||
| if self.exchange_manager.is_future: | ||
| params = params or {} | ||
| # on futures exchange expects, quantity in contracts: convert quantity into contracts | ||
| quantity = quantity / self.get_contract_size(symbol) | ||
| try: | ||
| # "marginMode": "ISOLATED" // Added field for margin mode: ISOLATED, CROSS, default: ISOLATED | ||
| # from https://www.kucoin.com/docs/rest/futures-trading/orders/place-order | ||
| if ( | ||
| KucoinCCXTAdapter.KUCOIN_MARGIN_MODE not in params and | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_position_margin_type( | ||
| symbol | ||
| ) is trading_enums.MarginType.CROSS | ||
| ): | ||
| params[KucoinCCXTAdapter.KUCOIN_MARGIN_MODE] = "CROSS" | ||
| except ValueError as err: | ||
| self.logger.error(f"Impossible to add {KucoinCCXTAdapter.KUCOIN_MARGIN_MODE} to order: {err}") | ||
| return await super().create_order(order_type, symbol, quantity, | ||
| price=price, stop_price=stop_price, | ||
| side=side, current_price=current_price, | ||
|
|
@@ -448,6 +470,7 @@ class KucoinCCXTAdapter(exchanges.CCXTAdapter): | |
|
|
||
| # ORDER | ||
| KUCOIN_LEVERAGE = "leverage" | ||
| KUCOIN_MARGIN_MODE = "marginMode" | ||
|
|
||
| def fix_order(self, raw, symbol=None, **kwargs): | ||
| raw_order_info = raw[ccxt_enums.ExchangePositionCCXTColumns.INFO.value] | ||
|
|
@@ -515,13 +538,9 @@ def parse_funding_rate(self, fixed, from_ticker=False, **kwargs): | |
| def parse_position(self, fixed, **kwargs): | ||
| raw_position_info = fixed[ccxt_enums.ExchangePositionCCXTColumns.INFO.value] | ||
| parsed = super().parse_position(fixed, **kwargs) | ||
| parsed[trading_enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value] = \ | ||
| trading_enums.MarginType( | ||
| fixed.get(ccxt_enums.ExchangePositionCCXTColumns.MARGIN_MODE.value) | ||
| ) | ||
| parsed[trading_enums.ExchangeConstantsPositionColumns.POSITION_MODE.value] = \ | ||
| trading_enums.PositionMode.HEDGE if raw_position_info[self.KUCOIN_AUTO_DEPOSIT] \ | ||
| else trading_enums.PositionMode.ONE_WAY | ||
| parsed[trading_enums.ExchangeConstantsPositionColumns.AUTO_DEPOSIT_MARGIN.value] = ( | ||
| raw_position_info.get(self.KUCOIN_AUTO_DEPOSIT, False) # unset for cross positions | ||
| ) | ||
| parsed_leverage = self.safe_decimal( | ||
| parsed, trading_enums.ExchangeConstantsPositionColumns.LEVERAGE.value, constants.ZERO | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary anymore right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, it's there now https://github.com/Drakkar-Software/OctoBot-Trading/pull/1126/files#diff-e5b326dc37c0f13e228463fcd9ab3d5bcf3468d73b023398dfdc2130eaa671bdR281