Skip to content

Commit 0d543ba

Browse files
authored
integrator-subaccount-support (#130)
* integrator-subaccount-support * v1.0.6
1 parent cba4d84 commit 0d543ba

14 files changed

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

examples/integrator_create_market_order.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ async def main():
77
client.check_client()
88

99
# 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
10+
market_index = 2048
11+
# integrator_account_index = 6
12+
integrator_account_index = 281474976710647
1213
integrator_taker_fee = 1000
1314
integrator_maker_fee = 500
1415

1516
tx, tx_hash, err = await client.create_market_order(
1617
market_index=market_index,
1718
client_order_index=0,
1819
base_amount=1000, # 0.1 ETH
19-
avg_execution_price=4000_00,
20-
is_ask=False,
20+
avg_execution_price=1900_00,
21+
is_ask=True,
2122
integrator_account_index=integrator_account_index,
2223
integrator_taker_fee=integrator_taker_fee,
2324
integrator_maker_fee=integrator_maker_fee,

examples/integrator_create_modify_order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ async def main():
88

99
# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
1010
market_index = 0
11-
integrator_account_index = 6
11+
# integrator_account_index = 6
12+
integrator_account_index = 281474976710647
1213
integrator_taker_fee = 1000
1314
integrator_maker_fee = 500
1415

lighter/signer_client.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __populate_shared_library_functions(signer):
117117
signer.SignChangePubKey.restype = SignedTxResponse
118118

119119
signer.SignCreateOrder.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
120-
ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
120+
ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
121121
signer.SignCreateOrder.restype = SignedTxResponse
122122

123123
signer.SignCreateGroupedOrders.argtypes = [ctypes.c_uint8, ctypes.POINTER(CreateOrderTxReq), ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
@@ -135,7 +135,7 @@ def __populate_shared_library_functions(signer):
135135
signer.SignCancelAllOrders.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
136136
signer.SignCancelAllOrders.restype = SignedTxResponse
137137

138-
signer.SignModifyOrder.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
138+
signer.SignModifyOrder.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
139139
signer.SignModifyOrder.restype = SignedTxResponse
140140

141141
signer.SignTransfer.argtypes = [ctypes.c_longlong, ctypes.c_int16, ctypes.c_int8, ctypes.c_int8, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_char_p, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
@@ -550,6 +550,30 @@ def sign_approve_integrator(
550550
)
551551
return self.__decode_and_sign_tx_info(eth_private_key, res)
552552

553+
def sign_approve_integrator_same_master_account(
554+
self,
555+
integrator_account_index: int,
556+
max_perps_taker_fee: int,
557+
max_perps_maker_fee: int,
558+
max_spot_taker_fee: int,
559+
max_spot_maker_fee: int,
560+
approval_expiry: int,
561+
nonce: int = DEFAULT_NONCE,
562+
api_key_index: int = DEFAULT_API_KEY_INDEX
563+
) -> Union[Tuple[str, str, str, None], Tuple[None, None, None, str]]:
564+
res = self.signer.SignApproveIntegrator(
565+
integrator_account_index,
566+
max_perps_taker_fee,
567+
max_perps_maker_fee,
568+
max_spot_taker_fee,
569+
max_spot_maker_fee,
570+
approval_expiry,
571+
nonce,
572+
api_key_index,
573+
self.account_index
574+
)
575+
return self.__decode_tx_info(res)
576+
553577
def sign_transfer(self, eth_private_key: str, to_account_index: int, asset_id: int, route_from: int, route_to: int, usdc_amount: int, fee: int, memo: str, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX) -> Union[Tuple[str, str, str, None], Tuple[None, None, None, str]]:
554578
return self.__decode_and_sign_tx_info(eth_private_key, self.signer.SignTransfer(to_account_index, asset_id, route_from, route_to, usdc_amount, fee, ctypes.c_char_p(memo.encode("utf-8")), nonce, api_key_index, self.account_index))
555579

@@ -1108,6 +1132,36 @@ async def approve_integrator(
11081132
logging.debug(f"Approve Integrator Send. TxResponse: {api_response}")
11091133
return tx_info, api_response, None
11101134

1135+
@process_api_key_and_nonce
1136+
async def approve_integrator_same_master_account(
1137+
self,
1138+
integrator_account_index: int,
1139+
max_perps_taker_fee: int,
1140+
max_perps_maker_fee: int,
1141+
max_spot_taker_fee: int,
1142+
max_spot_maker_fee: int,
1143+
approval_expiry: int,
1144+
nonce: int = DEFAULT_NONCE,
1145+
api_key_index: int = DEFAULT_API_KEY_INDEX
1146+
):
1147+
tx_type, tx_info, tx_hash, error = self.sign_approve_integrator_same_master_account(
1148+
integrator_account_index,
1149+
max_perps_taker_fee,
1150+
max_perps_maker_fee,
1151+
max_spot_taker_fee,
1152+
max_spot_maker_fee,
1153+
approval_expiry,
1154+
nonce,
1155+
api_key_index
1156+
)
1157+
if error is not None:
1158+
return None, None, error
1159+
1160+
logging.debug(f"Approve Integrator TxHash: {tx_hash} TxInfo: {tx_info}")
1161+
api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info)
1162+
logging.debug(f"Approve Integrator Send. TxResponse: {api_response}")
1163+
return tx_info, api_response, None
1164+
11111165
@process_api_key_and_nonce
11121166
async def transfer(self, eth_private_key: str, to_account_index: int, asset_id: int, route_from: int, route_to: int, amount: float, fee: int, memo: str, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX):
11131167
if asset_id in self.ASSET_TO_TICKER_SCALE:
0 Bytes
Binary file not shown.

lighter/signers/lighter-signer-darwin-arm64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ extern ApiKeyResponse GenerateAPIKey(void);
126126
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long cAccountIndex);
127127
extern char* CheckClient(int cApiKeyIndex, long long cAccountIndex);
128128
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
129-
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long cClientOrderIndex, long long cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long cOrderExpiry, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
129+
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long cClientOrderIndex, long long cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long cOrderExpiry, long long cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
130130
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
131131
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long cOrderIndex, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
132132
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, unsigned long long cAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
133133
extern SignedTxResponse SignCreateSubAccount(long long cNonce, int cApiKeyIndex, long long cAccountIndex);
134134
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long cTime, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
135-
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long cIndex, long long cBaseAmount, long long cPrice, long long cTriggerPrice, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
135+
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long cIndex, long long cBaseAmount, long long cPrice, long long cTriggerPrice, long long cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
136136
extern SignedTxResponse SignTransfer(long long cToAccountIndex, int16_t cAssetIndex, uint8_t cFromRouteType, uint8_t cToRouteType, long long cAmount, long long cUsdcFee, char* cMemo, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
137137
extern SignedTxResponse SignCreatePublicPool(long long cOperatorFee, int cInitialTotalShares, long long cMinOperatorShareRate, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
138138
extern SignedTxResponse SignUpdatePublicPool(long long cPublicPoolIndex, int cStatus, long long cOperatorFee, int cMinOperatorShareRate, long long cNonce, int cApiKeyIndex, long long cAccountIndex);

lighter/signers/lighter-signer-linux-amd64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ extern ApiKeyResponse GenerateAPIKey();
118118
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long int cAccountIndex);
119119
extern char* CheckClient(int cApiKeyIndex, long long int cAccountIndex);
120120
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
121-
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long int cClientOrderIndex, long long int cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long int cOrderExpiry, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
121+
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long int cClientOrderIndex, long long int cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long int cOrderExpiry, long long int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
122122
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
123123
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long int cOrderIndex, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
124124
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, long long unsigned int cAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
125125
extern SignedTxResponse SignCreateSubAccount(long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
126126
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long int cTime, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
127-
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long int cIndex, long long int cBaseAmount, long long int cPrice, long long int cTriggerPrice, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
127+
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long int cIndex, long long int cBaseAmount, long long int cPrice, long long int cTriggerPrice, long long int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
128128
extern SignedTxResponse SignTransfer(long long int cToAccountIndex, int16_t cAssetIndex, uint8_t cFromRouteType, uint8_t cToRouteType, long long int cAmount, long long int cUsdcFee, char* cMemo, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
129129
extern SignedTxResponse SignCreatePublicPool(long long int cOperatorFee, int cInitialTotalShares, long long int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
130130
extern SignedTxResponse SignUpdatePublicPool(long long int cPublicPoolIndex, int cStatus, long long int cOperatorFee, int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
8 Bytes
Binary file not shown.

lighter/signers/lighter-signer-linux-arm64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ extern ApiKeyResponse GenerateAPIKey();
118118
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long int cAccountIndex);
119119
extern char* CheckClient(int cApiKeyIndex, long long int cAccountIndex);
120120
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
121-
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long int cClientOrderIndex, long long int cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long int cOrderExpiry, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
121+
extern SignedTxResponse SignCreateOrder(int cMarketIndex, long long int cClientOrderIndex, long long int cBaseAmount, int cPrice, int cIsAsk, int cOrderType, int cTimeInForce, int cReduceOnly, int cTriggerPrice, long long int cOrderExpiry, long long int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
122122
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
123123
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long int cOrderIndex, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
124124
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, long long unsigned int cAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
125125
extern SignedTxResponse SignCreateSubAccount(long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
126126
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long int cTime, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
127-
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long int cIndex, long long int cBaseAmount, long long int cPrice, long long int cTriggerPrice, int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
127+
extern SignedTxResponse SignModifyOrder(int cMarketIndex, long long int cIndex, long long int cBaseAmount, long long int cPrice, long long int cTriggerPrice, long long int cIntegratorAccountIndex, int cIntegratorTakerFee, int cIntegratorMakerFee, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
128128
extern SignedTxResponse SignTransfer(long long int cToAccountIndex, int16_t cAssetIndex, uint8_t cFromRouteType, uint8_t cToRouteType, long long int cAmount, long long int cUsdcFee, char* cMemo, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
129129
extern SignedTxResponse SignCreatePublicPool(long long int cOperatorFee, int cInitialTotalShares, long long int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
130130
extern SignedTxResponse SignUpdatePublicPool(long long int cPublicPoolIndex, int cStatus, long long int cOperatorFee, int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
-104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)