diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index e3640d9..9c5af95 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -16,6 +16,7 @@ docs/AnnouncementApi.md docs/Announcements.md docs/ApiKey.md docs/ApiToken.md +docs/ApprovedIntegrator.md docs/Asset.md docs/AssetDetails.md docs/Auth.md @@ -157,6 +158,7 @@ docs/SubAccounts.md docs/SystemConfig.md docs/Ticker.md docs/Trade.md +docs/TradeStats.md docs/Trades.md docs/TransactionApi.md docs/TransferFeeInfo.md @@ -205,6 +207,7 @@ lighter/models/announcement.py lighter/models/announcements.py lighter/models/api_key.py lighter/models/api_token.py +lighter/models/approved_integrator.py lighter/models/asset.py lighter/models/asset_details.py lighter/models/auth.py @@ -337,6 +340,7 @@ lighter/models/sub_accounts.py lighter/models/system_config.py lighter/models/ticker.py lighter/models/trade.py +lighter/models/trade_stats.py lighter/models/trades.py lighter/models/transfer_fee_info.py lighter/models/transfer_history.py @@ -353,6 +357,7 @@ lighter/rest.py setup.cfg test-requirements.txt test/__init__.py +test/test_approved_integrator.py test/test_exchange_metric.py test/test_execute_stat.py test/test_lease_entry.py @@ -376,5 +381,6 @@ test/test_slippage_result.py test/test_spot_avg_entry_price.py test/test_strategy.py test/test_system_config.py +test/test_trade_stats.py test/test_user_referrals.py tox.ini diff --git a/docs/ApprovedIntegrator.md b/docs/ApprovedIntegrator.md new file mode 100644 index 0000000..4bbb4b6 --- /dev/null +++ b/docs/ApprovedIntegrator.md @@ -0,0 +1,35 @@ +# ApprovedIntegrator + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**account_index** | **int** | | +**name** | **str** | | +**max_perps_taker_fee** | **int** | | +**max_perps_maker_fee** | **int** | | +**max_spot_taker_fee** | **int** | | +**max_spot_maker_fee** | **int** | | +**approval_expiry** | **int** | Timestamp in milliseconds, after which the integrator is no longer approved | + +## Example + +```python +from lighter.models.approved_integrator import ApprovedIntegrator + +# TODO update the JSON string below +json = "{}" +# create an instance of ApprovedIntegrator from a JSON string +approved_integrator_instance = ApprovedIntegrator.from_json(json) +# print the JSON string representation of the object +print(ApprovedIntegrator.to_json()) + +# convert the object into a dict +approved_integrator_dict = approved_integrator_instance.to_dict() +# create an instance of ApprovedIntegrator from a dict +approved_integrator_from_dict = ApprovedIntegrator.from_dict(approved_integrator_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/DetailedAccount.md b/docs/DetailedAccount.md index dea48d9..9c2f857 100644 --- a/docs/DetailedAccount.md +++ b/docs/DetailedAccount.md @@ -32,6 +32,7 @@ Name | Type | Description | Notes **pool_info** | [**PublicPoolInfo**](PublicPoolInfo.md) | | **shares** | [**List[PublicPoolShare]**](PublicPoolShare.md) | | **pending_unlocks** | [**List[PendingUnlock]**](PendingUnlock.md) | | +**approved_integrators** | [**List[ApprovedIntegrator]**](ApprovedIntegrator.md) | | ## Example diff --git a/docs/Order.md b/docs/Order.md index d0e7216..72c269c 100644 --- a/docs/Order.md +++ b/docs/Order.md @@ -34,6 +34,9 @@ Name | Type | Description | Notes **to_trigger_order_id_0** | **str** | | **to_trigger_order_id_1** | **str** | | **to_cancel_order_id_0** | **str** | | +**integrator_fee_collector_index** | **str** | | +**integrator_taker_fee** | **str** | | +**integrator_maker_fee** | **str** | | **block_height** | **int** | | **timestamp** | **int** | | **created_at** | **int** | | diff --git a/docs/Referral.md b/docs/Referral.md index a835f02..35fa907 100644 --- a/docs/Referral.md +++ b/docs/Referral.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **l1_address** | **str** | | **referral_code** | **str** | | **used_at** | **int** | | +**trade_stats** | [**TradeStats**](TradeStats.md) | | ## Example diff --git a/docs/SystemConfig.md b/docs/SystemConfig.md index 8c7bf53..ac5cc1d 100644 --- a/docs/SystemConfig.md +++ b/docs/SystemConfig.md @@ -12,6 +12,10 @@ Name | Type | Description | Notes **funding_fee_rebate_account_index** | **int** | | **liquidity_pool_cooldown_period** | **int** | | **staking_pool_lockup_period** | **int** | | +**max_integrator_spot_taker_fee** | **int** | | +**max_integrator_spot_maker_fee** | **int** | | +**max_integrator_perps_taker_fee** | **int** | | +**max_integrator_perps_maker_fee** | **int** | | ## Example diff --git a/docs/TradeStats.md b/docs/TradeStats.md new file mode 100644 index 0000000..eb2ae62 --- /dev/null +++ b/docs/TradeStats.md @@ -0,0 +1,36 @@ +# TradeStats + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**count** | **int** | | +**volume** | **str** | | +**web_count** | **int** | | +**web_volume** | **str** | | +**mobile_app_count** | **int** | | +**mobile_app_volume** | **str** | | +**mobile_browser_count** | **int** | | +**mobile_browser_volume** | **str** | | + +## Example + +```python +from lighter.models.trade_stats import TradeStats + +# TODO update the JSON string below +json = "{}" +# create an instance of TradeStats from a JSON string +trade_stats_instance = TradeStats.from_json(json) +# print the JSON string representation of the object +print(TradeStats.to_json()) + +# convert the object into a dict +trade_stats_dict = trade_stats_instance.to_dict() +# create an instance of TradeStats from a dict +trade_stats_from_dict = TradeStats.from_dict(trade_stats_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/examples/integrator_approve.py b/examples/integrator_approve.py new file mode 100644 index 0000000..622ca6e --- /dev/null +++ b/examples/integrator_approve.py @@ -0,0 +1,30 @@ +import asyncio +from utils import default_example_setup + + +ETH_PRIVATE_KEY = "" + +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( + eth_private_key=ETH_PRIVATE_KEY, + integrator_account_index=6, + 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()) \ No newline at end of file diff --git a/examples/integrator_create_market_order.py b/examples/integrator_create_market_order.py new file mode 100644 index 0000000..76354d6 --- /dev/null +++ b/examples/integrator_create_market_order.py @@ -0,0 +1,34 @@ +import asyncio +from utils import default_example_setup + + +async def main(): + client, api_client, _ = default_example_setup() + 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 + 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, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + ) + print(f"Create Order {tx=} {tx_hash=} {err=}") + if err is not None: + raise Exception(err) + + await client.close() + await api_client.close() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/integrator_create_modify_order.py b/examples/integrator_create_modify_order.py new file mode 100644 index 0000000..a63b96f --- /dev/null +++ b/examples/integrator_create_modify_order.py @@ -0,0 +1,74 @@ +import asyncio +from utils import default_example_setup + + +async def main(): + client, api_client, _ = default_example_setup() + 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 + integrator_taker_fee = 1000 + integrator_maker_fee = 500 + + # create order + api_key_index, nonce = client.nonce_manager.next_nonce() + tx, tx_hash, err = await client.create_order( + market_index=market_index, + client_order_index=123, + base_amount=1000, # 0.1 ETH + price=4050_00, # $4050 + is_ask=True, + order_type=client.ORDER_TYPE_LIMIT, + time_in_force=client.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME, + reduce_only=False, + trigger_price=0, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, + ) + print(f"Create Order {tx=} {tx_hash=} {err=}") + if err is not None: + raise Exception(err) + + ## modify order + # use the same API key so the TX goes after the create order TX + api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index) + tx, tx_hash, err = await client.modify_order( + market_index=market_index, + order_index=123, + base_amount=1100, # 0.11 ETH + price=4100_00, # $4100 + trigger_price=0, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee // 2, # integrator fees can also be modified + integrator_maker_fee=integrator_maker_fee // 2, + nonce=nonce, + api_key_index=api_key_index, + ) + print(f"Modify Order {tx=} {tx_hash=} {err=}") + if err is not None: + raise Exception(err) + + ## cancel order + # use the same API key so the TX goes after the modify order TX + api_key_index, nonce = client.nonce_manager.next_nonce(api_key_index) + tx, tx_hash, err = await client.cancel_order( + market_index=market_index, + order_index=123, + nonce=nonce, + api_key_index=api_key_index, + ) + print(f"Cancel Order {tx=} {tx_hash=} {err=}") + if err is not None: + raise Exception(err) + + await client.close() + await api_client.close() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/examples/integrator_revoke.py b/examples/integrator_revoke.py new file mode 100644 index 0000000..6abe9b8 --- /dev/null +++ b/examples/integrator_revoke.py @@ -0,0 +1,30 @@ +import asyncio +from utils import default_example_setup + + +ETH_PRIVATE_KEY = "" + +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( + eth_private_key=ETH_PRIVATE_KEY, + integrator_account_index=6, + max_perps_taker_fee=0, + max_perps_maker_fee=0, + max_spot_taker_fee=0, + max_spot_maker_fee=0, + approval_expiry=0 + ) + print(tx_info, response, err) + + await client.close() + await api_client.close() + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/examples/read-only-auth/generate.py b/examples/read-only-auth/generate.py index bd5c407..68161d3 100644 --- a/examples/read-only-auth/generate.py +++ b/examples/read-only-auth/generate.py @@ -25,9 +25,8 @@ async def generate_tokens_for_account(account_info, base_url, duration_days): signer_client = lighter.SignerClient( url=base_url, - private_key=api_key_private_key, + api_private_keys={api_key_index: api_key_private_key}, account_index=account_index, - api_key_index=api_key_index, ) current_time = int(time.time()) diff --git a/examples/read-only-auth/setup.py b/examples/read-only-auth/setup.py index 31790ad..beaf494 100644 --- a/examples/read-only-auth/setup.py +++ b/examples/read-only-auth/setup.py @@ -21,9 +21,8 @@ async def setup_account(eth_private_key, account_index, base_url, api_key_index) tx_client = lighter.SignerClient( url=base_url, - private_key=private_key, + api_private_keys={api_key_index: private_key}, account_index=account_index, - api_key_index=api_key_index, ) response, err = await tx_client.change_api_key( diff --git a/examples/stake_and_unstake.py b/examples/stake_and_unstake.py new file mode 100644 index 0000000..a8b9022 --- /dev/null +++ b/examples/stake_and_unstake.py @@ -0,0 +1,30 @@ +import asyncio + +from utils import default_example_setup + +STAKING_POOL_INDEX = 281474976624800 + + +async def main(): + client, api_client, _ = default_example_setup() + + err = client.check_client() + if err is not None: + print(f"CheckClient error: {err}") + return + + try: + tx_info, response, err = await client.stake_assets(public_pool_index=STAKING_POOL_INDEX, share_amount=10_000) + if err is not None: + raise Exception(f'failed to stake assets {err}') + + tx_info, response, err = await client.unstake_assets(public_pool_index=STAKING_POOL_INDEX, share_amount=10_000) + if err is not None: + raise Exception(f'failed to unstake assets {err}') + finally: + await client.close() + await api_client.close() + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/lighter/__init__.py b/lighter/__init__.py index d4a9ac4..2264126 100644 --- a/lighter/__init__.py +++ b/lighter/__init__.py @@ -58,6 +58,7 @@ from lighter.models.announcements import Announcements from lighter.models.api_key import ApiKey from lighter.models.api_token import ApiToken +from lighter.models.approved_integrator import ApprovedIntegrator from lighter.models.asset import Asset from lighter.models.asset_details import AssetDetails from lighter.models.auth import Auth @@ -190,6 +191,7 @@ from lighter.models.system_config import SystemConfig from lighter.models.ticker import Ticker from lighter.models.trade import Trade +from lighter.models.trade_stats import TradeStats from lighter.models.trades import Trades from lighter.models.transfer_fee_info import TransferFeeInfo from lighter.models.transfer_history import TransferHistory diff --git a/lighter/models/__init__.py b/lighter/models/__init__.py index 1783c97..824f0ca 100644 --- a/lighter/models/__init__.py +++ b/lighter/models/__init__.py @@ -30,6 +30,7 @@ from lighter.models.announcements import Announcements from lighter.models.api_key import ApiKey from lighter.models.api_token import ApiToken +from lighter.models.approved_integrator import ApprovedIntegrator from lighter.models.asset import Asset from lighter.models.asset_details import AssetDetails from lighter.models.auth import Auth @@ -162,6 +163,7 @@ from lighter.models.system_config import SystemConfig from lighter.models.ticker import Ticker from lighter.models.trade import Trade +from lighter.models.trade_stats import TradeStats from lighter.models.trades import Trades from lighter.models.transfer_fee_info import TransferFeeInfo from lighter.models.transfer_history import TransferHistory diff --git a/lighter/models/approved_integrator.py b/lighter/models/approved_integrator.py new file mode 100644 index 0000000..b46e887 --- /dev/null +++ b/lighter/models/approved_integrator.py @@ -0,0 +1,112 @@ +# coding: utf-8 + +""" + + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr +from typing import Any, ClassVar, Dict, List +from typing import Optional, Set +from typing_extensions import Self + +class ApprovedIntegrator(BaseModel): + """ + ApprovedIntegrator + """ # noqa: E501 + account_index: StrictInt + name: StrictStr + max_perps_taker_fee: StrictInt + max_perps_maker_fee: StrictInt + max_spot_taker_fee: StrictInt + max_spot_maker_fee: StrictInt + approval_expiry: StrictInt = Field(description=" Timestamp in milliseconds, after which the integrator is no longer approved") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["account_index", "name", "max_perps_taker_fee", "max_perps_maker_fee", "max_spot_taker_fee", "max_spot_maker_fee", "approval_expiry"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of ApprovedIntegrator from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of ApprovedIntegrator from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_construct(**{ + "account_index": obj.get("account_index"), + "name": obj.get("name"), + "max_perps_taker_fee": obj.get("max_perps_taker_fee"), + "max_perps_maker_fee": obj.get("max_perps_maker_fee"), + "max_spot_taker_fee": obj.get("max_spot_taker_fee"), + "max_spot_maker_fee": obj.get("max_spot_maker_fee"), + "approval_expiry": obj.get("approval_expiry") + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/lighter/models/detailed_account.py b/lighter/models/detailed_account.py index 12b730e..22a747a 100644 --- a/lighter/models/detailed_account.py +++ b/lighter/models/detailed_account.py @@ -21,6 +21,7 @@ from typing import Any, ClassVar, Dict, List, Optional from lighter.models.account_asset import AccountAsset from lighter.models.account_position import AccountPosition +from lighter.models.approved_integrator import ApprovedIntegrator from lighter.models.pending_unlock import PendingUnlock from lighter.models.public_pool_info import PublicPoolInfo from lighter.models.public_pool_share import PublicPoolShare @@ -58,8 +59,9 @@ class DetailedAccount(BaseModel): pool_info: PublicPoolInfo shares: List[PublicPoolShare] pending_unlocks: List[PendingUnlock] + approved_integrators: List[ApprovedIntegrator] additional_properties: Dict[str, Any] = {} - __properties: ClassVar[List[str]] = ["code", "message", "account_type", "index", "l1_address", "cancel_all_time", "total_order_count", "total_isolated_order_count", "pending_order_count", "available_balance", "status", "collateral", "transaction_time", "account_trading_mode", "account_index", "name", "description", "can_invite", "referral_points_percentage", "created_at", "positions", "assets", "total_asset_value", "cross_asset_value", "pool_info", "shares", "pending_unlocks"] + __properties: ClassVar[List[str]] = ["code", "message", "account_type", "index", "l1_address", "cancel_all_time", "total_order_count", "total_isolated_order_count", "pending_order_count", "available_balance", "status", "collateral", "transaction_time", "account_trading_mode", "account_index", "name", "description", "can_invite", "referral_points_percentage", "created_at", "positions", "assets", "total_asset_value", "cross_asset_value", "pool_info", "shares", "pending_unlocks", "approved_integrators"] model_config = ConfigDict( populate_by_name=True, @@ -133,6 +135,13 @@ def to_dict(self) -> Dict[str, Any]: if _item: _items.append(_item.to_dict()) _dict['pending_unlocks'] = _items + # override the default output from pydantic by calling `to_dict()` of each item in approved_integrators (list) + _items = [] + if self.approved_integrators: + for _item in self.approved_integrators: + if _item: + _items.append(_item.to_dict()) + _dict['approved_integrators'] = _items # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: for _key, _value in self.additional_properties.items(): @@ -176,7 +185,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "cross_asset_value": obj.get("cross_asset_value"), "pool_info": PublicPoolInfo.from_dict(obj["pool_info"]) if obj.get("pool_info") is not None else None, "shares": [PublicPoolShare.from_dict(_item) for _item in obj["shares"]] if obj.get("shares") is not None else None, - "pending_unlocks": [PendingUnlock.from_dict(_item) for _item in obj["pending_unlocks"]] if obj.get("pending_unlocks") is not None else None + "pending_unlocks": [PendingUnlock.from_dict(_item) for _item in obj["pending_unlocks"]] if obj.get("pending_unlocks") is not None else None, + "approved_integrators": [ApprovedIntegrator.from_dict(_item) for _item in obj["approved_integrators"]] if obj.get("approved_integrators") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/lighter/models/order.py b/lighter/models/order.py index 42c370a..0e56204 100644 --- a/lighter/models/order.py +++ b/lighter/models/order.py @@ -55,13 +55,16 @@ class Order(BaseModel): to_trigger_order_id_0: StrictStr to_trigger_order_id_1: StrictStr to_cancel_order_id_0: StrictStr + integrator_fee_collector_index: StrictStr + integrator_taker_fee: StrictStr + integrator_maker_fee: StrictStr block_height: StrictInt timestamp: StrictInt created_at: StrictInt updated_at: StrictInt transaction_time: StrictInt additional_properties: Dict[str, Any] = {} - __properties: ClassVar[List[str]] = ["order_index", "client_order_index", "order_id", "client_order_id", "market_index", "owner_account_index", "initial_base_amount", "price", "nonce", "remaining_base_amount", "is_ask", "base_size", "base_price", "filled_base_amount", "filled_quote_amount", "side", "type", "time_in_force", "reduce_only", "trigger_price", "order_expiry", "status", "trigger_status", "trigger_time", "parent_order_index", "parent_order_id", "to_trigger_order_id_0", "to_trigger_order_id_1", "to_cancel_order_id_0", "block_height", "timestamp", "created_at", "updated_at", "transaction_time"] + __properties: ClassVar[List[str]] = ["order_index", "client_order_index", "order_id", "client_order_id", "market_index", "owner_account_index", "initial_base_amount", "price", "nonce", "remaining_base_amount", "is_ask", "base_size", "base_price", "filled_base_amount", "filled_quote_amount", "side", "type", "time_in_force", "reduce_only", "trigger_price", "order_expiry", "status", "trigger_status", "trigger_time", "parent_order_index", "parent_order_id", "to_trigger_order_id_0", "to_trigger_order_id_1", "to_cancel_order_id_0", "integrator_fee_collector_index", "integrator_taker_fee", "integrator_maker_fee", "block_height", "timestamp", "created_at", "updated_at", "transaction_time"] @field_validator('type') def type_validate_enum(cls, value): @@ -178,6 +181,9 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "to_trigger_order_id_0": obj.get("to_trigger_order_id_0"), "to_trigger_order_id_1": obj.get("to_trigger_order_id_1"), "to_cancel_order_id_0": obj.get("to_cancel_order_id_0"), + "integrator_fee_collector_index": obj.get("integrator_fee_collector_index"), + "integrator_taker_fee": obj.get("integrator_taker_fee"), + "integrator_maker_fee": obj.get("integrator_maker_fee"), "block_height": obj.get("block_height"), "timestamp": obj.get("timestamp"), "created_at": obj.get("created_at"), diff --git a/lighter/models/referral.py b/lighter/models/referral.py index 9d4393c..2dc106a 100644 --- a/lighter/models/referral.py +++ b/lighter/models/referral.py @@ -19,6 +19,7 @@ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr from typing import Any, ClassVar, Dict, List +from lighter.models.trade_stats import TradeStats from typing import Optional, Set from typing_extensions import Self @@ -29,8 +30,9 @@ class Referral(BaseModel): l1_address: StrictStr referral_code: StrictStr used_at: StrictInt + trade_stats: TradeStats additional_properties: Dict[str, Any] = {} - __properties: ClassVar[List[str]] = ["l1_address", "referral_code", "used_at"] + __properties: ClassVar[List[str]] = ["l1_address", "referral_code", "used_at", "trade_stats"] model_config = ConfigDict( populate_by_name=True, @@ -73,6 +75,9 @@ def to_dict(self) -> Dict[str, Any]: exclude=excluded_fields, exclude_none=True, ) + # override the default output from pydantic by calling `to_dict()` of trade_stats + if self.trade_stats: + _dict['trade_stats'] = self.trade_stats.to_dict() # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: for _key, _value in self.additional_properties.items(): @@ -92,7 +97,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: _obj = cls.model_construct(**{ "l1_address": obj.get("l1_address"), "referral_code": obj.get("referral_code"), - "used_at": obj.get("used_at") + "used_at": obj.get("used_at"), + "trade_stats": TradeStats.from_dict(obj["trade_stats"]) if obj.get("trade_stats") is not None else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/lighter/models/system_config.py b/lighter/models/system_config.py index da288a6..61a814b 100644 --- a/lighter/models/system_config.py +++ b/lighter/models/system_config.py @@ -33,8 +33,12 @@ class SystemConfig(BaseModel): funding_fee_rebate_account_index: StrictInt liquidity_pool_cooldown_period: StrictInt staking_pool_lockup_period: StrictInt + max_integrator_spot_taker_fee: StrictInt + max_integrator_spot_maker_fee: StrictInt + max_integrator_perps_taker_fee: StrictInt + max_integrator_perps_maker_fee: StrictInt additional_properties: Dict[str, Any] = {} - __properties: ClassVar[List[str]] = ["code", "message", "liquidity_pool_index", "staking_pool_index", "funding_fee_rebate_account_index", "liquidity_pool_cooldown_period", "staking_pool_lockup_period"] + __properties: ClassVar[List[str]] = ["code", "message", "liquidity_pool_index", "staking_pool_index", "funding_fee_rebate_account_index", "liquidity_pool_cooldown_period", "staking_pool_lockup_period", "max_integrator_spot_taker_fee", "max_integrator_spot_maker_fee", "max_integrator_perps_taker_fee", "max_integrator_perps_maker_fee"] model_config = ConfigDict( populate_by_name=True, @@ -100,7 +104,11 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "staking_pool_index": obj.get("staking_pool_index"), "funding_fee_rebate_account_index": obj.get("funding_fee_rebate_account_index"), "liquidity_pool_cooldown_period": obj.get("liquidity_pool_cooldown_period"), - "staking_pool_lockup_period": obj.get("staking_pool_lockup_period") + "staking_pool_lockup_period": obj.get("staking_pool_lockup_period"), + "max_integrator_spot_taker_fee": obj.get("max_integrator_spot_taker_fee"), + "max_integrator_spot_maker_fee": obj.get("max_integrator_spot_maker_fee"), + "max_integrator_perps_taker_fee": obj.get("max_integrator_perps_taker_fee"), + "max_integrator_perps_maker_fee": obj.get("max_integrator_perps_maker_fee") }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/lighter/models/trade_stats.py b/lighter/models/trade_stats.py new file mode 100644 index 0000000..28e48ef --- /dev/null +++ b/lighter/models/trade_stats.py @@ -0,0 +1,114 @@ +# coding: utf-8 + +""" + + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr +from typing import Any, ClassVar, Dict, List +from typing import Optional, Set +from typing_extensions import Self + +class TradeStats(BaseModel): + """ + TradeStats + """ # noqa: E501 + count: StrictInt + volume: StrictStr + web_count: StrictInt + web_volume: StrictStr + mobile_app_count: StrictInt + mobile_app_volume: StrictStr + mobile_browser_count: StrictInt + mobile_browser_volume: StrictStr + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["count", "volume", "web_count", "web_volume", "mobile_app_count", "mobile_app_volume", "mobile_browser_count", "mobile_browser_volume"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of TradeStats from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of TradeStats from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_construct(**{ + "count": obj.get("count"), + "volume": obj.get("volume"), + "web_count": obj.get("web_count"), + "web_volume": obj.get("web_volume"), + "mobile_app_count": obj.get("mobile_app_count"), + "mobile_app_volume": obj.get("mobile_app_volume"), + "mobile_browser_count": obj.get("mobile_browser_count"), + "mobile_browser_volume": obj.get("mobile_browser_volume") + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/lighter/signer_client.py b/lighter/signer_client.py index a1be4b3..d8d228f 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -31,7 +31,7 @@ class ApiKeyResponse(ctypes.Structure): class CreateOrderTxReq(ctypes.Structure): _fields_ = [ - ("MarketIndex", ctypes.c_uint8), + ("MarketIndex", ctypes.c_int), ("ClientOrderIndex", ctypes.c_longlong), ("BaseAmount", ctypes.c_longlong), ("Price", ctypes.c_uint32), @@ -41,6 +41,9 @@ class CreateOrderTxReq(ctypes.Structure): ("ReduceOnly", ctypes.c_uint8), ("TriggerPrice", ctypes.c_uint32), ("OrderExpiry", ctypes.c_longlong), + ("IntegratorAccountIndex", ctypes.c_int64), + ("IntegratorMakerFee", ctypes.c_int64), + ("IntegratorTakerFee", ctypes.c_int64), ] @@ -114,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_longlong, ctypes.c_int, ctypes.c_longlong] + 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] 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] @@ -132,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_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_int, 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] @@ -150,6 +153,12 @@ def __populate_shared_library_functions(signer): signer.SignBurnShares.argtypes = [ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] signer.SignBurnShares.restype = SignedTxResponse + signer.SignStakeAssets.argtypes = [ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] + signer.SignStakeAssets.restype = SignedTxResponse + + signer.SignUnstakeAssets.argtypes = [ctypes.c_longlong, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] + signer.SignUnstakeAssets.restype = SignedTxResponse + signer.SignUpdateLeverage.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] signer.SignUpdateLeverage.restype = SignedTxResponse @@ -162,6 +171,9 @@ def __populate_shared_library_functions(signer): signer.SignUpdateMargin.argtypes = [ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] signer.SignUpdateMargin.restype = SignedTxResponse + signer.SignApproveIntegrator.argtypes = [ctypes.c_longlong, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_longlong, ctypes.c_longlong, ctypes.c_int, ctypes.c_longlong] + signer.SignApproveIntegrator.restype = SignedTxResponse + def get_signer(): # check if singleton exists already @@ -445,6 +457,10 @@ def sign_create_order( reduce_only=False, trigger_price=NIL_TRIGGER_PRICE, order_expiry=DEFAULT_28_DAY_ORDER_EXPIRY, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX ) -> Union[Tuple[str, str, str, None], Tuple[None, None, None, str]]: @@ -459,6 +475,9 @@ def sign_create_order( reduce_only, trigger_price, order_expiry, + integrator_account_index, + integrator_taker_fee, + integrator_maker_fee, nonce, api_key_index, self.account_index, @@ -490,8 +509,46 @@ def sign_create_sub_account(self, nonce: int = DEFAULT_NONCE, api_key_index: int def sign_cancel_all_orders(self, time_in_force: int, timestamp_ms: int, 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_tx_info(self.signer.SignCancelAllOrders(time_in_force, timestamp_ms, nonce, api_key_index, self.account_index)) - def sign_modify_order(self, market_index: int, order_index: int, base_amount: int, price: int, trigger_price: int = NIL_TRIGGER_PRICE, 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_tx_info(self.signer.SignModifyOrder(market_index, order_index, base_amount, price, trigger_price, nonce, api_key_index, self.account_index)) + def sign_modify_order( + self, + market_index: int, + order_index: int, + base_amount: int, + price: int, + trigger_price: int = NIL_TRIGGER_PRICE, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + 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_tx_info(self.signer.SignModifyOrder(market_index, order_index, base_amount, price, trigger_price, integrator_account_index, integrator_taker_fee, integrator_maker_fee, nonce, api_key_index, self.account_index)) + + def sign_approve_integrator( + self, + eth_private_key: str, + 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_and_sign_tx_info(eth_private_key, 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)) @@ -511,6 +568,12 @@ def sign_mint_shares(self, public_pool_index: int, share_amount: int, nonce: int def sign_burn_shares(self, public_pool_index: int, share_amount: int, 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_tx_info(self.signer.SignBurnShares(public_pool_index, share_amount, nonce, api_key_index, self.account_index)) + def sign_stake_assets(self, staking_pool_index: int, share_amount: int, 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_tx_info(self.signer.SignStakeAssets(staking_pool_index, share_amount, nonce, api_key_index, self.account_index)) + + def sign_unstake_assets(self, staking_pool_index: int, share_amount: int, 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_tx_info(self.signer.SignUnstakeAssets(staking_pool_index, share_amount, nonce, api_key_index, self.account_index)) + def sign_update_leverage(self, market_index: int, fraction: int, margin_mode: int, 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_tx_info(self.signer.SignUpdateLeverage(market_index, fraction, margin_mode, nonce, api_key_index, self.account_index)) @@ -530,6 +593,10 @@ async def create_order( reduce_only=False, trigger_price=NIL_TRIGGER_PRICE, order_expiry=DEFAULT_28_DAY_ORDER_EXPIRY, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: @@ -544,8 +611,11 @@ async def create_order( reduce_only, trigger_price, order_expiry, - nonce, - api_key_index, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, ) if error is not None: return None, None, error @@ -560,6 +630,7 @@ async def create_grouped_orders( self, grouping_type: int, orders: List[CreateOrderTxReq], + *, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX ) ->Union[Tuple[CreateGroupedOrders, RespSendTx, None], Tuple[None, None, str]]: @@ -585,6 +656,10 @@ async def create_market_order( avg_execution_price, is_ask, reduce_only: bool = False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: @@ -598,6 +673,9 @@ async def create_market_order( time_in_force=self.ORDER_TIME_IN_FORCE_IMMEDIATE_OR_CANCEL, order_expiry=self.DEFAULT_IOC_EXPIRY, reduce_only=reduce_only, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, nonce=nonce, api_key_index=api_key_index, ) @@ -636,9 +714,13 @@ async def create_market_order_quote_amount( max_slippage, is_ask, reduce_only: bool = False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + ideal_price=None, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX, - ideal_price=None ): quote_amount = int(quote_amount * 1e6) ob_orders = await self.order_api.order_book_orders(market_index, 100) @@ -673,6 +755,9 @@ async def create_market_order_quote_amount( time_in_force=self.ORDER_TIME_IN_FORCE_IMMEDIATE_OR_CANCEL, order_expiry=self.DEFAULT_IOC_EXPIRY, reduce_only=reduce_only, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, nonce=nonce, api_key_index=api_key_index, ) @@ -686,9 +771,13 @@ async def create_market_order_limited_slippage( max_slippage, is_ask, reduce_only: bool = False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + ideal_price=None, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX, - ideal_price=None ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: if ideal_price is None: logging.debug( @@ -706,6 +795,9 @@ async def create_market_order_limited_slippage( time_in_force=self.ORDER_TIME_IN_FORCE_IMMEDIATE_OR_CANCEL, order_expiry=self.DEFAULT_IOC_EXPIRY, reduce_only=reduce_only, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, nonce=nonce, api_key_index=api_key_index, ) @@ -719,9 +811,13 @@ async def create_market_order_if_slippage( max_slippage, is_ask, reduce_only: bool = False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + ideal_price=None, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX, - ideal_price=None ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: ob_orders = await self.order_api.order_book_orders(market_index, 100) if ideal_price is None: @@ -751,6 +847,9 @@ async def create_market_order_if_slippage( time_in_force=self.ORDER_TIME_IN_FORCE_IMMEDIATE_OR_CANCEL, order_expiry=self.DEFAULT_IOC_EXPIRY, reduce_only=reduce_only, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, nonce=nonce, api_key_index=api_key_index, ) @@ -768,10 +867,22 @@ async def cancel_order(self, market_index, order_index, nonce: int = DEFAULT_NON logging.debug(f"Cancel Order Send. TxResponse: {api_response}") return CancelOrder.from_json(tx_info), api_response, None - async def create_tp_order(self, market_index, client_order_index, base_amount, trigger_price, price, is_ask, reduce_only=False, - nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX - ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: + async def create_tp_order( + self, + market_index, + client_order_index, + base_amount, + trigger_price, + price, + is_ask, + reduce_only=False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + nonce: int = DEFAULT_NONCE, + api_key_index: int = DEFAULT_API_KEY_INDEX + ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: return await self.create_order( market_index, client_order_index, @@ -783,14 +894,29 @@ async def create_tp_order(self, market_index, client_order_index, base_amount, t reduce_only, trigger_price, self.DEFAULT_28_DAY_ORDER_EXPIRY, - nonce, - api_key_index, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, ) - async def create_tp_limit_order(self, market_index, client_order_index, base_amount, trigger_price, price, is_ask, reduce_only=False, - nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX - ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: + async def create_tp_limit_order( + self, + market_index, + client_order_index, + base_amount, + trigger_price, + price, + is_ask, + reduce_only=False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + nonce: int = DEFAULT_NONCE, + api_key_index: int = DEFAULT_API_KEY_INDEX + ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: return await self.create_order( market_index, client_order_index, @@ -802,14 +928,29 @@ async def create_tp_limit_order(self, market_index, client_order_index, base_amo reduce_only, trigger_price, self.DEFAULT_28_DAY_ORDER_EXPIRY, - nonce, - api_key_index, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, ) - async def create_sl_order(self, market_index, client_order_index, base_amount, trigger_price, price, is_ask, reduce_only=False, - nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX - ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: + async def create_sl_order( + self, + market_index, + client_order_index, + base_amount, + trigger_price, + price, + is_ask, + reduce_only=False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + nonce: int = DEFAULT_NONCE, + api_key_index: int = DEFAULT_API_KEY_INDEX + ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: return await self.create_order( market_index, client_order_index, @@ -821,14 +962,29 @@ async def create_sl_order(self, market_index, client_order_index, base_amount, t reduce_only, trigger_price, self.DEFAULT_28_DAY_ORDER_EXPIRY, - nonce, - api_key_index, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, ) - async def create_sl_limit_order(self, market_index, client_order_index, base_amount, trigger_price, price, is_ask, reduce_only=False, - nonce: int = DEFAULT_NONCE, - api_key_index: int = DEFAULT_API_KEY_INDEX - ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: + async def create_sl_limit_order( + self, + market_index, + client_order_index, + base_amount, + trigger_price, + price, + is_ask, + reduce_only=False, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + nonce: int = DEFAULT_NONCE, + api_key_index: int = DEFAULT_API_KEY_INDEX + ) -> Union[Tuple[CreateOrder, RespSendTx, None], Tuple[None, None, str]]: return await self.create_order( market_index, client_order_index, @@ -840,8 +996,11 @@ async def create_sl_limit_order(self, market_index, client_order_index, base_amo reduce_only, trigger_price, self.DEFAULT_28_DAY_ORDER_EXPIRY, - nonce, - api_key_index, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index, ) @process_api_key_and_nonce @@ -884,9 +1043,31 @@ async def cancel_all_orders(self, time_in_force, timestamp_ms, nonce: int = DEFA @process_api_key_and_nonce async def modify_order( - self, market_index, order_index, base_amount, price, trigger_price=NIL_TRIGGER_PRICE, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX + self, + market_index, + order_index, + base_amount, + price, + trigger_price=NIL_TRIGGER_PRICE, + *, + integrator_account_index: int = 0, + integrator_taker_fee: int = 0, + integrator_maker_fee: int = 0, + nonce: int = DEFAULT_NONCE, + api_key_index: int = DEFAULT_API_KEY_INDEX ): - tx_type, tx_info, tx_hash, error = self.sign_modify_order(market_index, order_index, base_amount, price, trigger_price, nonce, api_key_index) + tx_type, tx_info, tx_hash, error = self.sign_modify_order( + market_index, + order_index, + base_amount, + price, + trigger_price, + integrator_account_index=integrator_account_index, + integrator_taker_fee=integrator_taker_fee, + integrator_maker_fee=integrator_maker_fee, + nonce=nonce, + api_key_index=api_key_index + ) if error is not None: return None, None, error @@ -895,6 +1076,38 @@ async def modify_order( logging.debug(f"Modify Order Send. TxResponse: {api_response}") return tx_info, api_response, None + @process_api_key_and_nonce + async def approve_integrator( + self, + eth_private_key: str, + 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( + eth_private_key, + 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: @@ -979,6 +1192,28 @@ async def burn_shares(self, public_pool_index, share_amount, nonce: int = DEFAUL logging.debug(f"Burn Shares Send. TxResponse: {api_response}") return tx_info, api_response, None + @process_api_key_and_nonce + async def stake_assets(self, staking_pool_index, share_amount, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX): + tx_type, tx_info, tx_hash, error = self.sign_stake_assets(staking_pool_index, share_amount, nonce, api_key_index) + if error is not None: + return None, None, error + + logging.debug(f"Stake Assets TxHash: {tx_hash} TxInfo: {tx_info}") + api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info) + logging.debug(f"Stake Assets Send. TxResponse: {api_response}") + return tx_info, api_response, None + + @process_api_key_and_nonce + async def unstake_assets(self, staking_pool_index, share_amount, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX): + tx_type, tx_info, tx_hash, error = self.sign_unstake_assets(staking_pool_index, share_amount, nonce, api_key_index) + if error is not None: + return None, None, error + + logging.debug(f"Unstake Assets TxHash: {tx_hash} TxInfo: {tx_info}") + api_response = await self.send_tx(tx_type=tx_type, tx_info=tx_info) + logging.debug(f"Unstake Assets Send. TxResponse: {api_response}") + return tx_info, api_response, None + @process_api_key_and_nonce async def update_leverage(self, market_index, margin_mode, leverage, nonce: int = DEFAULT_NONCE, api_key_index: int = DEFAULT_API_KEY_INDEX): imf = int(10_000 / leverage) diff --git a/lighter/signers/lighter-signer-darwin-arm64.dylib b/lighter/signers/lighter-signer-darwin-arm64.dylib index cb267ad..0d5fd4b 100644 Binary files a/lighter/signers/lighter-signer-darwin-arm64.dylib and b/lighter/signers/lighter-signer-darwin-arm64.dylib differ diff --git a/lighter/signers/lighter-signer-darwin-arm64.h b/lighter/signers/lighter-signer-darwin-arm64.h index 307323c..34040f9 100644 --- a/lighter/signers/lighter-signer-darwin-arm64.h +++ b/lighter/signers/lighter-signer-darwin-arm64.h @@ -12,6 +12,8 @@ #ifndef GO_CGO_GOSTRING_TYPEDEF typedef struct { const char *p; ptrdiff_t n; } _GoString_; +extern size_t _GoStringLen(_GoString_ s); +extern const char *_GoStringPtr(_GoString_ s); #endif #endif @@ -43,7 +45,7 @@ typedef struct { } ApiKeyResponse; typedef struct { - uint8_t MarketIndex; + int16_t MarketIndex; int64_t ClientOrderIndex; int64_t BaseAmount; uint32_t Price; @@ -53,6 +55,9 @@ typedef struct { uint8_t ReduceOnly; uint32_t TriggerPrice; int64_t OrderExpiry; + int64_t IntegratorAccountIndex; + int64_t IntegratorMakerFee; + int64_t IntegratorTakerFee; } CreateOrderTxReq; #line 1 "cgo-generated-wrapper" @@ -81,10 +86,16 @@ typedef size_t GoUintptr; typedef float GoFloat32; typedef double GoFloat64; #ifdef _MSC_VER +#if !defined(__cplusplus) || _MSVC_LANG <= 201402L #include typedef _Fcomplex GoComplex64; typedef _Dcomplex GoComplex128; #else +#include +typedef std::complex GoComplex64; +typedef std::complex GoComplex128; +#endif +#else typedef float _Complex GoComplex64; typedef double _Complex GoComplex128; #endif @@ -111,17 +122,17 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; extern "C" { #endif -extern ApiKeyResponse GenerateAPIKey(); +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, 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 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, 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 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); @@ -130,6 +141,9 @@ extern SignedTxResponse SignBurnShares(long long cPublicPoolIndex, long long cSh extern SignedTxResponse SignUpdateLeverage(int cMarketIndex, int cInitialMarginFraction, int cMarginMode, long long cNonce, int cApiKeyIndex, long long cAccountIndex); extern StrOrErr CreateAuthToken(long long cDeadline, int cApiKeyIndex, long long cAccountIndex); extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long cUSDCAmount, int cDirection, long long cNonce, int cApiKeyIndex, long long cAccountIndex); +extern SignedTxResponse SignStakeAssets(long long cStakingPoolIndex, long long cShareAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex); +extern SignedTxResponse SignUnstakeAssets(long long cStakingPoolIndex, long long cShareAmount, long long cNonce, int cApiKeyIndex, long long cAccountIndex); +extern SignedTxResponse SignApproveIntegrator(long long cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long cApprovalExpiry, long long cNonce, int cApiKeyIndex, long long cAccountIndex); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-amd64.h b/lighter/signers/lighter-signer-linux-amd64.h index b097024..f2f9707 100644 --- a/lighter/signers/lighter-signer-linux-amd64.h +++ b/lighter/signers/lighter-signer-linux-amd64.h @@ -43,7 +43,7 @@ typedef struct { } ApiKeyResponse; typedef struct { - uint8_t MarketIndex; + int16_t MarketIndex; int64_t ClientOrderIndex; int64_t BaseAmount; uint32_t Price; @@ -53,6 +53,9 @@ typedef struct { uint8_t ReduceOnly; uint32_t TriggerPrice; int64_t OrderExpiry; + int64_t IntegratorAccountIndex; + int64_t IntegratorMakerFee; + int64_t IntegratorTakerFee; } CreateOrderTxReq; #line 1 "cgo-generated-wrapper" @@ -115,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, 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 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, 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 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); @@ -130,6 +133,9 @@ extern SignedTxResponse SignBurnShares(long long int cPublicPoolIndex, long long extern SignedTxResponse SignUpdateLeverage(int cMarketIndex, int cInitialMarginFraction, int cMarginMode, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern StrOrErr CreateAuthToken(long long int cDeadline, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAmount, int cDirection, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-amd64.so b/lighter/signers/lighter-signer-linux-amd64.so index fa3f8c6..2adf117 100644 Binary files a/lighter/signers/lighter-signer-linux-amd64.so and b/lighter/signers/lighter-signer-linux-amd64.so differ diff --git a/lighter/signers/lighter-signer-linux-arm64.h b/lighter/signers/lighter-signer-linux-arm64.h index b097024..f2f9707 100644 --- a/lighter/signers/lighter-signer-linux-arm64.h +++ b/lighter/signers/lighter-signer-linux-arm64.h @@ -43,7 +43,7 @@ typedef struct { } ApiKeyResponse; typedef struct { - uint8_t MarketIndex; + int16_t MarketIndex; int64_t ClientOrderIndex; int64_t BaseAmount; uint32_t Price; @@ -53,6 +53,9 @@ typedef struct { uint8_t ReduceOnly; uint32_t TriggerPrice; int64_t OrderExpiry; + int64_t IntegratorAccountIndex; + int64_t IntegratorMakerFee; + int64_t IntegratorTakerFee; } CreateOrderTxReq; #line 1 "cgo-generated-wrapper" @@ -115,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, 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 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, 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 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); @@ -130,6 +133,9 @@ extern SignedTxResponse SignBurnShares(long long int cPublicPoolIndex, long long extern SignedTxResponse SignUpdateLeverage(int cMarketIndex, int cInitialMarginFraction, int cMarginMode, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern StrOrErr CreateAuthToken(long long int cDeadline, int cApiKeyIndex, long long int cAccountIndex); extern SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAmount, int cDirection, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); #ifdef __cplusplus } diff --git a/lighter/signers/lighter-signer-linux-arm64.so b/lighter/signers/lighter-signer-linux-arm64.so index d9254e8..fa2de73 100644 Binary files a/lighter/signers/lighter-signer-linux-arm64.so and b/lighter/signers/lighter-signer-linux-arm64.so differ diff --git a/lighter/signers/lighter-signer-windows-amd64.dll b/lighter/signers/lighter-signer-windows-amd64.dll index 9d1c2f4..c6735f1 100644 Binary files a/lighter/signers/lighter-signer-windows-amd64.dll and b/lighter/signers/lighter-signer-windows-amd64.dll differ diff --git a/lighter/signers/lighter-signer-windows-amd64.h b/lighter/signers/lighter-signer-windows-amd64.h index 164e01c..eba7b7d 100644 --- a/lighter/signers/lighter-signer-windows-amd64.h +++ b/lighter/signers/lighter-signer-windows-amd64.h @@ -43,7 +43,7 @@ typedef struct { } ApiKeyResponse; typedef struct { - uint8_t MarketIndex; + int16_t MarketIndex; int64_t ClientOrderIndex; int64_t BaseAmount; uint32_t Price; @@ -53,6 +53,9 @@ typedef struct { uint8_t ReduceOnly; uint32_t TriggerPrice; int64_t OrderExpiry; + int64_t IntegratorAccountIndex; + int64_t IntegratorMakerFee; + int64_t IntegratorTakerFee; } CreateOrderTxReq; #line 1 "cgo-generated-wrapper" @@ -115,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, 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 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, 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 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); @@ -130,6 +133,9 @@ extern __declspec(dllexport) SignedTxResponse SignBurnShares(long long int cPubl extern __declspec(dllexport) SignedTxResponse SignUpdateLeverage(int cMarketIndex, int cInitialMarginFraction, int cMarginMode, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); extern __declspec(dllexport) StrOrErr CreateAuthToken(long long int cDeadline, int cApiKeyIndex, long long int cAccountIndex); extern __declspec(dllexport) SignedTxResponse SignUpdateMargin(int cMarketIndex, long long int cUSDCAmount, int cDirection, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern __declspec(dllexport) SignedTxResponse SignStakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern __declspec(dllexport) SignedTxResponse SignUnstakeAssets(long long int cStakingPoolIndex, long long int cShareAmount, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); +extern __declspec(dllexport) SignedTxResponse SignApproveIntegrator(long long int cIntegratorIndex, uint32_t cMaxPerpsTakerFee, uint32_t cMaxPerpsMakerFee, uint32_t cMaxSpotTakerFee, uint32_t cMaxSpotMakerFee, long long int cApprovalExpiry, long long int cNonce, int cApiKeyIndex, long long int cAccountIndex); #ifdef __cplusplus } diff --git a/openapi.json b/openapi.json index 6ef9dfd..5c56e0d 100644 --- a/openapi.json +++ b/openapi.json @@ -3746,6 +3746,56 @@ "scopes" ] }, + "ApprovedIntegrator": { + "type": "object", + "properties": { + "account_index": { + "type": "integer", + "format": "int64", + "example": "54621" + }, + "name": { + "type": "string", + "example": "Integrator1" + }, + "max_perps_taker_fee": { + "type": "integer", + "format": "int32", + "example": "10" + }, + "max_perps_maker_fee": { + "type": "integer", + "format": "int32", + "example": "1" + }, + "max_spot_taker_fee": { + "type": "integer", + "format": "int32", + "example": "10" + }, + "max_spot_maker_fee": { + "type": "integer", + "format": "int32", + "example": "1" + }, + "approval_expiry": { + "type": "integer", + "format": "int64", + "example": "1640995200", + "description": " Timestamp in milliseconds, after which the integrator is no longer approved" + } + }, + "title": "ApprovedIntegrator", + "required": [ + "account_index", + "name", + "max_perps_taker_fee", + "max_perps_maker_fee", + "max_spot_taker_fee", + "max_spot_maker_fee", + "approval_expiry" + ] + }, "Asset": { "type": "object", "properties": { @@ -4320,6 +4370,12 @@ "items": { "$ref": "#/definitions/PendingUnlock" } + }, + "approved_integrators": { + "type": "array", + "items": { + "$ref": "#/definitions/ApprovedIntegrator" + } } }, "title": "DetailedAccount", @@ -4349,7 +4405,8 @@ "cross_asset_value", "pool_info", "shares", - "pending_unlocks" + "pending_unlocks", + "approved_integrators" ] }, "DetailedAccounts": { @@ -5299,6 +5356,18 @@ "type": "string", "example": "1" }, + "integrator_fee_collector_index": { + "type": "string", + "example": "1" + }, + "integrator_taker_fee": { + "type": "string", + "example": "1" + }, + "integrator_maker_fee": { + "type": "string", + "example": "1" + }, "block_height": { "type": "integer", "format": "int64", @@ -5356,6 +5425,9 @@ "to_trigger_order_id_0", "to_trigger_order_id_1", "to_cancel_order_id_0", + "integrator_fee_collector_index", + "integrator_taker_fee", + "integrator_maker_fee", "block_height", "timestamp", "created_at", @@ -6480,13 +6552,17 @@ "used_at": { "type": "integer", "format": "int64" + }, + "trade_stats": { + "$ref": "#/definitions/TradeStats" } }, "title": "Referral", "required": [ "l1_address", "referral_code", - "used_at" + "used_at", + "trade_stats" ] }, "ReqAckNotif": { @@ -8944,6 +9020,26 @@ "type": "integer", "format": "int64", "example": "604800" + }, + "max_integrator_spot_taker_fee": { + "type": "integer", + "format": "int32", + "example": "200" + }, + "max_integrator_spot_maker_fee": { + "type": "integer", + "format": "int32", + "example": "200" + }, + "max_integrator_perps_taker_fee": { + "type": "integer", + "format": "int32", + "example": "200" + }, + "max_integrator_perps_maker_fee": { + "type": "integer", + "format": "int32", + "example": "200" } }, "title": "SystemConfig", @@ -8953,7 +9049,11 @@ "staking_pool_index", "funding_fee_rebate_account_index", "liquidity_pool_cooldown_period", - "staking_pool_lockup_period" + "staking_pool_lockup_period", + "max_integrator_spot_taker_fee", + "max_integrator_spot_maker_fee", + "max_integrator_perps_taker_fee", + "max_integrator_perps_maker_fee" ] }, "Ticker": { @@ -9154,6 +9254,50 @@ "bid_account_pnl" ] }, + "TradeStats": { + "type": "object", + "properties": { + "count": { + "type": "integer", + "format": "int64" + }, + "volume": { + "type": "string" + }, + "web_count": { + "type": "integer", + "format": "int64" + }, + "web_volume": { + "type": "string" + }, + "mobile_app_count": { + "type": "integer", + "format": "int64" + }, + "mobile_app_volume": { + "type": "string" + }, + "mobile_browser_count": { + "type": "integer", + "format": "int64" + }, + "mobile_browser_volume": { + "type": "string" + } + }, + "title": "TradeStats", + "required": [ + "count", + "volume", + "web_count", + "web_volume", + "mobile_app_count", + "mobile_app_volume", + "mobile_browser_count", + "mobile_browser_volume" + ] + }, "Trades": { "type": "object", "properties": { diff --git a/pyproject.toml b/pyproject.toml index d76dd6e..e9348c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lighter-sdk" -version = "1.0.4" +version = "1.0.5" description = "Python client for Lighter" authors = ["elliot"] license = "NoLicense" diff --git a/setup.py b/setup.py index 469cc03..0fac30d 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools NAME = "lighter-sdk" -VERSION = "1.0.4" +VERSION = "1.0.5" PYTHON_REQUIRES = ">=3.7" REQUIRES = [ "urllib3 >= 1.25.3, < 2.1.0",