Skip to content

sign_create_order ignores market_index` parameter #98

@cherideal

Description

@cherideal

Issue: sign_create_order ignores market_index parameter

Summary

The signer_client.sign_create_order() method does not correctly use the market_index parameter. When calling with market_index=2048, the generated tx_info_json contains MarketIndex: 0 instead of the expected value.

Environment

  • SDK Version: lighter-sdk from git+https://github.com/elliottech/lighter-python.git@main
  • Python Version: (Please specify)
  • OS: Linux

Steps to Reproduce

  1. Create a SignerClient instance
  2. Call sign_create_order() with market_index=2048
  3. Parse the returned tx_info_json and check the MarketIndex field

Code Example

from lighter import SignerClient

# Initialize signer_client
signer_client = SignerClient(
    url=base_url,
    private_key=private_key,
    account_index=account_index,
    api_key_index=api_key_index
)

# Call sign_create_order with market_index=2048
tx_info_json, err = signer_client.sign_create_order(
    market_index=2048,  # Expected: MarketIndex should be 2048
    client_order_index=1765124480740,
    base_amount=100,
    price=298865,
    is_ask=False,
    order_type=signer_client.ORDER_TYPE_LIMIT,
    time_in_force=signer_client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
    reduce_only=False,
    trigger_price=0,
    order_expiry=1767543681675,
    nonce=37120
)

# Parse and check MarketIndex
import json
tx_info_dict = json.loads(tx_info_json)
market_index_in_tx = tx_info_dict.get('MarketIndex')
print(f"Expected: 2048, Actual: {market_index_in_tx}")
# Output: Expected: 2048, Actual: 0

Expected Behavior

The tx_info_json should contain "MarketIndex": 2048 matching the market_index parameter passed to sign_create_order().

Actual Behavior

The tx_info_json contains "MarketIndex": 0 regardless of the market_index parameter value.

Log Output

DEBUG:src.spot.lighter_spot_ws:📋 Creating order parameters: market_index=2048, client_order_index=1765124480740, base_amount=100, price=298865, is_sell=False, nonce=37120
WARNING:src.spot.lighter_spot_ws:⚠️ MarketIndex mismatch: expected 2048, actual 0
DEBUG:src.spot.lighter_spot_ws:📋 Sending WebSocket transaction message: tx_info_json={"AccountIndex":281474976649271,"ApiKeyIndex":2,"MarketIndex":0,"ClientOrderIndex":1765124480740,"BaseAmount":100,"Price":298865,"IsAsk":0,"Type":0,"TimeInForce":1,"ReduceOnly":0,"TriggerPrice":0,"OrderExpiry":1767543681675,"ExpiredAt":1765125080675,"Nonce":37120,"Sig":"xxV+DTw1YiSvmEc0apmXpYcaR79U8tg/CcvkL8TSUoYd95IsVWvAXHaybewyj+hddtxYTrKscj6tjaFXty0Wyjve8VCiYjB8RMk1Db4GP3I="}

Generated tx_info_json

{
  "AccountIndex": 281474976649271,
  "ApiKeyIndex": 2,
  "MarketIndex": 0,  // ❌ Should be 2048
  "ClientOrderIndex": 1765124480740,
  "BaseAmount": 100,
  "Price": 298865,
  "IsAsk": 0,
  "Type": 0,
  "TimeInForce": 1,
  "ReduceOnly": 0,
  "TriggerPrice": 0,
  "OrderExpiry": 1767543681675,
  "ExpiredAt": 1765125080675,
  "Nonce": 37120,
  "Sig": "xxV+DTw1YiSvmEc0apmXpYcaR79U8tg/CcvkL8TSUoYd95IsVWvAXHaybewyj+hddtxYTrKscj6tjaFXty0Wyjve8VCiYjB8RMk1Db4GP3I="
}

Impact

  • Severity: High
  • Impact: Orders cannot be created for the intended market because the MarketIndex is always set to 0, which may refer to an invalid or default market.
  • Workaround: None available. Modifying the MarketIndex in the JSON after signing would invalidate the signature, causing the order to be rejected by the server.

Additional Information

  • The issue occurs consistently regardless of the market_index value passed.
  • Other parameters (e.g., ClientOrderIndex, BaseAmount, Price, Nonce) are correctly included in the generated JSON.
  • The signature is generated correctly, but it's based on the wrong MarketIndex value.

Possible Root Causes

  1. The sign_create_order() method may be using an internal market_id attribute from the SignerClient instance instead of the market_index parameter.
  2. The market_index parameter may not be properly passed to the internal signing logic.
  3. There may be a default value of 0 being used when market_index is not recognized.

Suggested Fix

  1. Review the sign_create_order() implementation to ensure the market_index parameter is correctly used.
  2. If SignerClient maintains an internal market_id state, ensure it's updated or that the parameter takes precedence.
  3. Add validation to ensure market_index is not 0 (or handle 0 as a special case if it's intentionally valid).

Related Code

  • File: src/spot/lighter_spot_ws.py
  • Method: create_spot_order() (lines ~806-850)
  • SDK Method: signer_client.sign_create_order()

Test Case

def test_sign_create_order_market_index():
    """Test that sign_create_order correctly uses market_index parameter"""
    signer_client = create_signer_client(...)
    
    # Test with market_index=2048
    tx_info_json, err = signer_client.sign_create_order(
        market_index=2048,
        client_order_index=1,
        base_amount=100,
        price=100000,
        is_ask=False,
        order_type=signer_client.ORDER_TYPE_LIMIT,
        time_in_force=signer_client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
        reduce_only=False,
        trigger_price=0,
        order_expiry=1767543681675,
        nonce=1
    )
    
    assert err is None, f"sign_create_order failed: {err}"
    
    tx_info = json.loads(tx_info_json)
    assert tx_info['MarketIndex'] == 2048, \
        f"Expected MarketIndex=2048, got {tx_info['MarketIndex']}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions