0

I found an old thread ( how can I close position on OKX V5 based on CCXT Python? ) but is not working. I'm having problem in closing my current margin-spot position. Here's my code:

params = {'tdMode': 'cross', 'ccy': 'USDT'}
order = await self.okx.create_order(
    symbol='XRP/USDT', type='market', side='sell',
    amount=99.43, price=0.39024, params=params
)

Result:

{'amount': 99.431119,
 'average': 0.39005,
 'clientOrderId': 'e847386590ce4dBCce71dedc37e12254',
 'cost': 38.78310796595,
 'datetime': '2022-12-02T17:29:58.048Z',
 'fee': {'cost': 0.03878310796595, 'currency': 'USDT'},
 'fees': [{'cost': 0.03878310796595, 'currency': 'USDT'}],
 'filled': 99.431119,
 'id': '518962064594153472',

Places the first order correctly. Now to close this order I use barrely the same code, changing sides:

params = {'tdMode': 'cross', 'ccy': 'USDT'}
order = await self.okx.create_order(
    symbol='XRP/USDT', type='market', side='buy',
    amount=99.43, price=0.39017, params=params
)

Problem is that the amount in the second order seeems to be 'contracts'/'price' instead:

result:

{'amount': 99.43111,
 'average': 0.39015,
 'clientOrderId': 'e847386590ce4dBC328bc6dfc937795f',
 'cost': 99.43110980145,
 'datetime': '2022-12-02T17:36:47.913Z',
 'fee': {'cost': 0.254853543, 'currency': 'XRP'},
 'fees': [{'cost': 0.254853543, 'currency': 'XRP'}],
 'filled': 254.853543,
 'id': '518963783692562432',

What am I doing wrong ?

Piero Costa
  • 180
  • 11

1 Answers1

0

Are you changing the default tgtCcy value?

Can you try to place the market order without the price (market orders execute at the market price so you don't need to specify it)?

  • tgtCcy does not work, only for SPOT markets. I'll use the standard lib for closing all orders with market orders. Thank you Carlos! – Piero Costa Dec 14 '22 at 15:24
  • 1
    @PieroCosta, if you can make it using the standard lib you can definitely do it using ccxt, you just need to realize the difference between the std lib and ccxt request :) – Carlos Gonçalves Dec 15 '22 at 17:56