Skip to content

Commit 9aa25cd

Browse files
committed
Add twap order
1 parent f503f83 commit 9aa25cd

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

examples/create_twap_order.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import asyncio
2+
import logging
3+
import lighter
4+
5+
logging.basicConfig(level=logging.DEBUG)
6+
7+
# The API_KEY_PRIVATE_KEY provided belongs to a dummy account registered on Testnet.
8+
# It was generated using the setup_system.py script, and servers as an example.
9+
BASE_URL = "https://testnet.zklighter.elliot.ai"
10+
API_KEY_PRIVATE_KEY = "0xc0a06468a5bbc9a7b785065a8b227a37fdfa18e2b81d51b018cb03ddd99bfbef4b7551f0f0765639"
11+
ACCOUNT_INDEX = 595
12+
API_KEY_INDEX = 1
13+
14+
async def main():
15+
client = lighter.SignerClient(
16+
url=BASE_URL,
17+
private_key=API_KEY_PRIVATE_KEY,
18+
account_index=ACCOUNT_INDEX,
19+
api_key_index=API_KEY_INDEX,
20+
)
21+
22+
tx = await client.create_twap_order(
23+
market_index=0,
24+
client_order_index=0,
25+
base_amount=1000, # 0.1 ETH
26+
is_ask=True,
27+
)
28+
print("Create TWAP Order Tx:", tx)
29+
await client.close()
30+
31+
32+
if __name__ == "__main__":
33+
asyncio.run(main())

lighter/signer_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,20 @@ async def create_market_order(
469469
reduce_only=reduce_only,
470470
)
471471

472+
async def create_twap_order(self, market_index, client_order_index, base_amount, is_ask, reduce_only: bool = False):
473+
return await self.create_order(
474+
market_index,
475+
client_order_index,
476+
base_amount,
477+
is_ask = is_ask,
478+
reduce_only=reduce_only,
479+
price = 1,
480+
order_type=self.ORDER_TYPE_TWAP,
481+
time_in_force=self.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
482+
trigger_price=0,
483+
order_expiry=self.DEFAULT_28_DAY_ORDER_EXPIRY,
484+
)
485+
472486
async def cancel_order(self, market_index, order_index, nonce=-1) -> (CancelOrder, TxHash, str):
473487
tx_info, error = self.sign_cancel_order(market_index, order_index, nonce)
474488
if error is not None:

0 commit comments

Comments
 (0)