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
6 changes: 6 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
35 changes: 35 additions & 0 deletions docs/ApprovedIntegrator.md
Original file line number Diff line number Diff line change
@@ -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)


1 change: 1 addition & 0 deletions docs/DetailedAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/Order.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** | |
Expand Down
1 change: 1 addition & 0 deletions docs/Referral.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Name | Type | Description | Notes
**l1_address** | **str** | |
**referral_code** | **str** | |
**used_at** | **int** | |
**trade_stats** | [**TradeStats**](TradeStats.md) | |

## Example

Expand Down
4 changes: 4 additions & 0 deletions docs/SystemConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions docs/TradeStats.md
Original file line number Diff line number Diff line change
@@ -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)


30 changes: 30 additions & 0 deletions examples/integrator_approve.py
Original file line number Diff line number Diff line change
@@ -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())
34 changes: 34 additions & 0 deletions examples/integrator_create_market_order.py
Original file line number Diff line number Diff line change
@@ -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())
74 changes: 74 additions & 0 deletions examples/integrator_create_modify_order.py
Original file line number Diff line number Diff line change
@@ -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())
30 changes: 30 additions & 0 deletions examples/integrator_revoke.py
Original file line number Diff line number Diff line change
@@ -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())
3 changes: 1 addition & 2 deletions examples/read-only-auth/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions examples/read-only-auth/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 30 additions & 0 deletions examples/stake_and_unstake.py
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 2 additions & 0 deletions lighter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading