Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/integrator_approve_same_master_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio
from utils import default_example_setup

async def main():
client, api_client, _ = default_example_setup()

err = client.check_client()
if err is not None:
print(f"CheckClient error: {err}")
return

tx_info, response, err = await client.approve_integrator_same_master_account(
integrator_account_index=281474976710647,
max_perps_taker_fee=1000,
max_perps_maker_fee=1000,
max_spot_taker_fee=1000,
max_spot_maker_fee=1000,
approval_expiry=1775518466000
)
print(tx_info, response, err)

await client.close()
await api_client.close()

if __name__ == "__main__":
asyncio.run(main())
9 changes: 5 additions & 4 deletions examples/integrator_create_market_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ async def main():
client.check_client()

# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
market_index = 0
integrator_account_index = 6
market_index = 2048
# integrator_account_index = 6
integrator_account_index = 281474976710647
integrator_taker_fee = 1000
integrator_maker_fee = 500

tx, tx_hash, err = await client.create_market_order(
market_index=market_index,
client_order_index=0,
base_amount=1000, # 0.1 ETH
avg_execution_price=4000_00,
is_ask=False,
avg_execution_price=1900_00,
is_ask=True,
integrator_account_index=integrator_account_index,
integrator_taker_fee=integrator_taker_fee,
integrator_maker_fee=integrator_maker_fee,
Expand Down
3 changes: 2 additions & 1 deletion examples/integrator_create_modify_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ async def main():

# Note: change this to 2048 to trade spot ETH. Make sure you have at least 0.1 ETH to trade spot.
market_index = 0
integrator_account_index = 6
# integrator_account_index = 6
integrator_account_index = 281474976710647
integrator_taker_fee = 1000
integrator_maker_fee = 500

Expand Down
58 changes: 56 additions & 2 deletions lighter/signer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __populate_shared_library_functions(signer):
signer.SignChangePubKey.restype = SignedTxResponse

signer.SignCreateOrder.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int,
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]
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]
signer.SignCreateOrder.restype = SignedTxResponse

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

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]
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]
signer.SignModifyOrder.restype = SignedTxResponse

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]
Expand Down Expand Up @@ -550,6 +550,30 @@ def sign_approve_integrator(
)
return self.__decode_and_sign_tx_info(eth_private_key, res)

def sign_approve_integrator_same_master_account(
self,
integrator_account_index: int,
max_perps_taker_fee: int,
max_perps_maker_fee: int,
max_spot_taker_fee: int,
max_spot_maker_fee: int,
approval_expiry: int,
nonce: int = DEFAULT_NONCE,
api_key_index: int = DEFAULT_API_KEY_INDEX
) -> Union[Tuple[str, str, str, None], Tuple[None, None, None, str]]:
res = self.signer.SignApproveIntegrator(
integrator_account_index,
max_perps_taker_fee,
max_perps_maker_fee,
max_spot_taker_fee,
max_spot_maker_fee,
approval_expiry,
nonce,
api_key_index,
self.account_index
)
return self.__decode_tx_info(res)

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]]:
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))

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

@process_api_key_and_nonce
async def approve_integrator_same_master_account(
self,
integrator_account_index: int,
max_perps_taker_fee: int,
max_perps_maker_fee: int,
max_spot_taker_fee: int,
max_spot_maker_fee: int,
approval_expiry: int,
nonce: int = DEFAULT_NONCE,
api_key_index: int = DEFAULT_API_KEY_INDEX
):
tx_type, tx_info, tx_hash, error = self.sign_approve_integrator_same_master_account(
integrator_account_index,
max_perps_taker_fee,
max_perps_maker_fee,
max_spot_taker_fee,
max_spot_maker_fee,
approval_expiry,
nonce,
api_key_index
)
if error is not None:
return None, None, error

