from pylighter.client import Lighter
lighter = Lighter(key="your_wallet_address", secret="your_private_key")
await lighter.init_client()下限价单
参数:
ticker(str): 交易对符号,如 "TON", "XRP"amount(float): 交易数量,正数=买入/做多,负数=卖出/做空price(float): 限价价格tif(str): 订单有效期,默认 'GTC' (Good Till Cancelled)
返回:
tuple: (tx_info, tx_hash, error)
示例:
# 做多 3.2 TON,价格 3.15
tx_info, tx_hash, error = await lighter.limit_order("TON", 3.2, 3.15)
# 做空 3.2 TON,价格 3.20
tx_info, tx_hash, error = await lighter.limit_order("TON", -3.2, 3.20)下市价单
取消指定币种的所有订单
获取订单簿数据
返回:
{
'bids': [{'price': '3.141980', 'remaining_base_amount': '1234'}, ...],
'asks': [{'price': '3.144500', 'remaining_base_amount': '567'}, ...]
}获取交易对基本信息
获取交易对详细信息,包含最小交易量等约束
ticker_to_idx: 交易对名称到市场ID的映射ticker_min_base: 最小基础货币数量ticker_min_quote: 最小报价货币数量($10)ticker_to_price_precision: 价格精度ticker_to_lot_precision: 数量精度
所有交易方法都返回 (tx_info, tx_hash, error) 元组:
tx_info, tx_hash, error = await lighter.limit_order("TON", 3.2, 3.15)
if error is not None:
print(f"交易失败: {error}")
else:
print(f"交易成功: {tx_hash}")21120: 无效签名 - 检查私钥和API Key Index400: 参数错误 - 检查交易数量和价格是否符合最小值要求网络错误: 检查网络连接
- 错误处理: 始终检查返回的 error 参数
- 数量验证: 确保交易数量满足最小值要求
- 价格精度: 使用正确的价格精度
- 资源清理: 使用完毕后调用
await lighter.cleanup()
try:
lighter = Lighter(key=api_key, secret=api_secret)
await lighter.init_client()
# 执行交易
tx_info, tx_hash, error = await lighter.limit_order("TON", 3.2, 3.15)
if error is not None:
print(f"交易失败: {error}")
else:
print(f"交易成功: {tx_hash}")
finally:
await lighter.cleanup()