gateio / gateapi-python

247 stars 92 forks source link

How to partially close a futures position #95

Closed tensorboy closed 2 years ago

tensorboy commented 2 years ago

Hi,

How can I partially close an order/position with the Futures API? (I mean like if I click on "Limit Close" on the API, see below):

Screen Shot 2022-01-06 at 12 23 50 PM

I know how to close all my position with 'auto size':

close_short_order = FuturesOrder(contract=contract, size=0, price="0", tif='ioc', reduce_only=True, close=False,
                   is_close=True, auto_size="close_short")
close_short_order_response = futures_api.create_futures_order(settle, close_short_order)

however, if I only consider close part of my positions, how I can do it?

Revlvant issues: https://github.com/gateio/gateapi-python/issues/85#issue-1077783414

tensorboy commented 2 years ago

I know how to do it now...

revilwang commented 2 years ago

One thing to mention, you should set close to True instead of is_close to True when closing a position. You can read from the model doc. is_close is a read only field set from the server side.

To partially close, set size to the opposite direction with how much you want to close

tensorboy commented 2 years ago

Thanks for the help!!! Really appreciated!