Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close method in futures dual postion mode #16

Open
peacmake opened this issue Dec 1, 2023 · 2 comments
Open

Close method in futures dual postion mode #16

peacmake opened this issue Dec 1, 2023 · 2 comments

Comments

@peacmake
Copy link

peacmake commented Dec 1, 2023

I would like to place an order to close a long position in futures dual position mode.
The API manual says "In dual position mode, to close one side position, you need to set auto_size side, reduce_only to true and size to 0",
so I coded and ran it as follows.

const params = { contract: symbol, size: 0, price: 0, auto_size:"close_long", reduce_only: true, tif: "ioc" };
createFuturesOrder("usdt", params);

If I run it, I see an 'invalid size with close-order' error message.

If I change that code to size: 1 and run it, a long position is created,
If I change size: -1, a short position is created.

How can I close my positions?

@zhouguanglong1
Copy link

maybe you can try by this way

const params = { contract: symbol, size: 0, price: 0, autoSize:"close_long", reduceOnly: true, tif: "ioc" };

@peacmake
Copy link
Author

peacmake commented Dec 2, 2023

I solved it by changing line 868 of the node_modules/gate-api/dist/api/futuresApi.js source code as follows.

         // const config = {
         // method: 'POST',
         // params: localVarQueryParameters,
         // headers: localVarHeaderParams,
         // url: localVarPath,
         // data: models_1.ObjectSerializer.serialize(futuresOrder, 'FuturesOrder'),
         // };
         const config = {
             method: 'POST',
             params: localVarQueryParameters,
             headers: localVarHeaderParams,
             url: localVarPath,
             data: futuresOrder,
         };

models_1.ObjectSerializer.serialize(futuresOrder, 'FuturesOrder') is supposed to check the values of the input params and convert case to lowercase letters, etc., but there was a problem with the conversion of the auto_size part. But, I solved it by just changing that part of futuresApi.js without touching the model object code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants