docs: 更新 lighter-python-main 文档,添加示例代码和 API 说明,重构部分内容以提高可读性

This commit is contained in:
discountry
2025-09-30 18:35:14 +08:00
parent d6533733c9
commit e83bdfccf9
337 changed files with 50410 additions and 0 deletions
@@ -0,0 +1,70 @@
import asyncio
import logging
import lighter
logging.basicConfig(level=logging.DEBUG)
# The API_KEY_PRIVATE_KEY provided belongs to a dummy account registered on Testnet.
# It was generated using the setup_system.py script, and servers as an example.
BASE_URL = "https://testnet.zklighter.elliot.ai"
API_KEY_PRIVATE_KEY = "0xe0fa55e11d6b5575d54c0500bd2f3b240221ae90241e3b573f2307e27de20c04ea628de3f1936e56"
ACCOUNT_INDEX = 22
API_KEY_INDEX = 3
def trim_exception(e: Exception) -> str:
return str(e).strip().split("\n")[-1]
async def main():
client = lighter.SignerClient(
url=BASE_URL,
private_key=API_KEY_PRIVATE_KEY,
account_index=ACCOUNT_INDEX,
api_key_index=API_KEY_INDEX,
)
tx = await client.create_tp_order(
market_index=0,
client_order_index=0,
base_amount=1000, # 0.1 ETH
trigger_price=500000,
price=500000,
is_ask=False
)
print("Create Order Tx:", tx)
tx = await client.create_sl_order(
market_index=0,
client_order_index=0,
base_amount=1000, # 0.1 ETH
trigger_price=500000,
price=500000,
is_ask=False
)
print("Create Order Tx:", tx)
tx = await client.create_tp_limit_order(
market_index=0,
client_order_index=0,
base_amount=1000, # 0.1 ETH
trigger_price=500000,
price=500000,
is_ask=False
)
tx = await client.create_sl_limit_order(
market_index=0,
client_order_index=0,
base_amount=1000, # 0.1 ETH
trigger_price=500000,
price=500000,
is_ask=False
)
print("Create Order Tx:", tx)
await client.close()
if __name__ == "__main__":
asyncio.run(main())