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.44k stars 7.46k forks source link

Can you provide an example of OKX future buy order? #14017

Open KindSpidey opened 2 years ago

KindSpidey commented 2 years ago

I've already asked for this in the issue #13789 , but havent received the answer. We found some errors, but havent figured out how to solve them. So how to make an order on OKX futures and place market order to buy GMT with 10x leverage isolated?

ShieldTrade commented 2 years ago

CCXT Pro Version 1.1.33

I am also having problem sending a limit order with 5X leverage cross for symbol LTC/USDT.

leverage = await okx.setLeverage(5, 'LTC/USDT', {'mgnMode': 'cross'})
print(leverage)

gives me {'code': '0', 'data': [{'instId': 'LTC-USDT', 'lever': '5', 'mgnMode': 'cross', 'posSide': ''}], 'msg': ''}. So I guess the leverage is correctly set. but I could not send the limit order using it.

await okx.create_order('LTC/USDT', 'limit', 'buy', 0.5, 50) 
await okx.create_order('LTC/USDT', 'limit', 'buy', 0.5, 50,  {'tdMode': 'cash'})
await okx.create_order('LTC/USDT' 'limit', 'buy', 0.5, 50, {'mgnMode': 'cross'})
await okx.create_order('LTC/USDT' 'limit', 'buy', 0.5, 50, {'mgnMode': 'cross', 'ccy': 'USDT'})

they all let me send the order with no leverage

await okx.create_order('LTC/USDT', 'limit', 'buy', 0.5, 50, {'tdMode': 'cross'}) # this should be the right one according to okx documents... well.. they are not very clear..

raises the follow name 'symbol' is not defined

can you please help?

tx

KindSpidey commented 2 years ago

Fixed it. You needed to add 2 things: ":USDT" to symbol and parametr "posSide" Now try this okx.setLeverage(5, 'LTC/USDT:USDT', {'mgnMode': 'isolated', "posSide":"long"})

KindSpidey commented 2 years ago

Second help. I used this for market order: exchange.create_market_buy_order(coin + self.usdt + ':USDT', amount, {'mgnMode': 'cross', "posSide": "long"}) So in your case i guess it will be something like: await okx.create_order('LTC/USDT:USDT', 'limit', 'buy', 0.5, 50, {'mgnMode': 'cross', "posSide": "long"}) Write me back in any case, work it or not

ShieldTrade commented 2 years ago

@KindSpidey , Thank you for your help butLTC/USDT:USDT is the perpetual future. I want to trade LTC/USDT spot using 'mgnMode': 'cross' as I do from web.

KindSpidey commented 2 years ago

@ShieldTrade well. are you sure spot allows to buy in cross mode? Cross/isolation is only for futures, because futures allow you to trade using leverages, while spot is only for using your money. You can't trade isolated or crossed on Spot

ShieldTrade commented 2 years ago

image

As you can see from this screen shot I can buy 17.31 contracts at the price of 50 USDT having only 86.59 USDT on my account using leverage 10.

ShieldTrade commented 2 years ago

@KindSpidey I was thinking margin trading for spot could not be allowed in all countries. Can you trade LTC/USDT with margin on OKX?