ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.95k stars 7.52k forks source link

Bybit order error #7515

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi, I am getting this error below when I try to create an order on Bybit. I am sure the parameters should be correct. Also, I have some other private calls before that in my code which work and fetch data just fine.

print ((await Client.privatePostOrderCreate({"order_type": "Limit", "symbol": BaseInstrument, "side": "Buy", "qty": BaseQuantity, "time_in_force": "PostOnly", "price": self.BuyPostPrices.pop(self.BuyPostPrices.index(max(self.BuyPostPrices)))})))
raise ExchangeError(feedback)  # unknown message
ccxt.base.errors.ExchangeError: bybit {"ret_code":10004,"ret_msg":"error sign! origin_string[api_key=\u0026order_type=Limit\u0026price=11288.0\u0026qty=1\u0026recv_window=5000\u0026side=Buy\u0026symbol=BTCUSD\u0026time_in_force=PostOnly\u0026timestamp=1598386304084]","ext_code":"","ext_info":"","result":null,"time_now":"1598386304.170475"}
CryptoGnome commented 4 years ago

getting a similar error in previously working code, did they change somthing?

ghost commented 4 years ago

Just tested non-async version and seems to be working.

kroitor commented 4 years ago

@CryptoGnome in short, yes: https://github.com/ccxt/ccxt/issues/7454

CryptoGnome commented 4 years ago

This is the clip I was using FYI - Thanks for the amazing support @kroitor

exchange.create_limit_sell_order(self.pair, abs(self.size), int(self.takeprofit), {'reduce_only': True})
ghost commented 4 years ago

Well, just tried the code transformed from async and it still keeps throwing the same so I don't know.

ghost commented 4 years ago

Totally weird, int(...code to get the price from a list...) works. I guess the problem could be it doesn't accept like 11550.0, only 11550?

Basically what's in @CryptoGnome's code.

kroitor commented 4 years ago

@ZB83486 is your version of CCXT up to date?

import ccxt
print(ccxt.__version__)  # what does it say?
ghost commented 4 years ago

pip3 show ccxt Name: ccxt Version: 1.33.53

ghost commented 4 years ago

int(price) seems to be working though I am not sure why that is or how that can be, I guess it's not even really a problem of CCXT in this case.

kroitor commented 4 years ago

@ZB83486 nope, i mean the actual runtime version (not a pip3 output), please run your python3 interpreter and type:

# in python
import ccxt
print(ccxt.__version__)

Just asking, since this version has been addressed before and we have to isolate it if it's still there.

ghost commented 4 years ago
import ccxt
print(ccxt.__version__)
1.33.53
CryptoGnome commented 4 years ago

I am on


1.33.27

Guess i should update
ghost commented 4 years ago

