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/bybit connector upgrade v5 #6902

Open
wants to merge 75 commits into
base: development
Choose a base branch
from

Conversation

klpanagi
Copy link
Contributor

@klpanagi klpanagi commented Mar 9, 2024

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:

This PR is relevant to the bounty for upgrading Bybit API to V5

Bybit Spot / Perpetual - Upgrade API to V5

Currently supports the Spot API.

Tests performed by the developer:

Tips for QA testing:

@nikspz nikspz changed the base branch from master to development March 11, 2024 06:40
@nikspz
Copy link
Contributor

nikspz commented Mar 11, 2024

hi @klpanagi, thank you for submitting PR, fyi, it should be aimed to development, changed https://hummingbot.org/developers/contributions/#checklist

@klpanagi klpanagi force-pushed the fix/bybit_connector_upgrade_v5 branch from 46ce123 to 30bcc31 Compare March 13, 2024 20:37
Copy link

1 similar comment
Copy link

@nikspz
Copy link
Contributor

nikspz commented Apr 29, 2024

You must be using a Unified account. I just noticed that the free parameter is missing for Unified accounts and availableToWithdraw must be used. I will fix this asap.

Yes we're used Unified account, checking latest commit now

@nikspz
Copy link
Contributor

nikspz commented Apr 29, 2024

@klpanagi
commit 3634342
Unified trading account on spot:

DOGE-USDT - place order with wrong price❌

image
image

XRP-USDT - place order with wrong price❌

image
image

SOL-USDT - correct price ✅

image
image

@klpanagi
Copy link
Contributor Author

klpanagi commented Apr 30, 2024

@klpanagi commit 3634342 Unified trading account on spot:

DOGE-USDT - place order with wrong price❌

The order price issue is caused from the trading rule parameters returned from the relevant ByBit API endpoint (https://bybit-exchange.github.io/docs/v5/market/instrument#response-parameters).

The basePrecision and quotePrecision response parameters are used to define the min_base_amount_increment and min_quote_amount_increment properties of each TradingRule as below:

TradingRule(
    trading_pair,
    min_order_size=Decimal(lot_size_filter.get("minOrderAmt")),
    max_order_size=Decimal(lot_size_filter.get("maxOrderAmt")),
    min_price_increment=Decimal(price_filter.get("tickSize")),
    min_base_amount_increment=Decimal(lot_size_filter.get("basePrecision")),
    min_quote_amount_increment=Decimal(lot_size_filter.get('quotePrecision')),
    min_notional_size=Decimal(lot_size_filter.get("minOrderAmt"))
)

The /v5/market/instruments-info ByBit API endpoint returns the below for DOGE-USDT, for example.

image

Notice that the value of basePrecision returned from the API is 0.1 , and this causes rounding the actual order price is the cases mentioned above.

Am I missing or interpreting something wrong here?

UPDATE: Working on a solution...

UPDATE 2: Order prices seem to match the expected. @nikspz please pull the last commit.

@nikspz
Copy link
Contributor

nikspz commented Apr 30, 2024

@klpanagi

  • commit 562c686
    • cloned and installed PR6902
    • connected bybit spot, checked balance successfully
    • created/started pureMM strategy successfully
    • orders placed with correct price for DOGE-USDT, XRP-USDT
    • ETH-USDT Failed to place order with order amount 0.01 eth using Client
      • tested manually
        • able to place order with 0.01 ETH and 0.005 ETH amount, lower than minimum order size (1)
    • Same thing for BTC-USDT Failed to place order with order amount 0.0005 BTC using Client - lower than minimum order size (1)
    • Same for SOL-USDT Failed to place order with order amount 0.2 SOL

image
image

image

Manually able to place:
image

DOGE-USDT Fixed
DOGE-USDT bybit 562

@nikspz
Copy link
Contributor

nikspz commented May 1, 2024

Steps:

  1. Clone PR6902, commit f37f115
  2. connect bybit
  3. Create/start pureMM using bybit spot
  4. get multiple orders filled

Actual:
Review the Error: 'qty'

logs_conf_pure_mm_2.log
comf37f115.zip

WARNING - Failed to fetch trade updates for order BYBIT-BXPUT61764f19e743fa3459773. Error: 'qty'
Traceback (most recent call last):
  File "/home/nikita/bybitv5/hummingbot/connector/exchange_py_base.py", line 956, in _update_orders_fills
    trade_updates = await self._all_trade_updates_for_order(order=order)
  File "/home/nikita/bybitv5/hummingbot/connector/exchange/bybit/bybit_exchange.py", line 426, in _all_trade_updates_for_order
    fill_base_amount=Decimal(trade["qty"]),
KeyError: 'qty'

@nikspz
Copy link
Contributor

nikspz commented May 6, 2024

  • Test performed:

    • Connect an Bybit API key successfully
    • balance Displays the current available balance and match the balance in Bybit spot.
    • Markets availabe during the strategy creation
    • Created /started pureMM using Bybit spot
    • Order submission and cancellation is okay
    • status or status --live is okay
    • order_book --live is okay
    • Able to run fast/slow refresh rate config successfully
    • Hanging orders behave as expected

    Pending:
    Longrun test
    Perpetual connector fix

Steps:

  1. Clone and install PR6902
  2. connect fresh bybit_perpetual API keys

Actual:
Failed to check bybit_perpetual balance

image
image

@nikspz nikspz marked this pull request as ready for review May 15, 2024 13:16
klpanagi added a commit to klpanagi/hummingbot that referenced this pull request May 19, 2024
@klpanagi
Copy link
Contributor Author

klpanagi commented May 19, 2024

Steps:

1. Clone and install PR6902

2. connect fresh bybit_perpetual API keys

Actual: Failed to check bybit_perpetual balance

image image

@nikspz I cannot reproduce this error. I have tested with both Classic and Unified accounts and i get the balance as expected

image

I will split the PR into separate for Spot and Perp connectors, so maybe we shall continue the discussion there. I will post here as soon as I have the PRs ready.

@Silur
Copy link

Silur commented May 23, 2024

also tested for over 16 hours now and balances are reflected correctly (spot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Dev Work
Development

Successfully merging this pull request may close these issues.

None yet

4 participants