Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.
This repository was archived by the owner on Jul 16, 2026. It is now read-only.

Close method in futures dual postion mode #16

Open

Description

@peacmake

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?

Activity

  1. zhouguanglong1 commented on Dec 2, 2023

    @zhouguanglong1

    maybe you can try by this way

    const params = { contract: symbol, size: 0, price: 0, autoSize:"close_long", reduceOnly: true, tif: "ioc" };
    
  2. peacmake commented on Dec 2, 2023

    @peacmake
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions