[go: nahoru, domu]

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

fix/ kucoin perpetual incorrect pozition size for market order #6578

Conversation

yancong001
Copy link
Contributor
@yancong001 yancong001 commented Sep 22, 2023

Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You are using approved title ("feat/", "fix/", "docs/", "refactor/")

A description of the changes proposed in the pull request:

Tests performed by the developer:

Tips for QA testing:

@nikspz nikspz linked an issue Sep 22, 2023 that may be closed by this pull request
@nikspz nikspz changed the title fix bug fix/ kucoin perpetual incorrect pozition size bug Sep 22, 2023
@nikspz nikspz changed the title fix/ kucoin perpetual incorrect pozition size bug fix/ kucoin perpetual incorrect pozition size for market order Sep 22, 2023
Copy link
Contributor
@cardosofede cardosofede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cardosofede
Copy link
Contributor

@yancong001 check that the isort is complaining for use type(something) == str instead of isinstance(something, str)

@yancong001
Copy link
Contributor Author

Currently tested with this script kucoin_perp_3.py.txt got flooded with Could not fetch last fee payment for BCH-USD. Check network connection. and hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - NETWORK - Unexpected error while fetching last fee payment for BCH-USD.

same thing using same script on latest development 1.20.0 (PerpetualMM on development works however)

pending script from the user

image

2023-09-22 09:08:32,649 - 410480 - hummingbot.client.hummingbot_application - INFO - start command initiated.
2023-09-22 09:08:32,909 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - INFO - Network status has changed to NetworkStatus.CONNECTED. Starting networking...
2023-09-22 09:08:33,001 - 410480 - hummingbot.strategy.script_strategy_base - WARNING - kucoin_perpetual is not ready. Please wait...
2023-09-22 09:08:34,001 - 410480 - hummingbot.strategy.script_strategy_base - WARNING - kucoin_perpetual is not ready. Please wait...
2023-09-22 09:08:34,726 - 410480 - hummingbot.core.utils.async_utils - ERROR - Unhandled error in background task: 'BCH-USD'
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/nikita/kucperpfix/hummingbot/core/data_type/order_book_tracker.py", line 180, in _init_order_books
    self._order_books[trading_pair] = await self._initial_order_book_for_trading_pair(trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/core/data_type/order_book_tracker.py", line 173, in _initial_order_book_for_trading_pair
    return await self._data_source.get_new_order_book(trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/core/data_type/order_book_tracker_data_source.py", line 65, in get_new_order_book
    snapshot_msg: OrderBookMessage = await self._order_book_snapshot(trading_pair=trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 205, in _order_book_snapshot
    exchange_symbol = await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair),
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,729 - 410480 - hummingbot.core.utils.async_utils - ERROR - Unhandled error in background task: 'BCH-USD'
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/nikita/kucperpfix/hummingbot/connector/perpetual_derivative_py_base.py", line 364, in _listen_for_funding_info
    await self._init_funding_info()
  File "/home/nikita/kucperpfix/hummingbot/connector/perpetual_derivative_py_base.py", line 371, in _init_funding_info
    funding_info = await self._orderbook_ds.get_funding_info(trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 43, in get_funding_info
    funding_info_response = await self._request_complete_funding_info(trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 192, in _request_complete_funding_info
    exchange_symbol = await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair),
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,731 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - NETWORK - Unexpected error while fetching last fee payment for BCH-USD.
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/perpetual_derivative_py_base.py", line 414, in _update_funding_payment
    timestamp, funding_rate, payment_amount = await self._fetch_last_fee_payment(trading_pair=trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_derivative.py", line 885, in _fetch_last_fee_payment
    exchange_symbol = await self.exchange_symbol_associated_to_pair(trading_pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,732 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - WARNING - Could not fetch last fee payment for BCH-USD. Check network connection.
2023-09-22 09:08:34,872 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_order_book_data_source.KucoinPerpetualAPIOrderBookDataSource - ERROR - Unexpected error occurred subscribing to order book trading and delta streams...
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 59, in _subscribe_channels
    symbols = ",".join([await self._connector.exchange_symbol_associated_to_pair(trading_pair=pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 59, in <listcomp>
    symbols = ",".join([await self._connector.exchange_symbol_associated_to_pair(trading_pair=pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,873 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_order_book_data_source.KucoinPerpetualAPIOrderBookDataSource - ERROR - Unexpected error occurred when listening to order book streams. Retrying in 5 seconds...
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/core/data_type/order_book_tracker_data_source.py", line 79, in listen_for_subscriptions
    await self._subscribe_channels(ws)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 59, in _subscribe_channels
    symbols = ",".join([await self._connector.exchange_symbol_associated_to_pair(trading_pair=pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_order_book_data_source.py", line 59, in <listcomp>
    symbols = ",".join([await self._connector.exchange_symbol_associated_to_pair(trading_pair=pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,939 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_user_stream_data_source.KucoinPerpetualAPIUserStreamDataSource - ERROR - Unexpected error occurred subscribing to order book trading and delta streams wss://stream.kucoin.com/realtime_private...
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_user_stream_data_source.py", line 120, in _subscribe_to_channels
    symbols = [
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_user_stream_data_source.py", line 121, in <listcomp>
    await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:34,939 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_user_stream_data_source.KucoinPerpetualAPIUserStreamDataSource - ERROR - Unexpected error while listening to user stream wss://stream.kucoin.com/realtime_private. Retrying after 5 seconds...
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_user_stream_data_source.py", line 86, in _listen_for_user_stream_on_url
    await self._subscribe_to_channels(ws, url, self._trading_pairs)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_user_stream_data_source.py", line 120, in _subscribe_to_channels
    symbols = [
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_api_user_stream_data_source.py", line 121, in <listcomp>
    await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:35,030 - 410480 - hummingbot.strategy.script_strategy_base - WARNING - kucoin_perpetual is not ready. Please wait...
2023-09-22 09:08:35,033 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - NETWORK - Unexpected error while fetching last fee payment for BCH-USD.
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/perpetual_derivative_py_base.py", line 414, in _update_funding_payment
    timestamp, funding_rate, payment_amount = await self._fetch_last_fee_payment(trading_pair=trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_derivative.py", line 885, in _fetch_last_fee_payment
    exchange_symbol = await self.exchange_symbol_associated_to_pair(trading_pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:35,034 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - WARNING - Could not fetch last fee payment for BCH-USD. Check network connection.
2023-09-22 09:08:35,034 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - NETWORK - Unexpected error while fetching last fee payment for BCH-USD.
Traceback (most recent call last):
  File "/home/nikita/kucperpfix/hummingbot/connector/perpetual_derivative_py_base.py", line 414, in _update_funding_payment
    timestamp, funding_rate, payment_amount = await self._fetch_last_fee_payment(trading_pair=trading_pair)
  File "/home/nikita/kucperpfix/hummingbot/connector/derivative/kucoin_perpetual/kucoin_perpetual_derivative.py", line 885, in _fetch_last_fee_payment
    exchange_symbol = await self.exchange_symbol_associated_to_pair(trading_pair)
  File "hummingbot/connector/exchange_base.pyx", line 97, in exchange_symbol_associated_to_pair
    return symbol_map.inverse[trading_pair]
  File "/home/nikita/miniconda3/envs/hummingbot/lib/python3.10/site-packages/bidict/_base.py", line 523, in __getitem__
    return self._fwdm[key]
KeyError: 'BCH-USD'
2023-09-22 09:08:35,035 - 410480 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - WARNING - Could not fetch last fee payment for BCH-USD. Check network connection.

please test BCH-USDT instead of BCH-USD

@yancong001
Copy link
Contributor Author

@yancong001 check that the isort is complaining for use type(something) == str instead of isinstance(something, str)

fixed

@nikspz
Copy link
Contributor
nikspz commented Sep 22, 2023

@yancong001 Thanks, Ran successfully using BCH-USDT

6578.zip
logs_kucoin_perp_3fixed.log
image
image

however failed to reproduce issue on development using my script, will wait for updates from user.
image

@nikspz
Copy link
Contributor
nikspz commented Sep 22, 2023

Could you check failing unit tests? @yancong001

@nikspz
Copy link
Contributor
nikspz commented Sep 22, 2023

Reproduced issue #6567 on latest development using perpetualMM strategy.
#6567 (comment)

Currently using this PR6578 - can't reproduce, after orders OPENED bot placed correct amount, ongoing longrun test

Test performed:
Cloned and install fix branch
Create perpetualMM using BCH-USDT and order amount 0.05
Get 9 trades, not reproduced currently
logs_kucperpfix.log

@yancong001
Copy link
Contributor Author

i will fix unittest tomorrow

@yancong001
Copy link
Contributor Author

fixed

Copy link
Contributor
@nikspz nikspz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Cloned and install fix branch
  • Create perpetualMM using kucoin perpetual, BCH-USDT and order amount 0.05
  • Review issue are not reproduced
  • Manually built docker image successfully

@nikspz nikspz merged commit 63f257c into hummingbot:development Sep 26, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Kucoin perpetual - incorrect position size in connector
4 participants