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_leverage #6640

Merged

Conversation

leastchaos
Copy link
Contributor

@leastchaos leastchaos commented Nov 3, 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:
leverage is set in the place_order and not using risk_level_limit.
risk level limit is an account setting which determine the max leverage for that symbol only.
image
anything more than 8 will result in leverage always be stuck at one as it will always fail and will also result in max leverage setting changed to lower than current leverage.

Tests performed by the developer:

Tips for QA testing:

@leastchaos leastchaos changed the title Fix_kucoin_perpetual_leverage Fix/kucoin_perpetual_leverage Nov 3, 2023
@nikspz
Copy link
Contributor

nikspz commented Nov 7, 2023

hi @leastchaos Could you please fix unit-tests?
image

@rapcmia rapcmia requested a review from nikspz November 8, 2023 12:43
@nikspz
Copy link
Contributor

nikspz commented Nov 10, 2023

Kucoin use leverage 1, however config set to 3 (same thing for config leverage 10)

Steps:

  1. Clone and install fix branch
  2. Create/start perpetualMM with kucoin_perpetual and leverage 3 (or leverage 10)
  3. Review orders leverage on exchange

Actual:
leverage 1 used for orders

Kucoin perpetual leverage fix PR2

@leastchaos
Copy link
Contributor Author

leastchaos commented Nov 13, 2023

Kucoin use leverage 1, however config set to 3 (same thing for config leverage 10)

Steps:

  1. Clone and install fix branch
  2. Create/start perpetualMM with kucoin_perpetual and leverage 3 (or leverage 10)
  3. Review orders leverage on exchange

Actual: leverage 1 used for orders

Kucoin perpetual leverage fix PR2 Kucoin perpetual leverage fix PR2

I think this is another bug in the perpetual_market_making strategy...

        if not self._position_mode_ready:
            self._position_mode_not_ready_counter += 1
            # Attempt to switch position mode every 10 ticks only to not spam and DDOS
            if self._position_mode_not_ready_counter == 10:
                market: DerivativeBase = self._market_info.market
                if market.ready:
                    market.set_leverage(self.trading_pair, self._leverage)
                    market.set_position_mode(self._position_mode)
                self._position_mode_not_ready_counter = 0
            return

set leverage will only be activated only when market is ready.
from your log, the strategy did not attempt to set the leverage at all as market is not ready.
It should try to set leverage and position mode at the start to prevent this siutation.

    def start(self, clock: Clock, timestamp: float):
        self._market_info.market.set_leverage(self.trading_pair, self._leverage)

you can add this 2 line to the strategy to ensure that the leverage is set by the strategy to test.

@rapcmia
Copy link
Contributor

rapcmia commented Nov 16, 2023

    def start(self, clock: Clock, timestamp: float):
        self._market_info.market.set_leverage(self.trading_pair, self._leverage)

you can add this 2 line to the strategy to ensure that the leverage is set by the strategy to test.

Thanks for the fix on perpetual market making strategy @leastchaos, I confirm that it works on #6658. However when I tried to add it here on this PR, im not getting this behavior on the screenshot and does not change the leverage to desired value.

image

  • I made sure this has been added import and func but does not get this result
  • The leverage is still set to 1, see logs below
    image
    2023-11-16 21:44:30,838 - 6459 - hummingbot.client.hummingbot_application - INFO - start command initiated.
    2023-11-16 21:44:30,882 - 6459 - hummingbot.strategy.perpetual_market_making.perpetual_market_making - INFO - Changing position mode to ONEWAY succeeded.
    2023-11-16 21:44:31,060 - 6459 - hummingbot.strategy.perpetual_market_making.perpetual_market_making - WARNING - Markets are not ready. No market making trades are permitted.
    2023-11-16 21:44:31,298 - 6459 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_derivative.KucoinPerpetualDerivative - INFO - Network status has changed to NetworkStatus.CONNECTED. Starting networking...
    2023-11-16 21:44:31,945 - 6459 - hummingbot.core.data_type.order_book_tracker - INFO - Initialized order book for LOOKS-USDT. 1/1 completed.
    2023-11-16 21:44:37,439 - 6459 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_user_stream_data_source.KucoinPerpetualAPIUserStreamDataSource - INFO - Subscribed to private account and orders channels wss://stream.kucoin.com/realtime_private...
    2023-11-16 21:44:37,487 - 6459 - hummingbot.connector.derivative.kucoin_perpetual.kucoin_perpetual_api_order_book_data_source.KucoinPerpetualAPIOrderBookDataSource - INFO - Subscribed to public order book, trade and funding info channels...
    2023-11-16 21:44:38,001 - 6459 - hummingbot.strategy.perpetual_market_making.perpetual_market_making - INFO - (LOOKS-USDT) Creating 1 LIMIT bid orders at (Size, Price): ['1E+2 LOOKS, 0.07797 USDT'] to OPEN position.
    2023-11-16 21:44:38,002 - 6459 - hummingbot.strategy.perpetual_market_making.perpetual_market_making - INFO - (LOOKS-USDT) Creating 1  LIMIT ask orders at (Size, Price): ['1E+2 LOOKS, 0.07955 USDT'] to OPEN position.
    2023-11-16 21:44:38,457 - 6459 - hummingbot.connector.client_order_tracker - INFO - Created LIMIT BUY order HummingbotBLSUT60a45388c461acc9b6fcf81a6 for 100.0 to OPEN a LOOKS-USDT position.
    2023-11-16 21:44:38,457 - 6459 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1700142278.0, "type": "OrderType.LIMIT", "trading_pair": "LOOKS-USDT", "amount": "100.0", "price": "0.07797", "order_id": "HummingbotBLSUT60a45388c461acc9b6fcf81a6", "creation_timestamp": 1700142278.0, "exchange_order_id": "114626454481801217", "leverage": 1, "position": "OPEN", "event_name": "BuyOrderCreatedEvent", "event_source": "kucoin_perpetual"}
    2023-11-16 21:44:38,517 - 6459 - hummingbot.connector.client_order_tracker - INFO - Created LIMIT SELL order HummingbotSLSUT60a45388c4782cc9b6fcf81a6 for 100.0 to OPEN a LOOKS-USDT position.
    2023-11-16 21:44:38,517 - 6459 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": 1700142278.0, "type": "OrderType.LIMIT", "trading_pair": "LOOKS-USDT", "amount": "100.0", "price": "0.07955", "order_id": "HummingbotSLSUT60a45388c4782cc9b6fcf81a6", "creation_timestamp": 1700142278.0, "exchange_order_id": "114626454515421185", "leverage": 1, "position": "OPEN", "event_name": "SellOrderCreatedEvent", "event_source": "kucoin_perpetual"}
    

logs_perp-kucoin2.log

@leastchaos
Copy link
Contributor Author

@rapcmia i think you can test with this pr directly now
image

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.

Test performed:

  • Cloned and installed fix branch
  • Manually built docker image successfully
  • Created/started perpetualMM using kucoin_perpetual and leverages 3/5/10/15
  • Got orders to OPEN filled
  • Review stop-loss and take profit works as expected
  • Review opened position leverage shows in status

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.

Good job @leastchaos ! LGTM

@cardosofede cardosofede merged commit 40eb299 into hummingbot:development Nov 17, 2023
1 of 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.

None yet

4 participants