Skip to content

SDK v7.2.8 is injecting unsupported fields into the put object for /spot/price_orders #184

@sambaTux

Description

@sambaTux

Hi everyone,

I have this issue with the official Gate.io python SDK:

Environment:

  • Python: 3.x (Linux/Windows)

  • gate-api: 7.2.8

  • Endpoint: SpotApi.create_spot_price_triggered_order

from gate_api import Configuration, ApiClient, SpotApi, SpotPricePutOrder, SpotPriceTrigger, SpotPriceTriggeredOrder

configuration = Configuration(
    host="https://api.gateio.ws/api/v4",
    key=api_key,
    secret=api_secret,
)
api_client = ApiClient(configuration)
spot_api   = SpotApi(api_client)



def place_stop_loss(symbol, base_amount, entry_price, side, sl_pct):
    if side.lower() == "buy":
        trigger_price = round(entry_price * (1 - sl_pct), 6)
        order_side    = "sell"
        trigger_rule  = "<="
    elif side.lower() == "sell":
        trigger_price = round(entry_price * (1 + sl_pct), 6)
        order_side    = "buy"
        trigger_rule  = ">="
    else:
        return None

    put_order = SpotPricePutOrder(
        type="market",
        side=order_side,
        price="",
        amount=str(base_amount),
    )

    trigger = SpotPriceTrigger(
        price=str(trigger_price),
        rule=trigger_rule,
        expiration=7 * 24 * 60 * 60,
    )

    price_triggered_order = SpotPriceTriggeredOrder(
        market=symbol,
        trigger=trigger,
        put=put_order,
    )

    print("SpotPricePutOrder payload:", put_order.to_dict())
    print("SpotPriceTriggeredOrder payload:", price_triggered_order.to_dict())

    created = spot_api.create_spot_price_triggered_order(price_triggered_order)
    print("Created stop-loss:", created)
    return created.id

Example call:

place_stop_loss(
    symbol="DOGE3L_USDT",
    base_amount=10530.93,
    entry_price=0.002279,
    side="Buy",
    sl_pct=0.10,
)

Log output

SpotPricePutOrder payload: {'type': 'market', 'side': 'sell', 'price': '', 'amount': '10530.93', 'account': 'normal', 'time_in_force': 'gtc', 'auto_borrow': False, 'auto_repay': False, 'text': None}
SpotPriceTriggeredOrder payload: {'trigger': {'price': '0.002051', 'rule': '<=', 'expiration': 604800}, 'put': {'type': 'market', 'side': 'sell', 'price': '', 'amount': '10530.93', 'account': 'normal', 'time_in_force': 'gtc', 'auto_borrow': False, 'auto_repay': False, 'text': None}, 'id': None, 'user': None, 'market': 'DOGE3L_USDT', 'ctime': None, 'ftime': None, 'fired_order_id': None, 'status': None, 'reason': None}

HTTP 400 response:
{"label":"INVALID_PARAM_VALUE","message":"invalid argument: put.time_in_force"}

Conclusion
So it looks like gate-api 7.2.8 (had the same issue with v.7.1.8) is serializing extra fields (time_in_force, account, etc.) into put for SpotPriceTriggeredOrder, but /spot/price_orders rejects put.time_in_force with INVALID_PARAM_VALUE

Thank you very much for your help.

Regards,

Bob

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