TheFourGreatErrors / alpha-rptr

A trading bot for automated algorithmic trading on Binance Futures, Bybit, BitMEX and FTX written in python.
MIT License
441 stars 67 forks source link

Api error code -4164 #77

Open brtechcrypto opened 1 month ago

brtechcrypto commented 1 month ago

I am running the bot for futures in binance and after some time I get the next error:

python3.9 main.py --account binanceaccount1 --exchange binance --pair BTCUSDT --strategy Rci
2024-07-30 21:03:50,238 - INFO - Bot Mode : Trade
2024-07-30 21:03:50,238 - INFO - pair: BTCUSDT
2024-07-30 21:03:50,238 - INFO - timeframes: ['5m']
2024-07-30 21:03:51,393 - INFO - Starting Bot
2024-07-30 21:03:51,394 - INFO - Strategy : Rci
2024-07-30 21:03:52,523 - INFO - Websocket connected
2024-07-30 21:03:52,833 - INFO - Pair Launched: 2019-09-25T08:00:00+00:00
2024-07-30 21:03:53,127 - INFO - Current Leverage: 7.0
2024-07-30 21:03:53,179 - INFO - fetching OHLCV data - 2024-07-30 16:43:53.176590+00:00
2024-07-30 21:03:54,522 - INFO - Initial Buffer Fill - Last Candle: 2024-07-31 01:03:53+00:00
2024-07-30 21:03:54,565 - INFO - Asset: BTC Rounding: 3 - Quote: USDT Rounding: 2
2024-07-30 21:03:54,565 - INFO - Position Size: 0.000 Entry Price: 0.00
2024-07-30 21:03:54,565 - INFO - Balance : 65.3243244
2024-07-30 21:40:00,612 - INFO - pos_size: 0.0
2024-07-30 21:40:02,034 - INFO - APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).
2024-07-30 21:40:02,035 - ERROR - Fatal error. APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).
2024-07-30 21:40:02,041 - ERROR - Traceback (most recent call last):
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/__init__.py", line 448, in retry_binance_futures
    ret, res = func()
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures.py", line 638, in <lambda>
    retry(lambda: self.client.futures_create_order(symbol=self.pair, type=ord_type, newClientOrderId=ord_id,
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures_api.py", line 444, in futures_create_order
    return self._request_futures_api('post', 'order', True, data=params)
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures_api.py", line 259, in _request_futures_api
    return self._request(method, uri, signed, True, **kwargs)
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures_api.py", line 234, in _request
    return self._handle_response()
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures_api.py", line 268, in _handle_response
    raise BinanceAPIException(self.response)
src.exchange.binance_futures.exceptions.BinanceAPIException: APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures.py", line 1760, in __update_ohlcv
    self.strategy(t, open, close, high, low, volume)
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/strategies/Rci.py", line 58, in strategy
    self.exchange.entry("Short", False, lot)
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures.py", line 743, in entry
    self.order(id, long, ord_qty, limit=limit, stop=stop, post_only=post_only, reduce_only=reduce_only,
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures.py", line 1216, in order
    self.__new_order(ord_id, side, ord_qty, limit, stop, post_only, reduce_only,
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/exchange/binance_futures/binance_futures.py", line 638, in __new_order
    retry(lambda: self.client.futures_create_order(symbol=self.pair, type=ord_type, newClientOrderId=ord_id,
  File "/Users/billy/trading/repos/alpharptr/alpha-rptr/src/__init__.py", line 475, in retry_binance_futures
    raise FatalError(error)
src.FatalError: APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

what can it be wrong? I am testing in this moment.

Thanks in advance for any explanation and help.

praveenbm5 commented 1 month ago

You seem to be placing an order with notional value less than 100 USDT.

APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

Please check the size and value in USDT of the order you are sending.

brtechcrypto commented 1 month ago

You seem to be placing an order with notional value less than 100 USDT.

APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

Please check the size and value in USDT of the order you are sending.

Hi @praveenbm5 thanks for your answer, where exactly should change the size and value in USDT?

praveenbm5 commented 1 month ago

look into Rci->strategy function

self.exchange.entry("Long", True, lot)

this call places an order for maximum quantity allowed at the set leverage for your account on exchange for the balance in your account.

Ex. if the leverage is set to 20 (default on Binance Futures) and you have 50 USDT balance on your futures account, then this call will place an order for 20*50 = 1000 USDT worth of BTC.

brtechcrypto commented 1 month ago

Okay, so, this error: APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

was telling me that my balance which was 65 USDT and the leverage (I assume this was 1x because I didn't specify it) was less than 100 USDT, right?

Now I could find the leverage is an option that can be provided to the main.py script but I don't see where I can limit the amount of invest. For just an example, of my 65 USDT I would like to invest only 40 USDT with a leverage of 20x. How can I do it?

really appreciated your help :)

praveenbm5 commented 1 month ago

Leverage is an account wide setting which can be set using command line arguments.

Whereas order size is set on a per order basis.

You can specify order size when posting order related calls like entry, order, etc. In your strategy.

Natively most exchanges support order sizes specified in asset quatity ex. 0.1 (btc) but we also support setting order size in USDT which will be internally converted to assert quantity.

Better to go with quantity in asset units.

Please read the source code for granular details.. it's simple and self explanatory.

On Thu, 1 Aug, 2024, 03:10 brtechcrypto, @.***> wrote:

Okay, so, this error: APIError(code=-4164): Order's notional must be no smaller than 100 (unless you choose reduce only).

was telling me that my balance which was 65 USDT and the leverage (I assume this was 1x because I didn't specify it) was less than 100 USDT, right?

Now I could find the leverage is an option that can be provided to the main.py script but I don't see where I can limit the amount of invest. For just an example, of my 65 USDT I would like to invest only 40 USDT with a leverage of 20x. How can I do it?

really appreciated your help :)

— Reply to this email directly, view it on GitHub https://github.com/TheFourGreatErrors/alpha-rptr/issues/77#issuecomment-2261508072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD32QYNPRGNWCODDYJKH7DZPFKUZAVCNFSM6AAAAABLXPVOZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRRGUYDQMBXGI . You are receiving this because you were mentioned.Message ID: @.***>