Skip to content

Commit 724febf

Browse files
committed
integrator-support
1 parent b7fc10b commit 724febf

15 files changed

+452
-53
lines changed

examples/integrator_approve.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
ETH_PRIVATE_KEY = ""
6+
7+
async def main():
8+
client, api_client, _ = default_example_setup()
9+
10+
err = client.check_client()
11+
if err is not None:
12+
print(f"CheckClient error: {err}")
13+
return
14+
15+
tx_info, response, err = await client.approve_integrator(
16+
eth_private_key=ETH_PRIVATE_KEY,
17+
integrator_account_index=6,
18+
max_perps_taker_fee=1000,
19+
max_perps_maker_fee=1000,
20+
max_spot_taker_fee=1000,
21+
max_spot_maker_fee=1000,
22+
approval_expiry=1775518466000
23+
)
24+
print(tx_info, response, err)
25+
26+
await client.close()
27+
await api_client.close()
28+
29+
if __name__ == "__main__":
30+
asyncio.run(main())
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
async def main():
6+
client, api_client, _ = default_example_setup()
7+
client.check_client()
8+
9+
# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
10+
market_index = 0
11+
integrator_account_index = 6
12+
integrator_taker_fee = 1000
13+
integrator_maker_fee = 500
14+
15+
# create order
16+
api_key_index, nonce = client.nonce_manager.next_nonce()
17+
tx, tx_hash, err = await client.create_order(
18+
market_index=market_index,
19+
client_order_index=123,
20+
base_amount=1000, # 0.1 ETH
21+
price=4050_00, # $4050
22+
is_ask=True,
23+
order_type=client.ORDER_TYPE_LIMIT,
24+
time_in_force=client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
25+
reduce_only=False,
26+
trigger_price=0,
27+
integrator_account_index=integrator_account_index,
28+
integrator_taker_fee=integrator_taker_fee,
29+
integrator_maker_fee=integrator_maker_fee,
30+
nonce=nonce,
31+
api_key_index=api_key_index,
32+
)
33+
print(f"Create Order {tx=} {tx_hash=} {err=}")
34+
if err is not None:
35+
raise Exception(err)
36+
37+
## modify order
38+
# use the same API key so the TX goes after the create order TX
39+
api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index)
40+
tx, tx_hash, err = await client.modify_order(
41+
market_index=market_index,
42+
order_index=123,
43+
base_amount=1100, # 0.11 ETH
44+
price=4100_00, # $4100
45+
trigger_price=0,
46+
integrator_account_index=integrator_account_index,
47+
integrator_taker_fee=integrator_taker_fee // 2, # integrator fees can also be modified
48+
integrator_maker_fee=integrator_maker_fee // 2,
49+
nonce=nonce,
50+
api_key_index=api_key_index,
51+
)
52+
print(f"Modify Order {tx=} {tx_hash=} {err=}")
53+
if err is not None:
54+
raise Exception(err)
55+
56+
## cancel order
57+
# use the same API key so the TX goes after the modify order TX
58+
api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index)
59+
tx, tx_hash, err = await client.cancel_order(
60+
market_index=market_index,
61+
order_index=123,
62+
nonce=nonce,
63+
api_key_index=api_key_index,
64+
)
65+
print(f"Cancel Order {tx=} {tx_hash=} {err=}")
66+
if err is not None:
67+
raise Exception(err)
68+
69+
await client.close()
70+
await api_client.close()
71+
72+
73+
if __name__ == "__main__":
74+
asyncio.run(main())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
async def main():
6+
client, api_client, _ = default_example_setup()
7+
client.check_client()
8+
9+
# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
10+
market_index = 0
11+
integrator_account_index = 6
12+
integrator_taker_fee = 1000
13+
integrator_maker_fee = 500
14+
15+
tx, tx_hash, err = await client.create_market_order(
16+
market_index=market_index,
17+
client_order_index=0,
18+
base_amount=1000, # 0.1 ETH
19+
avg_execution_price=4000_00,
20+
is_ask=False,
21+
integrator_account_index=integrator_account_index,
22+
integrator_taker_fee=integrator_taker_fee,
23+
integrator_maker_fee=integrator_maker_fee,
24+
)
25+
print(f"Create Order {tx=} {tx_hash=} {err=}")
26+
if err is not None:
27+
raise Exception(err)
28+
29+
await client.close()
30+
await api_client.close()
31+
32+
33+
if __name__ == "__main__":
34+
asyncio.run(main())

examples/integrator_revoke.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
ETH_PRIVATE_KEY = ""
6+
7+
async def main():
8+
client, api_client, _ = default_example_setup()
9+
10+
err = client.check_client()
11+
if err is not None:
12+
print(f"CheckClient error: {err}")
13+
return
14+
15+
tx_info, response, err = await client.approve_integrator(
16+
eth_private_key=ETH_PRIVATE_KEY,
17+
integrator_account_index=6,
18+
max_perps_taker_fee=0,
19+
max_perps_maker_fee=0,
20+
max_spot_taker_fee=0,
21+
max_spot_maker_fee=0,
22+
approval_expiry=0
23+
)
24+
print(tx_info, response, err)
25+
26+
await client.close()
27+
await api_client.close()
28+
29+
if __name__ == "__main__":
30+
asyncio.run(main())

examples/read-only-auth/generate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ async def generate_tokens_for_account(account_info, base_url, duration_days):
2525

2626
signer_client = lighter.SignerClient(
2727
url=base_url,
28-
private_key=api_key_private_key,
28+
api_private_keys={api_key_index: api_key_private_key},
2929
account_index=account_index,
30-
api_key_index=api_key_index,
3130
)
3231

3332
current_time = int(time.time())

examples/read-only-auth/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ async def setup_account(eth_private_key, account_index, base_url, api_key_index)
2121

2222
tx_client = lighter.SignerClient(
2323
url=base_url,
24-
private_key=private_key,
24+
api_private_keys={api_key_index: private_key},
2525
account_index=account_index,
26-
api_key_index=api_key_index,
2726
)
2827

2928
response, err = await tx_client.change_api_key(

0 commit comments

Comments
 (0)