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 ?