lnmarkets-sdk 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lnmarkets-sdk might be problematic. Click here for more details.
- lnmarkets_sdk-0.0.2/.github/workflows/check.yml +38 -0
- lnmarkets_sdk-0.0.2/.gitignore +5 -0
- lnmarkets_sdk-0.0.2/.markdownlint.json +10 -0
- lnmarkets_sdk-0.0.2/LICENSE +21 -0
- lnmarkets_sdk-0.0.2/Makefile +35 -0
- lnmarkets_sdk-0.0.2/PKG-INFO +134 -0
- lnmarkets_sdk-0.0.2/README.md +110 -0
- lnmarkets_sdk-0.0.2/codebook.toml +40 -0
- lnmarkets_sdk-0.0.2/examples/basic.py +161 -0
- lnmarkets_sdk-0.0.2/images/lnmarkets-logo.svg +78 -0
- lnmarkets_sdk-0.0.2/pyproject.toml +79 -0
- lnmarkets_sdk-0.0.2/scripts/create-api-key-v3.py +155 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/__init__.py +1 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/_internal/__init__.py +83 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/_internal/models.py +90 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/_internal/utils.py +115 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/__init__.py +129 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/account.py +178 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/futures/__init__.py +65 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/futures/cross.py +153 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/futures/isolated.py +147 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/oracle.py +40 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/client/synthetic_usd.py +48 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/__init__.py +0 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/account.py +203 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/funding_fees.py +30 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/futures_cross.py +119 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/futures_data.py +100 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/futures_isolated.py +142 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/oracle.py +19 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/models/synthetic_usd.py +51 -0
- lnmarkets_sdk-0.0.2/src/lnmarkets_sdk/py.typed +0 -0
- lnmarkets_sdk-0.0.2/uv.lock +528 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Check
|
|
2
|
+
|
|
3
|
+
concurrency:
|
|
4
|
+
group: ${{ github.workflow }}.${{ github.ref }}
|
|
5
|
+
cancel-in-progress: true
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches:
|
|
10
|
+
- main
|
|
11
|
+
pull_request:
|
|
12
|
+
types: [opened, synchronize, reopened]
|
|
13
|
+
workflow_call:
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
check:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: 3.13
|
|
24
|
+
|
|
25
|
+
- name: Install uv
|
|
26
|
+
uses: astral-sh/setup-uv@v4
|
|
27
|
+
with:
|
|
28
|
+
version: "latest"
|
|
29
|
+
enable-cache: true
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: uv sync --all-groups
|
|
33
|
+
|
|
34
|
+
- name: Run linter (ruff)
|
|
35
|
+
run: uv run ruff check .
|
|
36
|
+
|
|
37
|
+
- name: Run type checker (pyright)
|
|
38
|
+
run: uv run pyright
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LN Markets
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.PHONY: help install install-browsers create-api-key example lint format typecheck test check
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available commands:"
|
|
5
|
+
@echo " make install - Install dependencies"
|
|
6
|
+
@echo " make install-browsers - Install Playwright browsers"
|
|
7
|
+
@echo " make create-api-key - Create API key for v3"
|
|
8
|
+
@echo " make example - Run basic example"
|
|
9
|
+
@echo " make lint - Run linter (ruff check)"
|
|
10
|
+
@echo " make format - Format code (ruff format)"
|
|
11
|
+
@echo " make typecheck - Run type checker (pyright)"
|
|
12
|
+
@echo " make check - Run all checks (lint, typecheck)"
|
|
13
|
+
|
|
14
|
+
install:
|
|
15
|
+
uv sync --all-groups
|
|
16
|
+
|
|
17
|
+
install-browsers:
|
|
18
|
+
uv run playwright install chromium
|
|
19
|
+
|
|
20
|
+
create-api-key: install-browsers
|
|
21
|
+
uv run python scripts/create-api-key-v3.py
|
|
22
|
+
|
|
23
|
+
example:
|
|
24
|
+
uv run python examples/basic.py
|
|
25
|
+
|
|
26
|
+
lint:
|
|
27
|
+
uv run ruff check .
|
|
28
|
+
|
|
29
|
+
format:
|
|
30
|
+
uv run ruff format .
|
|
31
|
+
|
|
32
|
+
typecheck:
|
|
33
|
+
uv run pyright
|
|
34
|
+
|
|
35
|
+
check: lint typecheck
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lnmarkets-sdk
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: LN Markets API Python SDK
|
|
5
|
+
Project-URL: Homepage, https://github.com/ln-markets/sdk-python
|
|
6
|
+
Project-URL: Repository, https://github.com/ln-markets/sdk-python
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/ln-markets/sdk-python/issues
|
|
8
|
+
Author-email: K <kha.nguyen@ito.am>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,bitcoin,futures,lightning,lnmarkets,network,options,rest,trading
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: httpx>=0.28.1
|
|
21
|
+
Requires-Dist: pydantic>=2.12.2
|
|
22
|
+
Requires-Dist: requests>=2.32.3
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# LN Markets SDK v3
|
|
26
|
+
|
|
27
|
+
This is the Python version of the LN Markets API SDK. It provides a client-based interface for interacting with the LN Markets API.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
For public endpoints, you can just do this:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from lnmarkets_sdk.client import LNMClient
|
|
35
|
+
import asyncio
|
|
36
|
+
|
|
37
|
+
async with LNMClient() as client:
|
|
38
|
+
ticker = await client.futures.get_ticker()
|
|
39
|
+
await asyncio.sleep(1)
|
|
40
|
+
leaderboard = await client.futures.get_leaderboard()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Remember to sleep between requests, as the rate limit is 1 requests per second for public endpoints.
|
|
44
|
+
|
|
45
|
+
For endpoints that need authentication, you need to create an instance of the `LNMClient` class and provide your API credentials:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from lnmarkets_sdk.client import APIAuthContext, APIClientConfig, LNMClient
|
|
49
|
+
|
|
50
|
+
config = APIClientConfig(
|
|
51
|
+
authentication=APIAuthContext(
|
|
52
|
+
key=your_key,
|
|
53
|
+
secret=your_secret,
|
|
54
|
+
passphrase=your_passphrase,
|
|
55
|
+
),
|
|
56
|
+
network="mainnet",
|
|
57
|
+
timeout=60.0, # 60 second timeout (default is 30s)
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
async with LNMClient(config) as client:
|
|
61
|
+
account = await client.account.get_account()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
or let playwright create it for you by typing the following command in your terminal at the project root
|
|
65
|
+
(assuming you have `make` installed on your machine):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
make create-api-key
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This will create a new API key for you and write it to the `.env` file at the project root.
|
|
72
|
+
|
|
73
|
+
```txt
|
|
74
|
+
# LN Markets API V3 Credentials
|
|
75
|
+
LNM_API_KEY_V3=<your_api_key>
|
|
76
|
+
LNM_API_SECRET_V3=<your_api_secret>
|
|
77
|
+
LNM_API_PASSPHRASE_V3=<your_api_passphrase>
|
|
78
|
+
LNM_API_NAME_V3=<your_api_keyname>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
After that, you can use the client to make API requests to the LN Markets API:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
async with LNMClient(config) as client:
|
|
85
|
+
account = await client.account.get_account()
|
|
86
|
+
btc_address = await client.account.get_bitcoin_address()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
For endpoints that requires input parameters, you can find the corresponding models in the `lnmarkets_sdk.models` module.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
|
|
93
|
+
from lnmarkets_sdk.client import APIAuthContext, APIClientConfig, LNMClient
|
|
94
|
+
from lnmarkets_sdk.models.account import GetLightningDepositsParams
|
|
95
|
+
|
|
96
|
+
config = APIClientConfig(
|
|
97
|
+
authentication=APIAuthContext(
|
|
98
|
+
key=your_key,
|
|
99
|
+
secret=your_secret,
|
|
100
|
+
passphrase=your_passphrase,
|
|
101
|
+
),
|
|
102
|
+
network="mainnet",
|
|
103
|
+
timeout=60.0, # 60 second timeout (default is 30s)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
async with LNMClient(config) as client:
|
|
107
|
+
deposits = await client.account.get_lightning_deposits(
|
|
108
|
+
GetLightningDepositsParams(limit=5)
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Check our [example](./examples/basic.py) for more details.
|
|
113
|
+
|
|
114
|
+
## API Reference
|
|
115
|
+
|
|
116
|
+
For full API documentation, see: [LNM API Documentation](https://docs.lnmarkets.com/)
|
|
117
|
+
|
|
118
|
+
## Examples
|
|
119
|
+
|
|
120
|
+
Run:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
make example
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
after you generated your API key using `make create-api-key` or setup `.env` file yourself.
|
|
127
|
+
|
|
128
|
+
## Contributing
|
|
129
|
+
|
|
130
|
+
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# LN Markets SDK v3
|
|
2
|
+
|
|
3
|
+
This is the Python version of the LN Markets API SDK. It provides a client-based interface for interacting with the LN Markets API.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
For public endpoints, you can just do this:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from lnmarkets_sdk.client import LNMClient
|
|
11
|
+
import asyncio
|
|
12
|
+
|
|
13
|
+
async with LNMClient() as client:
|
|
14
|
+
ticker = await client.futures.get_ticker()
|
|
15
|
+
await asyncio.sleep(1)
|
|
16
|
+
leaderboard = await client.futures.get_leaderboard()
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Remember to sleep between requests, as the rate limit is 1 requests per second for public endpoints.
|
|
20
|
+
|
|
21
|
+
For endpoints that need authentication, you need to create an instance of the `LNMClient` class and provide your API credentials:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from lnmarkets_sdk.client import APIAuthContext, APIClientConfig, LNMClient
|
|
25
|
+
|
|
26
|
+
config = APIClientConfig(
|
|
27
|
+
authentication=APIAuthContext(
|
|
28
|
+
key=your_key,
|
|
29
|
+
secret=your_secret,
|
|
30
|
+
passphrase=your_passphrase,
|
|
31
|
+
),
|
|
32
|
+
network="mainnet",
|
|
33
|
+
timeout=60.0, # 60 second timeout (default is 30s)
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
async with LNMClient(config) as client:
|
|
37
|
+
account = await client.account.get_account()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
or let playwright create it for you by typing the following command in your terminal at the project root
|
|
41
|
+
(assuming you have `make` installed on your machine):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
make create-api-key
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This will create a new API key for you and write it to the `.env` file at the project root.
|
|
48
|
+
|
|
49
|
+
```txt
|
|
50
|
+
# LN Markets API V3 Credentials
|
|
51
|
+
LNM_API_KEY_V3=<your_api_key>
|
|
52
|
+
LNM_API_SECRET_V3=<your_api_secret>
|
|
53
|
+
LNM_API_PASSPHRASE_V3=<your_api_passphrase>
|
|
54
|
+
LNM_API_NAME_V3=<your_api_keyname>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
After that, you can use the client to make API requests to the LN Markets API:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
async with LNMClient(config) as client:
|
|
61
|
+
account = await client.account.get_account()
|
|
62
|
+
btc_address = await client.account.get_bitcoin_address()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For endpoints that requires input parameters, you can find the corresponding models in the `lnmarkets_sdk.models` module.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
|
|
69
|
+
from lnmarkets_sdk.client import APIAuthContext, APIClientConfig, LNMClient
|
|
70
|
+
from lnmarkets_sdk.models.account import GetLightningDepositsParams
|
|
71
|
+
|
|
72
|
+
config = APIClientConfig(
|
|
73
|
+
authentication=APIAuthContext(
|
|
74
|
+
key=your_key,
|
|
75
|
+
secret=your_secret,
|
|
76
|
+
passphrase=your_passphrase,
|
|
77
|
+
),
|
|
78
|
+
network="mainnet",
|
|
79
|
+
timeout=60.0, # 60 second timeout (default is 30s)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
async with LNMClient(config) as client:
|
|
83
|
+
deposits = await client.account.get_lightning_deposits(
|
|
84
|
+
GetLightningDepositsParams(limit=5)
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Check our [example](./examples/basic.py) for more details.
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
For full API documentation, see: [LNM API Documentation](https://docs.lnmarkets.com/)
|
|
93
|
+
|
|
94
|
+
## Examples
|
|
95
|
+
|
|
96
|
+
Run:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
make example
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
after you generated your API key using `make create-api-key` or setup `.env` file yourself.
|
|
103
|
+
|
|
104
|
+
## Contributing
|
|
105
|
+
|
|
106
|
+
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
dictionaries = ["en_gb", "en_us"]
|
|
2
|
+
|
|
3
|
+
words = [
|
|
4
|
+
"cashin",
|
|
5
|
+
"dotenv",
|
|
6
|
+
"linkingpublickey",
|
|
7
|
+
"lnmarkets",
|
|
8
|
+
"lnurl",
|
|
9
|
+
"nostr",
|
|
10
|
+
"ohlcs",
|
|
11
|
+
"pipreqs",
|
|
12
|
+
"snok",
|
|
13
|
+
"stoploss",
|
|
14
|
+
"takeprofit",
|
|
15
|
+
"topt",
|
|
16
|
+
"Totp",
|
|
17
|
+
"webauthn",
|
|
18
|
+
"APIHTTP",
|
|
19
|
+
"pyproject",
|
|
20
|
+
"httpx",
|
|
21
|
+
"leaderboard",
|
|
22
|
+
"sublicense",
|
|
23
|
+
"noninfringement",
|
|
24
|
+
"LNM",
|
|
25
|
+
"anypassword",
|
|
26
|
+
"aenter",
|
|
27
|
+
"aexit",
|
|
28
|
+
"urlencode",
|
|
29
|
+
"pydantic",
|
|
30
|
+
"mainnet",
|
|
31
|
+
"hmac",
|
|
32
|
+
"ohlc",
|
|
33
|
+
"wpkh",
|
|
34
|
+
"satoshis",
|
|
35
|
+
"sats",
|
|
36
|
+
"btc",
|
|
37
|
+
"asyncio",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
ignore_paths = [".venv/**/*", "**/.gitignore", "**/pyproject.toml", "*.svg", "**/*.lock"]
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example usage of the v3 client-based API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
from pprint import pprint
|
|
8
|
+
|
|
9
|
+
from dotenv import load_dotenv
|
|
10
|
+
|
|
11
|
+
from lnmarkets_sdk.client import APIAuthContext, APIClientConfig, LNMClient
|
|
12
|
+
from lnmarkets_sdk.models.account import GetLightningDepositsParams
|
|
13
|
+
from lnmarkets_sdk.models.futures_cross import (
|
|
14
|
+
FuturesCrossOrderLimit,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
load_dotenv()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def example_public_endpoints():
|
|
21
|
+
"""Example: Make public requests without authentication."""
|
|
22
|
+
print("\n" + "=" * 80)
|
|
23
|
+
print("PUBLIC ENDPOINTS EXAMPLE")
|
|
24
|
+
print("=" * 80)
|
|
25
|
+
|
|
26
|
+
# Create client without authentication for public endpoints
|
|
27
|
+
# The httpx.AsyncClient is created once and reuses connections
|
|
28
|
+
async with LNMClient() as client:
|
|
29
|
+
# All these requests share the same connection pool
|
|
30
|
+
print("\n🔄 Making multiple requests with connection reuse...")
|
|
31
|
+
|
|
32
|
+
# Get futures ticker
|
|
33
|
+
ticker = await client.futures.get_ticker()
|
|
34
|
+
print("\n--- Futures Ticker ---")
|
|
35
|
+
pprint(ticker.model_dump(), indent=2, width=100)
|
|
36
|
+
|
|
37
|
+
# Get leaderboard
|
|
38
|
+
await asyncio.sleep(1)
|
|
39
|
+
leaderboard = await client.futures.get_leaderboard()
|
|
40
|
+
print("\n--- Leaderboard (Top 3 Daily) ---")
|
|
41
|
+
pprint(leaderboard.daily[:3], indent=2, width=100)
|
|
42
|
+
|
|
43
|
+
# Get oracle data
|
|
44
|
+
await asyncio.sleep(1)
|
|
45
|
+
oracle_index = await client.oracle.get_index()
|
|
46
|
+
print("\n--- Oracle Index (Latest) ---")
|
|
47
|
+
pprint(oracle_index[0].model_dump() if oracle_index else "No data", indent=2)
|
|
48
|
+
|
|
49
|
+
# Get synthetic USD best price
|
|
50
|
+
await asyncio.sleep(1)
|
|
51
|
+
best_price = await client.synthetic_usd.get_best_price()
|
|
52
|
+
print("\n--- Synthetic USD Best Price ---")
|
|
53
|
+
pprint(best_price.model_dump(), indent=2)
|
|
54
|
+
|
|
55
|
+
# Ping the API
|
|
56
|
+
await asyncio.sleep(1)
|
|
57
|
+
ping_response = await client.ping()
|
|
58
|
+
print("\n--- Ping ---")
|
|
59
|
+
print(f"Response: {ping_response}")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
async def example_authenticated_endpoints():
|
|
63
|
+
"""Example: Use authenticated endpoints with credentials."""
|
|
64
|
+
print("\n" + "=" * 80)
|
|
65
|
+
print("AUTHENTICATED ENDPOINTS EXAMPLE")
|
|
66
|
+
print("=" * 80)
|
|
67
|
+
|
|
68
|
+
key = os.getenv("LNM_API_KEY_V3")
|
|
69
|
+
secret = os.getenv("LNM_API_SECRET_V3")
|
|
70
|
+
passphrase = os.getenv("LNM_API_PASSPHRASE_V3")
|
|
71
|
+
|
|
72
|
+
if not (key and secret and passphrase):
|
|
73
|
+
print("\n⚠️ Skipping authenticated example:")
|
|
74
|
+
print(
|
|
75
|
+
" Please set LNM_API_KEY_V3, LNM_API_SECRET_V3, and LNM_API_PASSPHRASE_V3"
|
|
76
|
+
)
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
# Create config with authentication and custom timeout
|
|
80
|
+
config = APIClientConfig(
|
|
81
|
+
authentication=APIAuthContext(
|
|
82
|
+
key=key,
|
|
83
|
+
secret=secret,
|
|
84
|
+
passphrase=passphrase,
|
|
85
|
+
),
|
|
86
|
+
network="mainnet",
|
|
87
|
+
timeout=60.0, # 60 second timeout (default is 30s)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
async with LNMClient(config) as client:
|
|
91
|
+
print("\n🔐 Using authenticated endpoints with connection pooling...")
|
|
92
|
+
|
|
93
|
+
# Get account info
|
|
94
|
+
account = await client.account.get_account()
|
|
95
|
+
print("\n--- Account Info ---")
|
|
96
|
+
print(f"Username: {account.username}")
|
|
97
|
+
print(f"Balance: {account.balance} sats")
|
|
98
|
+
print(f"Synthetic USD Balance: {account.synthetic_usd_balance}")
|
|
99
|
+
|
|
100
|
+
# Get Bitcoin address
|
|
101
|
+
btc_address = await client.account.get_bitcoin_address()
|
|
102
|
+
print("\n--- Bitcoin Deposit Address ---")
|
|
103
|
+
print(f"Address: {btc_address.address}")
|
|
104
|
+
|
|
105
|
+
# Get lightning deposits (last 5)
|
|
106
|
+
deposits = await client.account.get_lightning_deposits(
|
|
107
|
+
GetLightningDepositsParams(limit=5)
|
|
108
|
+
)
|
|
109
|
+
print(f"\n--- Recent Lightning Deposits (Last {len(deposits)}) ---")
|
|
110
|
+
for deposit in deposits:
|
|
111
|
+
print(f"Deposits {deposit.amount} sats at {deposit.created_at}")
|
|
112
|
+
|
|
113
|
+
# Get running trades
|
|
114
|
+
running_trades = await client.futures.isolated.get_running_trades()
|
|
115
|
+
print("\n--- Running Isolated Trades ---")
|
|
116
|
+
print(f"Count: {len(running_trades)}")
|
|
117
|
+
for trade in running_trades[:3]: # Show first 3
|
|
118
|
+
side = "LONG" if trade.side == "b" else "SHORT"
|
|
119
|
+
print(
|
|
120
|
+
f" {side} - Margin: {trade.margin} sats, Leverage: {trade.leverage}x, PL: {trade.pl} sats"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Get cross margin position
|
|
124
|
+
try:
|
|
125
|
+
position = await client.futures.cross.get_position()
|
|
126
|
+
print("\n--- Cross Margin Position ---")
|
|
127
|
+
print(f"Quantity: {position.quantity}")
|
|
128
|
+
print(f"Margin: {position.margin} sats")
|
|
129
|
+
print(f"Leverage: {position.leverage}x")
|
|
130
|
+
print(f"Total PL: {position.total_pl} sats")
|
|
131
|
+
except Exception as e:
|
|
132
|
+
print(f"Error: {e}")
|
|
133
|
+
|
|
134
|
+
# Open a new cross order
|
|
135
|
+
try:
|
|
136
|
+
print("\n--- Try to open a new cross order ---")
|
|
137
|
+
order_params = FuturesCrossOrderLimit(
|
|
138
|
+
type="limit", price=1.5, quantity=1, side="b"
|
|
139
|
+
)
|
|
140
|
+
new_order = await client.futures.cross.new_order(order_params)
|
|
141
|
+
print(f"New order: {new_order}")
|
|
142
|
+
except Exception as e:
|
|
143
|
+
print(f"Error: {e}")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def main():
|
|
147
|
+
"""Run all examples."""
|
|
148
|
+
print("\n" + "=" * 80)
|
|
149
|
+
print("LN MARKETS V3 CLIENT EXAMPLES")
|
|
150
|
+
print("=" * 80)
|
|
151
|
+
|
|
152
|
+
await example_public_endpoints()
|
|
153
|
+
await example_authenticated_endpoints()
|
|
154
|
+
|
|
155
|
+
print("\n" + "=" * 80)
|
|
156
|
+
print("EXAMPLES COMPLETE")
|
|
157
|
+
print("=" * 80 + "\n")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 28.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
4
|
+
viewBox="0 0 834.95 524.49" style="enable-background:new 0 0 834.95 524.49;" xml:space="preserve">
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
.st0{fill:#040011;}
|
|
7
|
+
.st1{fill:url(#SVGID_1_);}
|
|
8
|
+
.st2{fill:url(#SVGID_00000110446039568506646120000001643367989759818416_);}
|
|
9
|
+
.st3{fill:url(#SVGID_00000023979049476404522830000012242605696985444007_);}
|
|
10
|
+
.st4{fill:url(#SVGID_00000064322976733589025650000010215505666724282253_);}
|
|
11
|
+
.st5{fill:#E0E0E0;}
|
|
12
|
+
.st6{fill:url(#SVGID_00000059988898615944267150000017389142962728270521_);}
|
|
13
|
+
.st7{fill:url(#SVGID_00000117635160774013861670000002067002023121378722_);}
|
|
14
|
+
.st8{fill:url(#SVGID_00000158023115511523045840000010979365560953067395_);}
|
|
15
|
+
.st9{fill:url(#SVGID_00000027562514682485879320000010493469229589947799_);}
|
|
16
|
+
.st10{fill:url(#SVGID_00000148621228696321241060000016388942881879528867_);}
|
|
17
|
+
.st11{fill:url(#SVGID_00000119831743111776908580000005565317632388959375_);}
|
|
18
|
+
.st12{fill:url(#SVGID_00000177456917720906333180000013872287374596400775_);}
|
|
19
|
+
.st13{fill:url(#SVGID_00000159468776568146761380000008468609324671026353_);}
|
|
20
|
+
</style>
|
|
21
|
+
<g>
|
|
22
|
+
<g>
|
|
23
|
+
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="438.5886" y1="227.2814" x2="536.5365" y2="227.2814">
|
|
24
|
+
<stop offset="0" style="stop-color:#00D2D1"/>
|
|
25
|
+
<stop offset="1" style="stop-color:#2E80FF"/>
|
|
26
|
+
</linearGradient>
|
|
27
|
+
<path class="st1" d="M534.18,192.75c-8.68-10.88-17.53-20.42-26.64-30.93c-1.61-1.86-4.54-3.33-7.18-3.38
|
|
28
|
+
c-9.34-0.16-18.7-0.19-28.06-0.18c-1.83,0-3.39,1.3-3.73,3.09c-1.24,6.68-4.08,21.86-4.13,21.93l-0.07,0.41h44.23
|
|
29
|
+
c2.36,0,4.14,2.13,3.73,4.45l-18.29,103.73c-0.41,2.32,1.38,4.45,3.73,4.45l18.64,0c1.78,0,3.36-1.23,3.68-2.98
|
|
30
|
+
c0-0.01,0-0.02,0-0.02c5.52-31.14,11.09-62.28,16.36-93.41C536.87,197.48,535.65,194.59,534.18,192.75z"/>
|
|
31
|
+
|
|
32
|
+
<linearGradient id="SVGID_00000120552342442594988440000000426545412774743967_" gradientUnits="userSpaceOnUse" x1="419.1977" y1="240.0543" x2="464.7397" y2="240.0543">
|
|
33
|
+
<stop offset="0" style="stop-color:#00D2D1"/>
|
|
34
|
+
<stop offset="1" style="stop-color:#2E80FF"/>
|
|
35
|
+
</linearGradient>
|
|
36
|
+
<path style="fill:url(#SVGID_00000120552342442594988440000000426545412774743967_);" d="M437.81,186.78l-18.55,105.23
|
|
37
|
+
c-0.41,2.32,1.38,4.45,3.73,4.45h18.32c1.84,0,3.41-1.32,3.73-3.13l19.33-109.64l-22.82-0.04
|
|
38
|
+
C439.71,183.65,438.13,184.97,437.81,186.78z"/>
|
|
39
|
+
</g>
|
|
40
|
+
|
|
41
|
+
<linearGradient id="SVGID_00000016050477436791547170000017161762434926942345_" gradientUnits="userSpaceOnUse" x1="298.4119" y1="227.4026" x2="403.9907" y2="227.4026">
|
|
42
|
+
<stop offset="0" style="stop-color:#00D2D1"/>
|
|
43
|
+
<stop offset="1" style="stop-color:#2E80FF"/>
|
|
44
|
+
</linearGradient>
|
|
45
|
+
<path style="fill:url(#SVGID_00000016050477436791547170000017161762434926942345_);" d="M320.21,158.35h20
|
|
46
|
+
c2.36,0,4.14,2.13,3.73,4.45l-20.58,116.72c-0.41,2.32,1.38,4.45,3.73,4.45h1.83c0.42,0,0.84-0.07,1.23-0.21l48.59-16.72
|
|
47
|
+
c0.78-0.27,1.59-0.4,2.42-0.4h19.02c2.36,0,4.14,2.13,3.73,4.45l-3.92,22.24c-0.32,1.81-1.89,3.13-3.73,3.13h-73.56
|
|
48
|
+
c-1.19,0-2.31-0.56-3.03-1.51l-20.52-27.18c-0.63-0.84-0.89-1.9-0.71-2.94l18.01-103.36C316.79,159.67,318.37,158.35,320.21,158.35
|
|
49
|
+
z"/>
|
|
50
|
+
</g>
|
|
51
|
+
<g>
|
|
52
|
+
<polygon class="st5" points="243.91,350.25 243.03,350.25 236.46,333.38 225.16,333.38 225.16,365.36 232.61,365.36 232.61,341.56
|
|
53
|
+
239.53,358.92 246.93,358.92 253.9,341.36 253.9,365.36 261.96,365.36 261.96,333.38 250.44,333.38 "/>
|
|
54
|
+
<path class="st5" d="M302.96,333.38l-10.25,31.98h8.15l2.26-7.4h12.77l2.32,7.4h8.41l-10.6-31.98H302.96z M305.15,351.3l3.46-11.35
|
|
55
|
+
h1.64l3.56,11.35H305.15z"/>
|
|
56
|
+
<path class="st5" d="M382.45,350.75c1.1-1.59,1.64-3.58,1.64-5.98v-0.7c0-2.39-0.54-4.4-1.62-6.02c-1.08-1.62-2.63-2.85-4.64-3.68
|
|
57
|
+
c-2.02-0.83-4.41-1.25-7.18-1.25h-5.13h-2.06h-6.09v32.24h8.15v-9.81h4.64l6.49,9.81h9.37l-7.84-11.2
|
|
58
|
+
C379.99,353.36,381.43,352.24,382.45,350.75z M365.52,339.95h5.61c0.96,0,1.8,0.19,2.5,0.57c0.7,0.38,1.25,0.92,1.64,1.62
|
|
59
|
+
c0.39,0.7,0.59,1.53,0.59,2.5c0,0.94-0.2,1.75-0.59,2.45c-0.39,0.7-0.94,1.24-1.64,1.62c-0.7,0.38-1.53,0.57-2.5,0.57h-5.61V339.95
|
|
60
|
+
z"/>
|
|
61
|
+
<polygon class="st5" points="445.82,333.38 436.44,333.38 425.1,348.34 425.1,333.38 416.95,333.38 416.95,365.36 425.1,365.36
|
|
62
|
+
425.1,350.42 427.86,350.42 438.24,365.36 448.05,365.36 435.38,347.14 "/>
|
|
63
|
+
<polygon class="st5" points="486.03,352.44 497.73,352.44 497.73,345.78 486.03,345.78 486.03,340.04 498.39,340.04 498.39,333.38
|
|
64
|
+
486.03,333.38 485.16,333.38 478.15,333.38 478.15,365.36 485.16,365.36 486.03,365.36 498.65,365.36 498.65,358.7 486.03,358.7
|
|
65
|
+
"/>
|
|
66
|
+
<polygon class="st5" points="528.88,340.48 537.64,340.48 537.64,365.36 545.79,365.36 545.79,340.48 554.55,340.48 554.55,333.38
|
|
67
|
+
528.88,333.38 "/>
|
|
68
|
+
<path class="st5" d="M608.21,350.68c-1.05-1.43-2.5-2.56-4.34-3.4c-1.84-0.83-3.96-1.35-6.35-1.55l-2.06-0.18
|
|
69
|
+
c-1.37-0.12-2.34-0.47-2.89-1.05c-0.56-0.58-0.83-1.29-0.83-2.1c0-0.61,0.15-1.17,0.46-1.67c0.31-0.5,0.76-0.88,1.36-1.16
|
|
70
|
+
c0.6-0.28,1.34-0.42,2.21-0.42c0.93,0,1.73,0.17,2.39,0.5s1.16,0.8,1.51,1.38s0.53,1.23,0.53,1.93h7.89c0-2.1-0.48-3.95-1.45-5.54
|
|
71
|
+
c-0.96-1.59-2.36-2.83-4.18-3.7c-1.83-0.88-4.05-1.31-6.68-1.31c-2.42,0-4.53,0.39-6.31,1.18c-1.78,0.79-3.16,1.93-4.14,3.42
|
|
72
|
+
s-1.47,3.29-1.47,5.39c0,2.95,0.98,5.32,2.93,7.1c1.96,1.78,4.58,2.82,7.89,3.11l2.06,0.17c1.87,0.15,3.2,0.48,3.99,0.99
|
|
73
|
+
c0.79,0.51,1.18,1.23,1.18,2.17c0,0.73-0.21,1.36-0.64,1.88c-0.42,0.53-1.04,0.93-1.84,1.23c-0.8,0.29-1.77,0.44-2.91,0.44
|
|
74
|
+
c-1.31,0-2.4-0.18-3.24-0.53s-1.48-0.84-1.91-1.47c-0.42-0.63-0.63-1.32-0.63-2.08h-7.89c0,2.1,0.52,3.96,1.55,5.58
|
|
75
|
+
c1.04,1.62,2.57,2.9,4.6,3.83c2.03,0.93,4.53,1.4,7.51,1.4c2.77,0,5.15-0.42,7.12-1.27c1.97-0.85,3.49-2.04,4.56-3.59
|
|
76
|
+
c1.07-1.55,1.6-3.36,1.6-5.43C609.79,353.87,609.26,352.12,608.21,350.68z"/>
|
|
77
|
+
</g>
|
|
78
|
+
</svg>
|