enarjord / passivbot

Trading bot running on Binance, Bybit, Bitget, OKX, BingX, and Hyperliquid
https://www.passivbot.com
Other
1.07k stars 403 forks source link

ByBit USDT perpetual not working #420

Closed dasbts closed 9 months ago

dasbts commented 10 months ago

Hi,

The ByBit exchange has inactivated some of their API REST and WS endpoints, I believe this is why it is no longer trading at all for me since some time ago (gives me a good idea to implement some form of "last trade was long ago" reconciliation.

See issue in hummingbot for details: https://github.com/hummingbot/hummingbot/issues/6585

Hope there is some good way to migrate.

enarjord commented 10 months ago

The bybit implementation of passivbot has been updated to use their API v5 via CCXT. The latest master branch works fine for me.

dasbts commented 10 months ago

I was so confused, because I had not made any changes other than maybe a git pull. Tried migrating from v1 manager config to v2 but without success as syncing worked but info showed stopped instances. Turned out to be just as easy as just pip install -r requirements.txt to update CCXT, lol.

Asked ChatGPT to make a script to automatically do this in the future, might be useful for other Linux-heads:

set -e

# Define your repository path
REPO_PATH="/home/aaa/bbb"

# Change to the repository directory
cd "$REPO_PATH"

# Perform a Git pull
git pull

# Activate your Python virtual environment if needed
# source /path/to/venv/bin/activate

# Install Python packages from requirements.txt
pip install -r requirements.txt

# Restart the systemd service
sudo systemctl restart your-service-name

Still haven't seen any new trades coming in, but I'm gonna close this for now since it says it's running again now.

dasbts commented 10 months ago

This occurred due to: 2023-10-30T23:26:52 ERROR error on minute mark float division by zero Traceback (most recent call last): File "/home/abc/Trading/passivbot/passivbot.py", line 1546, in on_minute_mark await self.cancel_and_create() File "/home/abc/Trading/passivbot/passivbot.py", line 1000, in cancel_and_create all_orders = self.calc_orders() File "/home/abc/Trading/passivbot/passivbot.py", line 662, in calc_orders calc_clock_entry_long( File "/home/abc/Trading/passivbot/njit_clock.py", line 81, in calc_clock_entry_long wallet_exposure_long = qty_to_cost(psize_long, pprice_long, inverse, c_mult) / balance ZeroDivisionError: float division by zero

dasbts commented 10 months ago

Tried assigning it a balance of $250 and over night it's the same result sadly.

2023-10-31T10:31:51 ERROR error on minute mark float division by zero Traceback (most recent call last): File "/home/abc/Trading/passivbot/passivbot.py", line 1546, in on_minute_mark await self.cancel_and_create() File "/home/abc/Trading/passivbot/passivbot.py", line 1000, in cancel_and_create all_orders = self.calc_orders() File "/home/abc/Trading/passivbot/passivbot.py", line 662, in calc_orders calc_clock_entry_long( File "/home/abc/Trading/passivbot/njit_clock.py", line 81, in calc_clock_entry_long wallet_exposure_long = qty_to_cost(psize_long, pprice_long, inverse, c_mult) / balance ZeroDivisionError: float division by zero

I can look into the code and try to fix it sometime in the upcoming days if no1 else knows what is wrong. Could eventually just be solved with a try: catch: but haven't investigated the code base yet.

A quick look in the file seem like balance is undefined/null/0, and that balance_long is not set, strange because my config does not include it at all, leading me to think it defaults to zero so it won't trade, which obviously causes problems in any calculations.

This leads me to def backtest_clock, is passivbot automatically backtesting?

dasbts commented 10 months ago

Attaching config: version: 2

defaults: config: "latest.json" api_keys: /home/samd/Trading/passivbot/api-keys.json assigned_balance: 250 market_type: "futures" leverage: 7 long_mode: "n" short_mode: "m"

long_exposure: 0.99

instances:

dasbts commented 10 months ago

After a quick check of the code base, it leads me back to: def calc_orders(self): balance = self.position["wallet_balance"]

Meaning it likely fails in "async def cancel_and_create(self)".

The account has two active orders since the time it crashed. SOLUSDT 0/0.1 filled at price 26.606 and ADAUSDT 0/19 filled at order price 0.2478. No TP/SL set in the app. Tried both cancelling these and adding a try: ... except: all_orders = [] in cancel_and_create but same result, so this has to do with positions most likely. Strange because first off it is trying to get positions where there are none.

I know in CCXT I get positions with value zero even if there is nothing in it, so ByBit seem to return more data than we expect, and likely since passivbot works with multi exchanges, this maybe haven't popped up before. So obviously then self.position["wallet_balance"]

Very strange, because there is balance in this wallet, about $250. I suspect /passivbot/exchanges/bybit.py "async def fetch_position(self)" is the issue.

dasbts commented 10 months ago

Row 173, is this return not supposed to be indented once more? @enarjord https://github.com/enarjord/passivbot/blob/master/exchanges/bybit.py

EDIT: Nvm, seem to just be duplicated code.