Skip to content

Commit b134c92

Browse files
Adding enable and disable UTA
1 parent aaeed8e commit b134c92

11 files changed

Lines changed: 60 additions & 0 deletions

examples/disable_uta.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
async def main():
6+
client, api_client, _ = default_example_setup()
7+
8+
# Disable Unified Trading Account (mode=0, back to Simple)
9+
tx, response, err = await client.update_account_config(account_trading_mode=0)
10+
print(f"Disable UTA: {tx=} {response=} {err=}")
11+
if err is not None:
12+
raise Exception(err)
13+
14+
await client.close()
15+
await api_client.close()
16+
17+
18+
if __name__ == "__main__":
19+
asyncio.run(main())

examples/enable_uta.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import asyncio
2+
from utils import default_example_setup
3+
4+
5+
async def main():
6+
client, api_client, _ = default_example_setup()
7+
8+
# Enable Unified Trading Account (mode=1)
9+
tx, response, err = await client.update_account_config(account_trading_mode=1)
10+
print(f"Enable UTA: {tx=} {response=} {err=}")
11+
if err is not None:
12+
raise Exception(err)
13+
14+
await client.close()
15+
await api_client.close()
16+
17+
18+
if __name__ == "__main__":
19+
asyncio.run(main())

lighter/signer_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def __populate_shared_library_functions(signer):
172172
signer.SignApproveIntegrator.argtypes = [ctypes.c_longlong, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_longlong, ctypes.c_uint8, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
173173
signer.SignApproveIntegrator.restype = SignedTxResponse
174174

175+
signer.SignUpdateAccountConfig.argtypes = [ctypes.c_uint8, ctypes.c_uint8, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong]
176+
signer.SignUpdateAccountConfig.restype = SignedTxResponse
177+
175178
signer.Free.argtypes = [ctypes.c_void_p]
176179
signer.Free.restype = None
177180

@@ -620,6 +623,11 @@ def sign_update_leverage(self, market_index: int, fraction: int, margin_mode: in
620623
def sign_update_margin(self, market_index: int, usdc_amount: int, direction: int, skip_nonce: int = SKIP_NONCE_OFF, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX) -> Union[Tuple[str, str, str, None], Tuple[None, None, None, str]]:
621624
return self.__decode_tx_info(self.signer.SignUpdateMargin(market_index, usdc_amount, direction, skip_nonce, nonce, api_key_index, self.account_index))
622625

626+
def sign_update_account_config(self, account_trading_mode: int, skip_nonce: int = SKIP_NONCE_OFF,
627+
nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX):
628+
return self.__decode_tx_info(self.signer.SignUpdateAccountConfig(account_trading_mode, skip_nonce, nonce, api_key_index,
629+
self.account_index))
630+
623631
@process_api_key_and_nonce
624632
async def create_order(
625633
self,
@@ -1342,6 +1350,16 @@ async def update_margin(self, market_index: int, usdc_amount: float, direction:
13421350
logging.debug(f"Update Margin Tx Response: {api_response}")
13431351
return tx_info, api_response, None
13441352

1353+
@process_api_key_and_nonce
1354+
async def update_account_config(self, account_trading_mode: int, skip_nonce: int = SKIP_NONCE_OFF,
1355+
nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX):
1356+
tx_type, tx_info, tx_hash, error = self.sign_update_account_config(account_trading_mode, skip_nonce, nonce,
1357+
api_key_index)
1358+
if error is not None:
1359+
return None, None, error
1360+
api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info)
1361+
return tx_info, api_response, None
1362+
13451363
async def send_tx(self, tx_type: StrictInt, tx_info: str) -> RespSendTx:
13461364
if tx_info[0] != "{":
13471365
raise Exception(tx_info)
544 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long cUSDCAmount
141141
extern SignedTxResponse SignStakeAssets(long long cStakingPoolIndex, long long cShareAmount, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
142142
extern SignedTxResponse SignUnstakeAssets(long long cStakingPoolIndex, long long cShareAmount, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
143143
extern SignedTxResponse SignApproveIntegrator(long long cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long cApprovalExpiry, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
144+
extern SignedTxResponse SignUpdateAccountConfig(uint8_t cAccountTradingMode, uint8_t cSkipNonce, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
144145
extern void Free(void* ptr);
145146

146147
#ifdef __cplusplus

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAm
133133
extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
134134
extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
135135
extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
136+
extern SignedTxResponse SignUpdateAccountConfig(uint8_t cAccountTradingMode, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
136137
extern void Free(void* ptr);
137138

138139
#ifdef __cplusplus
7.4 KB
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAm
133133
extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
134134
extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
135135
extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
136+
extern SignedTxResponse SignUpdateAccountConfig(uint8_t cAccountTradingMode, uint8_t cSkipNonce, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
136137
extern void Free(void* ptr);
137138

138139
#ifdef __cplusplus
7.5 KB
Binary file not shown.
19.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)