germangar / whook

WHOOK is a fully functional webhook for handling Tradingview Alerts to crypto exchanges in perpetual USDT futures. Supported exchanges: Binance, Kucoin, Bitget, Coinex, Okx, Bybit, Bingx, Kraken and Phemex.
MIT License
33 stars 9 forks source link

Error bitget when order with percetage of the wallet #14

Open iZnogoude opened 2 months ago

iZnogoude commented 2 months ago

I have a bot that place short order using a percentage of the walle. I have 200$ on the future account, and I use 100% of the wallet on this test and it returns in the log :

[2024/06/10][13:34:52]  ALERT: 2024-06-10 15:34:52 - BGUSER-1M3ZWDAW NOTUSDT sell 100% x1
[2024/06/10][13:34:52] ----------------------------
[2024/06/10][13:34:52]  * E: Invalid Order. Cancelling bitget {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1718026492923,"data":null}

Can you help me please? Do you think it could be an error by my side?

Thanks a lot

germangar commented 2 months ago

It's probably an error in the balance value on my side. I just changed that code as part of the other fix. I'll check and fix it now.

germangar commented 2 months ago

Can you update and try again? I can't test this one myself. I don't have more than 10usdt in Bitget.

iZnogoude commented 2 months ago

I just test and I have the same error.

FYI, i'm using CCXT 4.3.40

ubuntu@ip-172-31-16-xxx:~/whook$ git stash
Saved working directory and index state WIP on main: 662e4da Bitget (Fix): CCXT is now handling Bitget order parameters internally. If you update the script and Bitget doesn't work anymore make sure to update CCXT to the latest version.
ubuntu@ip-172-31-16-xxx:~/whook$ git pull
Updating 662e4da..383f327
Fast-forward
 main.py | 10 ----------
 1 file changed, 10 deletions(-)
germangar commented 2 months ago

I don't understand. As far as I can test with 10usdt seems to be working for me

I added a print to the code to check the balance conversion. Could you update and test it once more?

18:27:29 [bitget/bitget]  
18:27:29 [bitget/bitget]  ALERT: bitget NOTUSDT sell 100% x1
18:27:29 [bitget/bitget] ----------------------------       
   Balance: 10.01975372$ 100.0% = 10.01975372$
18:27:32 [bitget/bitget]  * Order successful: NOT/USDT:USDT sell 539.5 1x at price 0.018568 id 1184097873847549960
------------------------------
  1 positions found.
  NOT/USDT:USDT * isolated:1x * short * 530.0 * 9.8410[$] * -0.00[$] * -0.05%
------------------------------
iZnogoude commented 2 months ago

I should be cursed.....

[2024/06/10][21:52:43] ALERT: 2024-06-10 21:52:43 - BGUSER-1M3ZWDAW NOTUSDT sell 10% x1 [2024/06/10][21:52:43] ---------------------------- [2024/06/10][21:52:43] Balance: 196.40890111$ 10.0% = 19.640890111$ [2024/06/10][21:52:44] * E: Invalid Order. Cancelling bitget {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1718049164084,"data":null}

germangar commented 2 months ago

Wait what. The conversion is correct. I'm so confused right now.

iZnogoude commented 2 months ago

Me too.... I have a look on the bot, but it's working on bybit....

germangar commented 2 months ago

Don't worry. I keep trying to figure it out.

When you place orders in bitget with a value (not a percent) they do work, right? It only fails with the percent.

iZnogoude commented 2 months ago

Absolutely, my bot that I use in tradingview order in values not in percent.

germangar commented 2 months ago

Give it another try with the latest update, please.

iZnogoude commented 2 months ago

I Would like to give good news, but I still have the same problem.

What is this config.json file for? This seems to be cool :D [ { "ALERT_TIMEOUT":180, "ORDER_TIMEOUT":40, "REFRESH_POSITIONS_FREQUENCY":300, "UPDATE_ORDERS_FREQUENCY":0.25, "VERBOSE":false, "SHOW_BALANCE":false, "SHOW_ENTRYPRICE":false, "SHOW_BREAKEVEN":true, "TELEGRAM_BOT_TOKEN":"", "TELEGRAM_CHAT_ID":"", "TELEGRAM_WHOOK_URL":"", "TELEGRAM_MODE":"ADMIN", "USE_PROXY":true, "PROXY_PORT":50000 } ]

Le mar. 18 juin 2024 à 23:54, germangar @.***> a écrit :

Give it another try with the latest update, please.

— Reply to this email directly, view it on GitHub https://github.com/germangar/whook/issues/14#issuecomment-2177142637, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHVUAOA5XG5ZOG6G3SRLJWDZICUALAVCNFSM6AAAAABJCK34PSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZXGE2DENRTG4 . You are receiving this because you authored the thread.Message ID: @.***>

germangar commented 2 months ago

To configure a bunch of things without having to modify the script :)

The SHOW_* ones are to include those things when printing the positions.

The telegram stuff is a new feature to get notifications in telegram when an order fails. It's explained in the read.me now.

iZnogoude commented 2 months ago

Hello,

I'm working on a workaround for the percentage error of bitget. I did a script to get the value of the wallet. (thanks chatgpt which helps a lot) I will modify the function in the delist bot and will see.

Have a nice day

Le mer. 19 juin 2024 à 17:01, germangar @.***> a écrit :

To configure a bunch of things without having to modify the script :)

The telegram stuff is a new feature to get notifications in telegram when an order fails. It's explained in the read.me now.

— Reply to this email directly, view it on GitHub https://github.com/germangar/whook/issues/14#issuecomment-2178923803, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHVUAOGS7VNJRM7RLSCNDGLZIGMMVAVCNFSM6AAAAABJCK34PSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYHEZDGOBQGM . You are receiving this because you authored the thread.Message ID: @.***>

iZnogoude commented 2 months ago

I worked on a solution that use a value instead of a percentage of my wallet. I worked hard on that but I still have the issue.... The thing is that I use a bot on traddinview with the whook that works perfectly

With the delist bot :

19:12:13 [BGUSER-XXXX/bitget]  ALERT: 2024-06-21 19:12:13 - BGUSER-XXXX NOTUSDT sell 26.500679868 USDT x1
19:12:13 [BGUSER-XXXX/bitget] ----------------------------
19:12:16 [BGUSER-XXXX/bitget]  * E: Invalid Order. Cancelling bitget {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1718989936288,"data":null}

With TV bot :

[2024/06/22][04:00:06]  ALERT: BGUSER-XXXX ONDO/USDT:USDT sell 11.1@ x3
[2024/06/22][04:00:06] ----------------------------
[2024/06/22][04:00:07]  * Order successful: ONDO/USDT:USDT sell 11.1 3x at price 1.2102 id 1188228229530034176
[2024/06/22][08:00:04]  
[2024/06/22][08:00:04]  ALERT: BGUSER-1M3ZWDAW TON/USDT:USDT sell 1.5@ x3
[2024/06/22][08:00:04] ----------------------------
[2024/06/22][08:00:05]  * Order successful: TON/USDT:USDT sell 1.5 3x at price 7.162 id 1188288618884145159

There must be something wrong with the sell function I suppose.

germangar commented 2 months ago

BGUSER-XXXX NOTUSDT sell 26.500679868 USDT x1

You made a mistake in this alert. It's trying to sell 26,5 NOT, which is 0,371 USDT. For selling in usdt the amount has to look like this 26,5$ Can you try again?

iZnogoude commented 2 months ago

Same :'(

14:56:17 [BGUSER-1M3ZWDAW/bitget] ALERT: 2024-06-22 14:56:17 - BGUSER-XXXXXX NOTUSDT sell 25$ x1 14:56:17 [BGUSER-1M3ZWDAW/bitget] ---------------------------- 14:56:18 [BGUSER-1M3ZWDAW/bitget] * E: Invalid Order. Cancelling bitget {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1719060978643,"data":null}

germangar commented 2 months ago

Could you update whook and try once more with the same alert? I want to see how many NOTs is trying to sell

iZnogoude commented 2 months ago

15:16:10 [BGUSER-1M3ZWDAW/bitget] ALERT: 2024-06-22 15:16:10 - BGUSER-XXXXX NOTUSDT sell 25$ x1 15:16:10 [BGUSER-1M3ZWDAW/bitget] ---------------------------- 15:16:13 [BGUSER-1M3ZWDAW/bitget] * E: Order size invalid: 25.0 x1

germangar commented 2 months ago

Ok. That helps. For some reason it's not understanding the dollar sign and it thinks the order is in NOT. I'm now thinking this may be a text encoding issue. It's weird that it's printing the $ sign correctly, tho, but I think this may be it.

But you should be having the same problem in the other exchanges when you make this same order from your script.

iZnogoude commented 2 months ago

Here the part of the code where is the $. max_transfer_out is the amount of my wallet

short_amount = round((float(max_transfer_out) * percentage) / 100)
message = f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - {username} {highest_turnover_crypto} sell {short_amount}$ x{max_leverage}'
germangar commented 2 months ago

Yeah, that's totally fine. If anything I suspect it may be something in the code that sends the webhook not setting the right text encoding. But this is a field I don't know much about, tbh. It should be set to UTF8, I guess.

iZnogoude commented 2 months ago

In fact it's already implemented :

          if highest_turnover_crypto:
                with open(output_file, 'a', encoding='utf-8') as f:
                    f.write(f"{highest_turnover_crypto} - {valid_cryptos[highest_turnover_crypto]['info']}\n")
                print(f"Nouvelle crypto trouvée : {highest_turnover_crypto}")
                max_leverage = valid_cryptos[highest_turnover_crypto]['max_leverage']
                max_transfer_out = get_bitget_wallet_balance()
                if max_transfer_out is not None:
                    short_amount = round((float(max_transfer_out) * percentage) / 100)
                    message = f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - {username} {highest_turnover_crypto} sell {short_amount}$ x{max_leverage}'
germangar commented 2 months ago

Let's try this to see if the problem is really there. I just added the commands 'force_usdt', 'force_percent' and 'force_basecurrency'.

Update and try sending your alert including the command 'force_usdt'. Let see if that makes it work before anything else.

iZnogoude commented 2 months ago

Sorry, where I should add your command? I'm not a pro like you ^_^'

germangar commented 2 months ago

Just add it to the alert at the end. It's just a replacement for the dollar sign

BGUSER-XXXXX NOTUSDT sell 25 x1 force_usdt

iZnogoude commented 2 months ago

17:08:02 [BGUSER-1M3ZWDAW/bitget] ALERT: 2024-06-22 17:08:02 - BGUSER-XXXXXX NOTUSDT sell 25 x1 force_usdt 17:08:02 [BGUSER-1M3ZWDAW/bitget] ---------------------------- 17:08:04 [BGUSER-1M3ZWDAW/bitget] * E: Order size invalid: 25.0 x1

germangar commented 2 months ago

damn

You updated whook before sending it, right? I should have added a print ^_^'

iZnogoude commented 2 months ago

Yes I did ^_^'

A friend who is working on a another bot also, have problems with values and percentages quantity also with the whook. He is using bybit and not bitget. He has made a very simpliest script to buy and sell and it was working (without your whook) So mayby there is a deepest issue somewere. Did you think to split the whook to have one file by broker?

germangar commented 2 months ago

I have plans to split it so you don't need to send the alerts with a webhook, but import whook into your script.

I don't understand how it is failing. It is receiving the correct number. 25 is there. It's just not converting it from usdt to NOT. But I don't understand why.

Could you enable 'verbose' in the config file and do it once more? Check if the print that says "CONVERTING" gives a result other than 25?

iZnogoude commented 2 months ago

17:30:35 [BGUSER-1M3ZWDAW/bitget] ALERT: 2024-06-22 17:30:35 - BGUSER-XXXXX NOTUSDT sell 25 x1 force_usdt 17:30:35 [BGUSER-1M3ZWDAW/bitget] ---------------------------- CONVERTING (x1) 25.0 NOT ==> 25.0 contracts 17:30:38 [BGUSER-1M3ZWDAW/bitget] * E: Order size invalid: 25.0 x1

germangar commented 2 months ago

Ok, for some reason it's thinking it's not in USDT but in NOT. We are getting somewhere. I'm going to ask you for one more test. Hold on

germangar commented 2 months ago

Ok. Can you try one last time for today? Update and verbose on

iZnogoude commented 2 months ago

Well done lad !!!!

17:52:38 [BGUSER-1M3ZWDAW/bitget]  ALERT: 2024-06-22 17:52:38 - BGUSER-1M3ZWDAW NOTUSDT sell 25 x1 force_usdt
17:52:38 [BGUSER-1M3ZWDAW/bitget] ----------------------------
PROCESSALERT: alert['isUSDT']: True isUSDT: True
PROCESSALERT: alert['isBaseCurrency']: False isBaseCurrency: False
PROCESSALERT: isUSDT path
   CONVERTING (x1) 25.0 USDT ==> 1676.2 contracts
17:52:41  * Activating Order NOT/USDT:USDT sell 1676.2 1x id 1188437752102428675

NOT/USDT:USDT * cross:1x * short * 1670.0 * 24.9080[$] * 0.01[$] * 0.05% * [ep]0.015 * [be]0.0149

Shall I keep force_usdt or shall I put the $?

germangar commented 2 months ago

YAY!

I'm pretty sure if you issue the order with 25$ it will still fail. But at least it works now with 25 force_usdt. I'll leave dealing with the charset encoding for another day (mabye).

germangar commented 2 months ago

You should be able to use force_percent now too

iZnogoude commented 2 months ago

I will try that and let you know. Thanks a lot !

a202037 commented 3 weeks ago

Hi, thanks for the efforts and it is a great repo.

For Bitget, I have encountered the following error when trading futures. Could you help to fix it? I think it is related to one-way/ hedge mode issue. This error only happens when using one-way mode

"code":"40774","msg":"The order type for unilateral position must also be the unilateral position type."

germangar commented 3 weeks ago

Hey, I only support one-way. Hedge mode is not supported.

This is weird because I'm currently running scripts in Bitget and everything is working fine for me. I haven't updated ccxt in a while, tho. I'll try updating and see if there's some recent change that triggered it.

In the meantime, could you paste your alert here so I can try to reproduce it?