-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
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-sdkfromgit+https://github.com/elliottech/lighter-python.git@main - Python Version: (Please specify)
- OS: Linux
Steps to Reproduce
- Create a
SignerClientinstance - Call
sign_create_order()withmarket_index=2048 - Parse the returned
tx_info_jsonand check theMarketIndexfield
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: 0Expected 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
MarketIndexis always set to 0, which may refer to an invalid or default market. - Workaround: None available. Modifying the
MarketIndexin 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_indexvalue 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
MarketIndexvalue.
Possible Root Causes
- The
sign_create_order()method may be using an internalmarket_idattribute from theSignerClientinstance instead of themarket_indexparameter. - The
market_indexparameter may not be properly passed to the internal signing logic. - There may be a default value of
0being used whenmarket_indexis not recognized.
Suggested Fix
- Review the
sign_create_order()implementation to ensure themarket_indexparameter is correctly used. - If
SignerClientmaintains an internalmarket_idstate, ensure it's updated or that the parameter takes precedence. - Add validation to ensure
market_indexis 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
Labels
No labels