@@ -84,125 +84,112 @@ the key stays out of source code):
8484export DATAMAXI_API_KEY=" your_api_key"
8585```
8686
87- ``` python
88- from datamaxi import Datamaxi, Telegram, Naver
87+ === "Sync"
88+
89+ ```python
90+ from datamaxi import Datamaxi, Telegram, Naver
91+
92+ # Clients read DATAMAXI_API_KEY from the environment automatically.
93+ # Alternatively, pass api_key="your_api_key" explicitly to each client.
94+ maxi = Datamaxi()
95+ telegram = Telegram()
96+ naver = Naver()
97+
98+ # Fetch CEX candle data (returns pandas DataFrame)
99+ df = maxi.cex.candle(
100+ exchange="binance",
101+ symbol="BTC-USDT",
102+ interval="1d",
103+ market="spot"
104+ )
105+ print(df.head())
89106
90- # Clients read DATAMAXI_API_KEY from the environment automatically.
91- # Alternatively, pass api_key="your_api_key" explicitly to each client.
92- maxi = Datamaxi()
93- telegram = Telegram()
94- naver = Naver()
107+ # Fetch ticker data
108+ ticker = maxi.cex.ticker.get(
109+ exchange="binance",
110+ symbol="BTC-USDT",
111+ market="spot"
112+ )
113+ print(ticker)
95114
96- # Fetch CEX candle data (returns pandas DataFrame)
97- df = maxi.cex.candle(
98- exchange = " binance" ,
99- symbol = " BTC-USDT" ,
100- interval = " 1d" ,
101- market = " spot"
102- )
103- print (df.head())
115+ # Fetch premium data
116+ premium = maxi.premium(asset="BTC")
117+ print(premium.head())
118+ ```
104119
105- # Fetch ticker data
106- ticker = maxi.cex.ticker.get(
107- exchange = " binance" ,
108- symbol = " BTC-USDT" ,
109- market = " spot"
110- )
111- print (ticker)
120+ === "Async"
112121
113- # Fetch premium data
114- premium = maxi.premium(asset = " BTC" )
115- print (premium.head())
116- ```
122+ ```python
123+ import asyncio
124+ from datamaxi.aio import AsyncDatamaxi
117125
118- ## Async Client
119126
120- For ` asyncio ` applications the SDK ships an async client, ` AsyncDatamaxi ` , built
121- on [ httpx] ( https://www.python-httpx.org/ ) . It mirrors the sync ` Datamaxi `
122- resource tree — the same endpoints and arguments — but every request method is a
123- coroutine and must be ` await ` ed.
127+ async def main():
128+ # Reads DATAMAXI_API_KEY from the environment automatically.
129+ # Alternatively, pass api_key="your_api_key" explicitly.
130+ async with AsyncDatamaxi() as client:
131+ # Fetch CEX candle data (returns pandas DataFrame)
132+ df = await client.cex.candle(
133+ exchange="binance",
134+ symbol="BTC-USDT",
135+ interval="1d",
136+ market="spot",
137+ )
138+ print(df.head())
139+
140+ # Fetch ticker data
141+ ticker = await client.cex.ticker.get(
142+ exchange="binance",
143+ symbol="BTC-USDT",
144+ market="spot",
145+ )
146+ print(ticker)
147+
148+ # Fetch premium data
149+ premium = await client.premium(asset="BTC")
150+ print(premium.head())
151+
124152
125- Install the async extra (pulls in ` httpx ` ):
153+ asyncio.run(main())
154+ ```
155+
156+ ## Async Client
157+
158+ The SDK also ships an async client, ` AsyncDatamaxi ` (built on
159+ [ httpx] ( https://www.python-httpx.org/ ) ). It mirrors the same resource tree and
160+ arguments as ` Datamaxi ` , with one rule: every method is a coroutine and must be
161+ ` await ` ed. Install the async extra:
126162
127163``` shell
128164pip install " datamaxi[async]"
129165```
130166
131- Use it as an async context manager so the underlying HTTP client is closed
132- cleanly (or call ` await client.aclose() ` yourself). The async client reads the
133- same ` DATAMAXI_API_KEY ` environment variable as the sync client:
134-
135167``` python
136168import asyncio
137169from datamaxi.aio import AsyncDatamaxi
138170
139171
140172async def main ():
141- # Reads DATAMAXI_API_KEY from the environment, like the sync client.
142- # Alternatively, pass api_key="your_api_key" explicitly.
173+ # Reads DATAMAXI_API_KEY from the environment, or pass api_key=... explicitly.
143174 async with AsyncDatamaxi() as client:
144- # Fetch CEX candle data (returns pandas DataFrame)
145175 df = await client.cex.candle(
146- exchange = " binance" ,
147- symbol = " BTC-USDT" ,
148- interval = " 1d" ,
149- market = " spot" ,
176+ exchange = " binance" , symbol = " BTC-USDT" , interval = " 1d" , market = " spot"
150177 )
151178 print (df.head())
152179
153- # Fetch ticker data
154- ticker = await client.cex.ticker.get(
155- exchange = " binance" ,
156- symbol = " BTC-USDT" ,
157- market = " spot" ,
158- )
159- print (ticker)
160-
161- # Fetch premium data
162- premium = await client.premium(asset = " BTC" )
163- print (premium.head())
164-
165180
166181asyncio.run(main())
167182```
168183
169- If you do not use ` async with ` , close the client explicitly:
170-
171- ``` python
172- client = AsyncDatamaxi()
173- try :
174- df = await client.cex.candle(
175- exchange = " binance" , symbol = " BTC-USDT" , interval = " 1d" , market = " spot"
176- )
177- finally :
178- await client.aclose()
179- ```
180-
181- Notes on the async client:
184+ Use ` AsyncDatamaxi ` as an async context manager (shown above) or call
185+ ` await client.aclose() ` yourself. Paginated endpoints return an async
186+ ` next_request ` — ` await ` it too
187+ (` data, next_request = await client.cex.announcement(...) ` ). Telegram and Naver
188+ have standalone ` AsyncTelegram ` / ` AsyncNaver ` clients.
182189
183- - Every data method is a coroutine — ` await ` it (e.g. ` await client.cex.candle(...) ` ).
184- - ` AsyncDatamaxi ` mirrors the sync resource tree: ` cex.* ` (candle, ticker, fee,
185- wallet_status, announcement, token, symbol), ` funding_rate ` , ` forex ` ,
186- ` premium ` , ` liquidation ` , ` open_interest ` , ` margin_borrow ` , and ` index_price ` .
187- - Paginated endpoints return an ** async** ` next_request ` callable — ` await ` it too:
188-
189- ``` python
190- data, next_request = await client.cex.announcement(page = 1 , limit = 100 )
191- data2, next_request2 = await next_request()
192- ```
193-
194- - Telegram and Naver have standalone async clients, ` AsyncTelegram ` and
195- ` AsyncNaver ` (also async context managers):
196-
197- ``` python
198- from datamaxi.aio import AsyncTelegram, AsyncNaver
199-
200- async with AsyncTelegram() as telegram:
201- channels, next_request = await telegram.channels(page = 1 , limit = 100 )
202-
203- async with AsyncNaver() as naver:
204- trend = await naver.trend(symbol = " BTC" )
205- ```
190+ Every endpoint in the [ API Reference] ( #api-reference ) works the same under the
191+ async client — see the [ docs] ( https://datamaxi.readthedocs.io/ ) where each
192+ example has a Sync/Async tab.
206193
207194## API Reference
208195
0 commit comments