Anyway, basically, I am fine with that for now because I can work with only integer number variables, and I guess it could work with half decimals too having done some tweaking (probably won't be accepting the full numbers with decimals .0 so needs rounding). I have reversed all the code back to async again and it just runs fine for the time being.

kroitor commented 4 years ago

@ZB83486 with the implicit privatePostOrderCreate you have to format the values according to the ByBit API docs. As you can see from here: https://bybit-exchange.github.io/docs/inverse/#t-placeactive Bybit requires the amount for Inverse swaps (USD contracts) to be an integer. If you use the CCXT's unified createOrder method instead of privatePostOrderCreate CCXT will resolve this for you. If you're using the implicit methods directly, then you should pre-format your values correctly.

@CryptoGnome lmk if you have the same issue with the most recent version of the lib.

CryptoGnome commented 4 years ago

@kroitor Yes same issue after update


bybit {"ret_code":10004,"ret_msg":"error sign! origin_string[api_key=keygoeshere\u0026order_type=Limit\u0026price=11372.0\u0026qty=2\u0026recv_window=5000\u0026reduce_only=true\u0026side=Buy\u0026symbol=BTCUSD\u0026time_in_force=GoodTillCancel\u0026timestamp=1598473350183]","ext_code":"","ext_info":"","result":null,"time_now":"1598473350.878895"}
kroitor commented 4 years ago

@CryptoGnome https://github.com/ccxt/ccxt/wiki/FAQ#what-is-required-to-get-help

ghost commented 4 years ago

Yeah, I haven't checked that, sorry, though it still seems a bit odd to me that this matters at all in the present day and logs itself as an auth problem(?). Never mind, thanks a lot for your time, I appreciate it knowing you must have a lot of work to do on the project. Take care.

CryptoGnome commented 4 years ago
Traceback (most recent call last):
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 258, in <module>
    bot.start_bot()
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 249, in start_bot
    bot.check_positions(pairs)
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 101, in check_positions
    bot.take_profit(self.symbol)
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 144, in take_profit
    bot.cancel_tp()
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 215, in cancel_tp
    bot.short_profit()
  File "C:/Users/oimap/Desktop/LickHunterPro2/bybitProfit.py", line 239, in short_profit
    exchange.create_limit_buy_order(self.pair, abs(self.size), int(self.takeprofit), {"reduce_only": True})
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\base\exchange.py", line 1801, in create_limit_buy_order
    return self.create_order(symbol, 'limit', 'buy', *args)
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\bybit.py", line 1248, in create_order
    response = getattr(self, method)(self.extend(request, params))
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\base\exchange.py", line 465, in inner
    return entry(_self, **inner_kwargs)
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\base\exchange.py", line 490, in request
    return self.fetch2(path, api, method, params, headers, body)
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\base\exchange.py", line 486, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\base\exchange.py", line 608, in fetch
    self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
  File "C:\Users\oimap\Desktop\LickHunterPro2\venv\lib\site-packages\ccxt\bybit.py", line 2057, in handle_errors
    raise ExchangeError(feedback)  # unknown message
ccxt.base.errors.ExchangeError: bybit {"ret_code":10004,"ret_msg":"error sign! origin_string[api_key=KEYGOESHERE\u0026order_type=Limit\u0026price=11372.0\u0026qty=2\u0026recv_window=5000\u0026reduce_only=true\u0026side=Buy\u0026symbol=BTCUSD\u0026time_in_force=GoodTillCancel\u0026timestamp=1598473514315]","ext_code":"","ext_info":"","result":null,"time_now":"1598473515.030975"}
kroitor commented 4 years ago

@ZB83486

and logs itself as an auth problem(?)

Yeah, not all exchanges are super-consistent with their error reporting. Anyways, glad you've figured it out.

@CryptoGnome can you post a snippet of code to reproduce it, including the exchange instantiation, but without your keys?

CryptoGnome commented 4 years ago

PYTHON:

self.pair = 'BTCUSD' self.size = -2 self.takeprofit = 11500.50

    def long_profit(self):
        print("Placing Long Take Profit", self.pair)
        exchange.create_limit_sell_order(self.pair, abs(self.size), int(self.takeprofit), {'reduce_only': True})

To note i am able to call positions and use market orders, only limits are failing.

kroitor commented 4 years ago

@CryptoGnome i'll check that and will get back to you asap.

CryptoGnome commented 4 years ago

Hey @kroitor, I know you are busy, wanted to check if had a chance to look at his or if there is currently a workaround, kind of surprised no one else is reporting this...

kroitor commented 4 years ago

@CryptoGnome pardon for the delay, i'll debug this on my side and will let you know shortly

kroitor commented 4 years ago

@CryptoGnome let me know if you have the same issue with version 1.33.76+, it will arrive in 15 minutes. If you still have errors, please follow the guidelines precisely and paste your entire verbose output here:

import ccxt
from pprint import pprint

print('CCXT Version:', ccxt.__version__)

exchange = ccxt.bybit({
    'enableRateLimit': True,
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET', 
})

markets = exchange.load_markets()

symbol = 'BTC/USD'
type = 'limit'
side = 'sell'
amount = 2
price = 11500
params = {
    "reduce_only": True
}

exchange.verbose = True

order = exchange.create_order(symbol, type, side, amount, price, params)

pprint(order)
CryptoGnome commented 4 years ago

Fixed! You sir a legend, thank you for resolving this!

ghost commented 4 years ago

Seems to have been fixed for me as well, thanks.

kroitor commented 4 years ago

@CryptoGnome @ZB83486 thanks for your feedback!

ghost commented 4 years ago

Sure thing, just a little update. It seems that openapiPostOrderReplace endpoint keeps throwing that error (only async tested). Could you check that?

kroitor commented 4 years ago

@ZB83486 plz run and post the output of this snippet here: https://github.com/ccxt/ccxt/issues/7515#issuecomment-683950512

ghost commented 4 years ago

I'll try to reproduce it again manually when I have time and let you know, thanks. Think it was the price adjustment (not qty) to be precise but let's see.