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

ByBit USDT perpetual not working #420

Closed
dasbts opened this issue Oct 30, 2023 · 7 comments
Closed

ByBit USDT perpetual not working #420

dasbts opened this issue Oct 30, 2023 · 7 comments

Comments

@dasbts
Copy link

dasbts commented Oct 30, 2023

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:
hummingbot/hummingbot#6585

Hope there is some good way to migrate.

@enarjord
Copy link
Owner

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

@dasbts
Copy link
Author

dasbts commented Oct 30, 2023

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 dasbts closed this as completed Oct 30, 2023
@dasbts
Copy link
Author

dasbts commented Oct 30, 2023

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 dasbts reopened this Oct 30, 2023
@dasbts
Copy link
Author

dasbts commented Oct 31, 2023

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
Copy link
Author

dasbts commented Oct 31, 2023

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:

  • user: "bybit_01"
    symbols:

    • "DOGEUSDT"
      live_config_name: "DOGE_clock.json"
      live_config_path: "DOGE_clock.json"
  • user: "bybit_01"
    symbols:

    • "MATICUSDT"
      live_config_name: "MATIC_clock.json"
      live_config_path: "MATIC_clock.json"

@dasbts
Copy link
Author

dasbts commented Oct 31, 2023

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
Copy link
Author

dasbts commented Oct 31, 2023

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.

@dasbts dasbts closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants