realmarketapi-python-sdk-beta 0.1.0b1__py3-none-any.whl
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.
- realmarketapi_python_sdk_beta-0.1.0b1.dist-info/METADATA +252 -0
- realmarketapi_python_sdk_beta-0.1.0b1.dist-info/RECORD +8 -0
- realmarketapi_python_sdk_beta-0.1.0b1.dist-info/WHEEL +5 -0
- realmarketapi_python_sdk_beta-0.1.0b1.dist-info/licenses/LICENSE +21 -0
- realmarketapi_python_sdk_beta-0.1.0b1.dist-info/top_level.txt +1 -0
- realmarketapi_sdk/__init__.py +4 -0
- realmarketapi_sdk/client.py +65 -0
- realmarketapi_sdk/websocket.py +45 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: realmarketapi-python-sdk-beta
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: RealMarketAPI Python SDK beta
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: httpx>=0.27.0
|
|
9
|
+
Requires-Dist: websockets>=12.0
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# RealMarketAPI Python SDK (Beta)
|
|
13
|
+
|
|
14
|
+
Official beta Python SDK for RealMarketAPI REST and WebSocket market data endpoints.
|
|
15
|
+
|
|
16
|
+
Website: [https://realmarketapi.com/](https://realmarketapi.com/)
|
|
17
|
+
|
|
18
|
+
## Why use this SDK
|
|
19
|
+
|
|
20
|
+
- Thin Python wrapper for RealMarketAPI HTTP and streaming APIs.
|
|
21
|
+
- Simple class-based client for request/response usage.
|
|
22
|
+
- Async WebSocket streams with automatic reconnect behavior.
|
|
23
|
+
- Small dependency footprint (`httpx`, `websockets`).
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Python 3.9+
|
|
28
|
+
- RealMarketAPI API key
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install realmarketapi-python-sdk-beta
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
### REST client
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from realmarketapi_sdk import RealMarketApiClient
|
|
42
|
+
|
|
43
|
+
client = RealMarketApiClient(api_key="YOUR_API_KEY")
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
price = client.get_price("EURUSD", "M1")
|
|
47
|
+
print("Close:", price.get("closePrice"))
|
|
48
|
+
finally:
|
|
49
|
+
client.close()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### WebSocket client
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import asyncio
|
|
56
|
+
from realmarketapi_sdk import RealMarketApiWebSocket
|
|
57
|
+
|
|
58
|
+
ws = RealMarketApiWebSocket(api_key="YOUR_API_KEY")
|
|
59
|
+
|
|
60
|
+
async def main() -> None:
|
|
61
|
+
async for tick in ws.stream_price("BTCUSDT", "M1"):
|
|
62
|
+
print(tick)
|
|
63
|
+
|
|
64
|
+
asyncio.run(main())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## REST API methods
|
|
68
|
+
|
|
69
|
+
All REST methods return a Python `dict` parsed from JSON and include your API key as query parameter.
|
|
70
|
+
|
|
71
|
+
### `get_price(symbol_code, time_frame)`
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
price = client.get_price("EURUSD", "M1")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Example response payload:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"symbolCode": "EURUSD",
|
|
84
|
+
"timeFrame": "M1",
|
|
85
|
+
"openPrice": 1.07874,
|
|
86
|
+
"highPrice": 1.07882,
|
|
87
|
+
"lowPrice": 1.07868,
|
|
88
|
+
"closePrice": 1.07879,
|
|
89
|
+
"openTime": "2026-05-21T09:12:00Z"
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `get_candles(symbol_code, time_frame)`
|
|
94
|
+
|
|
95
|
+
Example:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
candles = client.get_candles("BTCUSDT", "M5")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Example response payload:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"symbolCode": "BTCUSDT",
|
|
106
|
+
"timeFrame": "M5",
|
|
107
|
+
"candles": [
|
|
108
|
+
{
|
|
109
|
+
"openTime": "2026-05-21T09:10:00Z",
|
|
110
|
+
"openPrice": 68620.3,
|
|
111
|
+
"highPrice": 68690.1,
|
|
112
|
+
"lowPrice": 68588.7,
|
|
113
|
+
"closePrice": 68655.8,
|
|
114
|
+
"volume": 128.42
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### `get_history(symbol_code, start_time, end_time, page_number=1, page_size=20)`
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
history = client.get_history(
|
|
126
|
+
symbol_code="EURUSD",
|
|
127
|
+
start_time="2026-05-20T00:00:00Z",
|
|
128
|
+
end_time="2026-05-21T00:00:00Z",
|
|
129
|
+
page_number=1,
|
|
130
|
+
page_size=20,
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Example response payload:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"pageNumber": 1,
|
|
139
|
+
"pageSize": 20,
|
|
140
|
+
"totalPages": 14,
|
|
141
|
+
"items": [
|
|
142
|
+
{
|
|
143
|
+
"openTime": "2026-05-20T00:00:00Z",
|
|
144
|
+
"openPrice": 1.07913,
|
|
145
|
+
"highPrice": 1.07942,
|
|
146
|
+
"lowPrice": 1.07898,
|
|
147
|
+
"closePrice": 1.07920,
|
|
148
|
+
"volume": 241.11
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### `get_symbols()`
|
|
155
|
+
|
|
156
|
+
Example:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
symbols = client.get_symbols()
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Example response payload:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"symbols": ["EURUSD", "BTCUSDT", "XAUUSD"]
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### `get_sma(symbol_code, time_frame, period=20)`
|
|
171
|
+
|
|
172
|
+
Example:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
sma = client.get_sma("EURUSD", "M15", period=50)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Example response payload:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"symbolCode": "EURUSD",
|
|
183
|
+
"timeFrame": "M15",
|
|
184
|
+
"period": 50,
|
|
185
|
+
"value": 1.08024,
|
|
186
|
+
"openTime": "2026-05-21T09:00:00Z"
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## WebSocket streaming methods
|
|
191
|
+
|
|
192
|
+
The WebSocket client exposes async generators and reconnects after transient failures.
|
|
193
|
+
|
|
194
|
+
### `stream_price(symbol_code, time_frame)`
|
|
195
|
+
|
|
196
|
+
Example:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
async for event in ws.stream_price("EURUSD", "M1"):
|
|
200
|
+
print(event)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Example message payload:
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"symbolCode": "EURUSD",
|
|
208
|
+
"timeFrame": "M1",
|
|
209
|
+
"closePrice": 1.07879,
|
|
210
|
+
"openTime": "2026-05-21T09:12:00Z"
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### `stream_candles(symbol_code, time_frame)`
|
|
215
|
+
|
|
216
|
+
Example:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
async for event in ws.stream_candles("BTCUSDT", "M5"):
|
|
220
|
+
print(event)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Example message payload:
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"symbolCode": "BTCUSDT",
|
|
228
|
+
"timeFrame": "M5",
|
|
229
|
+
"openTime": "2026-05-21T09:10:00Z",
|
|
230
|
+
"openPrice": 68620.3,
|
|
231
|
+
"highPrice": 68690.1,
|
|
232
|
+
"lowPrice": 68588.7,
|
|
233
|
+
"closePrice": 68655.8,
|
|
234
|
+
"volume": 128.42
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Error handling notes
|
|
239
|
+
|
|
240
|
+
- REST methods call `response.raise_for_status()`, so HTTP 4xx/5xx responses raise `httpx.HTTPStatusError`.
|
|
241
|
+
- WebSocket streams retry on connection errors using `reconnect_delay_seconds` (default `2.0`).
|
|
242
|
+
- Cancel the async task to stop streaming cleanly.
|
|
243
|
+
|
|
244
|
+
## Beta scope and compatibility
|
|
245
|
+
|
|
246
|
+
- Current REST coverage: price, candles, history, symbols, SMA.
|
|
247
|
+
- Current WebSocket coverage: price and candles.
|
|
248
|
+
- This package is beta and may receive additive changes before stable `1.0`.
|
|
249
|
+
|
|
250
|
+
## Links
|
|
251
|
+
|
|
252
|
+
- RealMarketAPI homepage: [https://realmarketapi.com/](https://realmarketapi.com/)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
realmarketapi_python_sdk_beta-0.1.0b1.dist-info/licenses/LICENSE,sha256=KqvwnGv5kvNYivAin7-hQgB6zKVjxHrUYgeKguwh8ro,1067
|
|
2
|
+
realmarketapi_sdk/__init__.py,sha256=eamNCi6nxQnreccbzUPjUNch6a0TN2bpTgmTVOKepyM,147
|
|
3
|
+
realmarketapi_sdk/client.py,sha256=W5XOf_mQ4GfLbagQra9Vu_RNRGSStFCE1F5K7T_sa3g,2076
|
|
4
|
+
realmarketapi_sdk/websocket.py,sha256=bPzPmf8uKULUqIIGNssplCoyVnU_OlltnvMImh13gBE,1737
|
|
5
|
+
realmarketapi_python_sdk_beta-0.1.0b1.dist-info/METADATA,sha256=9J4m1intztPpLn9x2GvzsQygEGVySEwqhWFrhuRq-Mk,4872
|
|
6
|
+
realmarketapi_python_sdk_beta-0.1.0b1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
realmarketapi_python_sdk_beta-0.1.0b1.dist-info/top_level.txt,sha256=xKsw_vuhhrx2UdXSNj8k2fR50s5ssSrzToUHqpuYexM,18
|
|
8
|
+
realmarketapi_python_sdk_beta-0.1.0b1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phideround
|
|
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 @@
|
|
|
1
|
+
realmarketapi_sdk
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
from urllib.parse import urlencode
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class RealMarketApiClient:
|
|
12
|
+
api_key: str
|
|
13
|
+
base_url: str = "https://api.realmarketapi.com"
|
|
14
|
+
timeout_seconds: float = 20.0
|
|
15
|
+
|
|
16
|
+
def __post_init__(self) -> None:
|
|
17
|
+
self.base_url = self.base_url.rstrip("/")
|
|
18
|
+
self._http = httpx.Client(timeout=self.timeout_seconds)
|
|
19
|
+
|
|
20
|
+
def close(self) -> None:
|
|
21
|
+
self._http.close()
|
|
22
|
+
|
|
23
|
+
def get_price(self, symbol_code: str, time_frame: str) -> Dict[str, Any]:
|
|
24
|
+
return self._get("/api/v1/price", {"symbolCode": symbol_code, "timeFrame": time_frame})
|
|
25
|
+
|
|
26
|
+
def get_candles(self, symbol_code: str, time_frame: str) -> Dict[str, Any]:
|
|
27
|
+
return self._get("/api/v1/candle", {"symbolCode": symbol_code, "timeFrame": time_frame})
|
|
28
|
+
|
|
29
|
+
def get_history(
|
|
30
|
+
self,
|
|
31
|
+
symbol_code: str,
|
|
32
|
+
start_time: str,
|
|
33
|
+
end_time: str,
|
|
34
|
+
page_number: int = 1,
|
|
35
|
+
page_size: int = 20,
|
|
36
|
+
) -> Dict[str, Any]:
|
|
37
|
+
return self._get(
|
|
38
|
+
"/api/v1/history",
|
|
39
|
+
{
|
|
40
|
+
"symbolCode": symbol_code,
|
|
41
|
+
"startTime": start_time,
|
|
42
|
+
"endTime": end_time,
|
|
43
|
+
"pageNumber": str(page_number),
|
|
44
|
+
"pageSize": str(page_size),
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def get_symbols(self) -> Dict[str, Any]:
|
|
49
|
+
return self._get("/api/v1/symbol", None)
|
|
50
|
+
|
|
51
|
+
def get_sma(self, symbol_code: str, time_frame: str, period: int = 20) -> Dict[str, Any]:
|
|
52
|
+
return self._get(
|
|
53
|
+
"/api/v1/indicator/sma",
|
|
54
|
+
{"symbolCode": symbol_code, "timeFrame": time_frame, "period": str(period)},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def _get(self, path: str, query: Optional[Dict[str, str]]) -> Dict[str, Any]:
|
|
58
|
+
params: Dict[str, str] = {"apiKey": self.api_key}
|
|
59
|
+
if query:
|
|
60
|
+
params.update(query)
|
|
61
|
+
|
|
62
|
+
url = f"{self.base_url}{path}?{urlencode(params)}"
|
|
63
|
+
response = self._http.get(url)
|
|
64
|
+
response.raise_for_status()
|
|
65
|
+
return response.json()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import json
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, AsyncIterator, Dict
|
|
7
|
+
from urllib.parse import urlencode, urlparse
|
|
8
|
+
|
|
9
|
+
import websockets
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class RealMarketApiWebSocket:
|
|
14
|
+
api_key: str
|
|
15
|
+
base_url: str = "https://api.realmarketapi.com"
|
|
16
|
+
reconnect_delay_seconds: float = 2.0
|
|
17
|
+
|
|
18
|
+
async def stream_price(self, symbol_code: str, time_frame: str) -> AsyncIterator[Dict[str, Any]]:
|
|
19
|
+
async for item in self._stream("price", {"symbolCode": symbol_code, "timeFrame": time_frame}):
|
|
20
|
+
yield item
|
|
21
|
+
|
|
22
|
+
async def stream_candles(self, symbol_code: str, time_frame: str) -> AsyncIterator[Dict[str, Any]]:
|
|
23
|
+
async for item in self._stream("candles", {"symbolCode": symbol_code, "timeFrame": time_frame}):
|
|
24
|
+
yield item
|
|
25
|
+
|
|
26
|
+
async def _stream(self, endpoint: str, params: Dict[str, str]) -> AsyncIterator[Dict[str, Any]]:
|
|
27
|
+
closed_by_user = False
|
|
28
|
+
|
|
29
|
+
while not closed_by_user:
|
|
30
|
+
url = self._to_ws_url(endpoint, params)
|
|
31
|
+
try:
|
|
32
|
+
async with websockets.connect(url) as socket:
|
|
33
|
+
while True:
|
|
34
|
+
raw = await socket.recv()
|
|
35
|
+
yield json.loads(raw)
|
|
36
|
+
except asyncio.CancelledError:
|
|
37
|
+
closed_by_user = True
|
|
38
|
+
except Exception:
|
|
39
|
+
await asyncio.sleep(self.reconnect_delay_seconds)
|
|
40
|
+
|
|
41
|
+
def _to_ws_url(self, endpoint: str, params: Dict[str, str]) -> str:
|
|
42
|
+
parsed = urlparse(self.base_url.rstrip("/"))
|
|
43
|
+
scheme = "wss" if parsed.scheme == "https" else "ws"
|
|
44
|
+
query = urlencode({"apiKey": self.api_key, **params})
|
|
45
|
+
return f"{scheme}://{parsed.netloc}/{endpoint}?{query}"
|