logging.debug(f"Approve Integrator TxHash: {tx_hash} TxInfo: {tx_info}")
api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info)
logging.debug(f"Approve Integrator Send. TxResponse: {api_response}")
return tx_info, api_response, None

@process_api_key_and_nonce
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):
if asset_id in self.ASSET_TO_TICKER_SCALE:
Expand Down
Binary file modified lighter/signers/lighter-signer-darwin-arm64.dylib
Binary file not shown.
4 changes: 2 additions & 2 deletions lighter/signers/lighter-signer-darwin-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ extern ApiKeyResponse GenerateAPIKey(void);
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long cAccountIndex);
extern char* CheckClient(int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
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);
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);
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long cOrderIndex, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, unsigned long long cAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignCreateSubAccount(long long cNonce, int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long cTime, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
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);
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);
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);
extern SignedTxResponse SignCreatePublicPool(long long cOperatorFee, int cInitialTotalShares, long long cMinOperatorShareRate, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
extern SignedTxResponse SignUpdatePublicPool(long long cPublicPoolIndex, int cStatus, long long cOperatorFee, int cMinOperatorShareRate, long long cNonce, int cApiKeyIndex, long long cAccountIndex);
Expand Down
4 changes: 2 additions & 2 deletions lighter/signers/lighter-signer-linux-amd64.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ extern ApiKeyResponse GenerateAPIKey();
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long int cAccountIndex);
extern char* CheckClient(int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
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);
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long int cOrderIndex, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, long long unsigned int cAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCreateSubAccount(long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long int cTime, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
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);
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);
extern SignedTxResponse SignCreatePublicPool(long long int cOperatorFee, int cInitialTotalShares, long long int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
Expand Down
Binary file modified lighter/signers/lighter-signer-linux-amd64.so
Binary file not shown.
4 changes: 2 additions & 2 deletions lighter/signers/lighter-signer-linux-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ extern ApiKeyResponse GenerateAPIKey();
extern char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long int cAccountIndex);
extern char* CheckClient(int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignChangePubKey(char* cPubKey, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
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);
extern SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCancelOrder(int cMarketIndex, long long int cOrderIndex, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, long long unsigned int cAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCreateSubAccount(long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long int cTime, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
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);
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);
extern SignedTxResponse SignCreatePublicPool(long long int cOperatorFee, int cInitialTotalShares, long long int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
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);
Expand Down
Binary file modified lighter/signers/lighter-signer-linux-arm64.so
Binary file not shown.
Binary file modified lighter/signers/lighter-signer-windows-amd64.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions lighter/signers/lighter-signer-windows-amd64.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ extern __declspec(dllexport) ApiKeyResponse GenerateAPIKey();
extern __declspec(dllexport) char* CreateClient(char* cUrl, char* cPrivateKey, int cChainId, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) char* CheckClient(int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignChangePubKey(char* cPubKey, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) 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);
extern __declspec(dllexport) 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);
extern __declspec(dllexport) SignedTxResponse SignCreateGroupedOrders(uint8_t cGroupingType, CreateOrderTxReq* cOrders, int cLen, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignCancelOrder(int cMarketIndex, long long int cOrderIndex, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignWithdraw(int cAssetIndex, int cRouteType, long long unsigned int cAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignCreateSubAccount(long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignCancelAllOrders(int cTimeInForce, long long int cTime, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) 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);
extern __declspec(dllexport) 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);
extern __declspec(dllexport) 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);
extern __declspec(dllexport) SignedTxResponse SignCreatePublicPool(long long int cOperatorFee, int cInitialTotalShares, long long int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
extern __declspec(dllexport) SignedTxResponse SignUpdatePublicPool(long long int cPublicPoolIndex, int cStatus, long long int cOperatorFee, int cMinOperatorShareRate, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex);
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lighter-sdk"
version = "1.0.5"
version = "1.0.6"
description = "Python client for Lighter"
authors = ["elliot"]
license = "NoLicense"
Expand Down
Loading