hummingbot / hummingbot

Open source software that helps you create and deploy high-frequency crypto trading bots
https://hummingbot.org
Apache License 2.0
8k stars 2.79k forks source link

Bybit spot wrong order amount when market buying #5863

Open Myobbb opened 1 year ago

Myobbb commented 1 year ago

Bybit spot uses the same order amount for both sides of the trading pair.

I.E. if order_amount is set to 100, it will attempt to sell 100 tokens for USDT but also tries to buy $100 worth of tokens instead of just buying 100 tokens.

It happens when using amm_arb strategy with dex(quickswap) as a second connector and attempting to sell on Bybit spot.

release version 1.9.0 as well as dev-1.10.0

Screenshot 2022-11-05 at 12 25 56 AM logs_conf_amm_arb.log

Myobbb commented 1 year ago

Update:

The same issue happens when using arb strategy with Bybit paired with another CEX

Bybit side swaps amounts for sides when buying, executes the orders, buy order goes through on Bybit but in the logs it says "market order canceled" straight after and order is left in "pending orders list" when using "status" command

1.10.0 dev-1.11.0

logs_conf_arb_bb_buy_fail_example.log

nikspz commented 1 year ago

Hi @Myobbb, could you please provide more info, did you use different or same base asset to trade? for AMM arbitrage bot should use 1st base asset amount to trade

Myobbb commented 1 year ago

same base asset in all instances

it's an issue with Bybit spot connector

Myobbb commented 1 year ago

Here is another hopefully more clean example, where Bybit spot uses wrong amount when buying, buying in the amount of USDT instead of token it's paired to

logs_conf_arb_buy_fail.log

nikspz commented 1 year ago

hi @Myobbb could you please check rate --token YOUR_TOKEN rate --pair YOUR_TOKEN-USDT commands for YOUR_TOKEN? Also needed to check rate_oracle_source you use in config. Issue you had could be related to your token is not available in rate oracle you use.

Myobbb commented 1 year ago

Issue persists with use_oracle_conversion_rate set to False it's exact same pair on both sides of arbitrage, so I never needed to convert

so I guess it rules out rate oracle being the reason behind it?

nikspz commented 1 year ago

Okay, nice. That's should be another issue, cause use_oracle_conversion_rate set to False not used in amm_arb strategy, it's part of XEMM (Cross exchange market making) strategy.

Also Looks like you use old version of hummingbot (use_oracle_conversion_rate was used in it), you could try to update version

@Myobbb Do you still have issue on Bybit spot the same order amount for both sides of the trading pair, using amm_arb?

Myobbb commented 1 year ago

@nikspz I could not recreate the issue with version 1.13.0 amm_arb on Bybit yet, trades just would not trigger when target price was reached, nothing in the logs.

It is my understanding that the issue with order amount is related to situations when Bybit is forced to do a market buy(limit orders in cross_exchange_market_making strategy are the correct size) and not a particular strategy, since I experienced it on both "arbitrage" and "amm_arb" in the previous version and no changes have been made to the Bybit CEX connector since. (The latest version in which I encountered this issue was dev-1.13.0 log example is above.)

will do further testing to confirm it.

Myobbb commented 1 year ago

update:

I just recreated the situation with the latest version(1.13.0), issue persists, orders go through (with the wrong order amount), HMB does not register them as successful, and the second side does not trigger (concurrent_order_submission is set to False).

Screenshot 2023-03-02 at 4 26 36 PM Screenshot 2023-03-02 at 4 28 40 PM logs_conf_amm_arb_CMP.log

nikspz commented 1 year ago

@Myobbb Thanks, I'll create a ticket for concurrent_order_submission. Could you please also provide your global config? especially rate oracle source that you use (this part) image

Myobbb commented 1 year ago

@nikspz concurrent_order_submission fails because of the initial problem with the Bybit market buy side, I don't think there is anything wrong with concurrent_order_submission in particular.

rate_oracle_source is kucoin, but I tried different ones in the past, and I don't think it actively plays a role here, tokens are paired 1:1

Image

nikspz commented 1 year ago

@Myobbb You're using kucoin rate oracle source and global token is USD

Noticed that bot failed to find rate for CMP when global_token is USD image

USDT should work better for kucoin rate_oracle_source After config global_token.global_token_name USDT: image image image image

Issue5863.zip

Myobbb commented 1 year ago

@nikspz Thanks for the tip, I recreated the situation with USDT as a global token, and it did not affect the issue. Please note that in your case you were only selling on Bybit, not buying, buying order amount is the problem.

Here are some more examples:

Image

Image

Image

Myobbb commented 1 year ago

I looked over Bybit v1 API docs https://bybit-exchange.github.io/docs-legacy/spot/v1/#t-placeactive

Under "Place Active Order" quantity, it says

Order quantity (for market orders: when side is Buy, this is in the quote currency. Otherwise, qty is in the base currency. For example, on BTCUSDT a Buy order is in USDT, otherwise it's in BTC. For limit orders, the qty is always in the base currency.)

probably the root of the problem.

Myobbb commented 1 year ago

As a temporary solution, I replaced

OrderType.MARKET with OrderType.LIMIT https://github.com/hummingbot/hummingbot/blob/master/hummingbot/connector/exchange/bybit/bybit_exchange.py#L114

Limit orders go through with the correct amounts.