1

I am using ccxt library to work with exchange. Struggling with making market order on Bybit. How it can be fixed? The error i've got is TypeError: Exchange.request() takes from 1 to 3 positional arguments but 5 were given

 bybit_spot = ccxt.bybit({
        "apiKey": config.bybit_API_KEY,
        "secret": config.bybit_SECRET_KEY,
        "options": {'defaultType': 'spot' }})
    bybit_spot.private_post_spot_v1_order("GMTUSDT", "buy", "market", amount)

2 Answers2

1

Where are you getting private_post_spot_v1_order method from? It doesn't seem to be a ccxt method as far as I can see. The correct method for place an order is createOrder as defined in the manual.

Here is a working example with binance but it should be the same for bybit:

import ccxt
exchange = ccxt.binance({
    'apiKey': '...',
    'secret': '...',
})

exchange.createOrder('BTC/USDT', 'market', 'sell', 0.1)

Let me know if it doesn't work and I will open an account with bybit to test it there.

Alex B
  • 1,092
  • 1
  • 14
  • 39
0

Hope this could help:

import ccxt from 'ccxt';

const bybit = new ccxt.bybit();

bybit.apiKey = 'YOUR_API_KEY';
bybit.secret = 'YOUR_SECRET';

const symbol = 'BTC/USDT';
const amount = 1;
const side = 'sell';

(async function () {
    try {
        const order = await bybit.createOrder(symbol, 'market', side, amount);
        console.log(order);

        const orderDetails = await bybit.fetchOrder(order.id, symbol);
        console.log(orderDetails);
    } catch (e) {
        console.error(e);
    }
})();
Ayoung
  • 23
  • 4
  • Users find it difficult to understand code only answers with no explanation. Please add some description explaining what is does and how it solves the problem or add comments in the source code at appropriate places. – Azhar Khan Feb 11 '23 at 09:32