fxsocket 0.1__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.
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: fxsocket
3
+ Version: 0.1
4
+ Summary: Python SDK for the FxSocket API — MT4/MT5 account management, trading, and real-time streaming.
5
+ Project-URL: Homepage, https://fxsocket.com
6
+ Project-URL: Documentation, https://api.fxsocket.com/v1/docs
7
+ Project-URL: Source, https://github.com/fxsocket-com/FxSocket-Python-SDK
8
+ Author: FxSocket
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: forex,fxsocket,metatrader,mt4,mt5,trading
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: httpx>=0.27
18
+ Requires-Dist: pydantic>=2.5
19
+ Requires-Dist: websockets>=13
20
+ Provides-Extra: dev
21
+ Requires-Dist: mypy>=1.11; extra == 'dev'
22
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
23
+ Requires-Dist: pytest>=8; extra == 'dev'
24
+ Requires-Dist: respx>=0.21; extra == 'dev'
25
+ Requires-Dist: ruff>=0.6; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # FxSocket Python SDK
29
+
30
+ [![PyPI](https://img.shields.io/pypi/v/fxsocket.svg)](https://pypi.org/project/fxsocket/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/fxsocket.svg)](https://pypi.org/project/fxsocket/)
32
+ [![CI](https://github.com/fxsocket-com/FxSocket-Python-SDK/actions/workflows/ci.yml/badge.svg)](https://github.com/fxsocket-com/FxSocket-Python-SDK/actions/workflows/ci.yml)
33
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/fxsocket-com/FxSocket-Python-SDK/blob/main/LICENSE)
34
+
35
+ Typed Python client for the [FxSocket](https://fxsocket.com) API. Connect your
36
+ MetaTrader 4 / 5 accounts, then place trades, read market data, and stream live
37
+ updates over REST and WebSocket — with mirrored **synchronous** and **async**
38
+ interfaces.
39
+
40
+ ## Features
41
+
42
+ - **Account management** — link, list, fetch, and disconnect MT4/MT5 accounts.
43
+ - **Trading** — market & pending orders, modify, close, plus margin/profit calculators.
44
+ - **Market data** — quotes, symbol specifications, OHLC history, account state & info.
45
+ - **Live streaming** — ticks, bars, account, positions, trades, and terminal status
46
+ over WebSocket, with automatic reconnect + subscription replay.
47
+ - **Sync *and* async** — `Client` / `AsyncClient`, method-for-method mirrors.
48
+ - **Typed** — Pydantic v2 models throughout; ships `py.typed`.
49
+ - **One interface for MT4 and MT5** — platform differences handled for you.
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install fxsocket
55
+ ```
56
+
57
+ Requires Python 3.10+.
58
+
59
+ ## Quickstart
60
+
61
+ ```python
62
+ from fxsocket import Client
63
+
64
+ with Client(api_key="fxs_live_…") as fx: # or set FXSOCKET_API_KEY
65
+ account = fx.accounts.list()[0]
66
+ term = fx.terminal(account)
67
+
68
+ print("equity:", term.account_summary().equity)
69
+ print("EURUSD:", term.quote("EURUSD").ask)
70
+ ```
71
+
72
+ ## Authentication
73
+
74
+ Every call uses your FxSocket API key (`fxs_live_…`), from the dashboard.
75
+ Pass it explicitly, or set the `FXSOCKET_API_KEY` environment variable and call
76
+ `Client()` with no arguments.
77
+
78
+ ```python
79
+ from fxsocket import Client
80
+
81
+ with Client(api_key="fxs_live_…") as fx:
82
+ for account in fx.accounts.list():
83
+ print(account.platform, account.nickname, account.status)
84
+ ```
85
+
86
+ ## Managing accounts
87
+
88
+ ```python
89
+ from fxsocket import Client
90
+
91
+ with Client(api_key="fxs_live_…") as fx:
92
+ # Link a new account (platform defaults to MT5).
93
+ account = fx.accounts.create(
94
+ platform="mt5", server="ICMarkets-Demo", login=1150125, password="…",
95
+ )
96
+
97
+ # Poll until it's connected.
98
+ account = fx.accounts.get(account.id)
99
+ print(account.status) # connecting → connected
100
+
101
+ # Where this account's terminal API lives (empty until provisioned).
102
+ print(account.rest_url, account.ws_url)
103
+
104
+ fx.accounts.delete(account.id) # unlink
105
+ ```
106
+
107
+ Everything is also available on `AsyncClient`:
108
+
109
+ ```python
110
+ from fxsocket import AsyncClient
111
+
112
+ async with AsyncClient(api_key="fxs_live_…") as fx:
113
+ accounts = await fx.accounts.list()
114
+ ```
115
+
116
+ ## Trading & market data
117
+
118
+ `fx.terminal(account)` returns a REST client bound to that account's terminal
119
+ (resolved from `account.rest_url`, whether it's a shared pod or a private droplet):
120
+
121
+ ```python
122
+ from fxsocket import Client
123
+
124
+ with Client(api_key="fxs_live_…") as fx:
125
+ account = fx.accounts.get("…") # must be connected (has a terminal)
126
+ term = fx.terminal(account)
127
+
128
+ summary = term.account_summary() # balance, equity, margin, …
129
+ quote = term.quote("EURUSD") # latest tick
130
+ bars = term.price_history("EURUSD", "M5") # recent OHLC bars
131
+
132
+ result = term.order_send( # market buy
133
+ symbol="EURUSD", operation="Buy", volume=0.10,
134
+ stop_loss=1.07, take_profit=1.10,
135
+ )
136
+ if result.success:
137
+ term.order_modify(result.order, take_profit=1.12) # None keeps the SL
138
+ term.order_close(result.order)
139
+ ```
140
+
141
+ Inputs are validated client-side before they're sent. One guard worth knowing:
142
+ in `order_modify`, a literal `stop_loss=0.0` would *remove* your stop-loss, so
143
+ it's rejected — pass `clear_stop_loss=True` to remove one deliberately, while
144
+ `None` (the default) keeps the current value.
145
+
146
+ MT4 and MT5 share one interface. MT5-only timeframes (`M2`, `M3`, `H2`, `H6`,
147
+ `H8`, `H12`) raise `UnsupportedOnPlatformError` on MT4 before any request.
148
+
149
+ > **MT4 history note:** on MT4, `price_history` with `from_`/`to` bounds (or the
150
+ > `D1` timeframe) can fail server-side with `CopyRates failed` when the terminal
151
+ > hasn't loaded that history. Calling `price_history(symbol, timeframe)` without
152
+ > date bounds returns the most recent bars reliably.
153
+
154
+ ## Streaming (WebSocket)
155
+
156
+ Subscribe to live ticks, bars, account, positions, trades, and terminal status.
157
+ Streaming is async-first; a synchronous wrapper is provided too. A dropped
158
+ connection auto-reconnects and replays active subscriptions
159
+ (`auto_reconnect=True` by default).
160
+
161
+ ```python
162
+ import asyncio
163
+ from fxsocket import AsyncClient, Tick, Bar, AccountUpdate
164
+
165
+ async def main():
166
+ async with AsyncClient(api_key="fxs_live_…") as fx:
167
+ account = await fx.accounts.get("…")
168
+ async with fx.stream(account) as s:
169
+ await s.subscribe_prices("EURUSD")
170
+ await s.subscribe_bars("EURUSD", "M5")
171
+ await s.subscribe_account()
172
+ async for event in s:
173
+ match event:
174
+ case Tick():
175
+ print(event.symbol, event.data.bid, event.data.ask)
176
+ case Bar():
177
+ print(event.symbol, event.timeframe, event.data.close)
178
+ case AccountUpdate():
179
+ print("equity", event.data.equity)
180
+
181
+ asyncio.run(main())
182
+ ```
183
+
184
+ Synchronous equivalent:
185
+
186
+ ```python
187
+ from fxsocket import Client, Tick
188
+
189
+ with Client(api_key="fxs_live_…") as fx:
190
+ with fx.stream(fx.accounts.get("…")) as s:
191
+ s.subscribe_prices("EURUSD")
192
+ for event in s:
193
+ if isinstance(event, Tick):
194
+ print(event.data.bid, event.data.ask)
195
+ ```
196
+
197
+ ## Errors
198
+
199
+ Every failure raises a subclass of `fxsocket.FxSocketError`:
200
+
201
+ | Exception | When |
202
+ |---|---|
203
+ | `AuthError` | missing/invalid API key |
204
+ | `RateLimitError` | rate limited (`.retry_after`) |
205
+ | `ValidationError` | malformed request |
206
+ | `NotFoundError` | account/resource not found |
207
+ | `AccountCapError` | plan account limit reached (`.cap`, `.current`) |
208
+ | `DuplicateAccountError` | account already linked |
209
+ | `ConnectFailedError` | broker rejected the login |
210
+ | `TerminalNotReadyError` | terminal not provisioned / not ready |
211
+ | `UnsupportedOnPlatformError` | feature not available on this platform |
212
+
213
+ ```python
214
+ from fxsocket import Client, AccountCapError
215
+
216
+ try:
217
+ fx.accounts.create(server="Demo", login=1, password="…")
218
+ except AccountCapError as e:
219
+ print(f"Plan limit reached: {e.current}/{e.cap}")
220
+ ```
221
+
222
+ ## Private hosting
223
+
224
+ Privately-hosted accounts (a dedicated droplet) are listed, traded, and streamed
225
+ exactly like shared-cluster accounts — their `rest_url` / `ws_url` simply point
226
+ at the droplet. The droplet serves a self-signed certificate, so reach it with
227
+ `Client(..., verify_terminal_tls=False)` (or supply a pinned CA). *Creating* a
228
+ private-hosted account is done in the dashboard.
229
+
230
+ ## Timestamps
231
+
232
+ Terminal timestamps (`quote.time`, candle `time`, order times) are returned as
233
+ **strings in broker server time** — not Python `datetime`. The trailing `Z` is
234
+ stylistic and does **not** mean UTC. Use `terminal.server_timezone()` to get the
235
+ broker's UTC offset if you need to convert.
236
+
237
+ ## Requirements
238
+
239
+ - Python 3.10+
240
+ - [`httpx`](https://www.python-httpx.org/), [`pydantic`](https://docs.pydantic.dev/) ≥ 2, [`websockets`](https://websockets.readthedocs.io/) ≥ 13
241
+
242
+ ## Links
243
+
244
+ - API reference: <https://api.fxsocket.com/v1/docs>
245
+ - Examples: [`examples/`](https://github.com/fxsocket-com/FxSocket-Python-SDK/tree/main/examples)
246
+
247
+ ## Development
248
+
249
+ ```bash
250
+ pip install -e ".[dev]"
251
+ ruff check . && mypy && pytest
252
+ ```
253
+
254
+ ## License
255
+
256
+ MIT — see [LICENSE](https://github.com/fxsocket-com/FxSocket-Python-SDK/blob/main/LICENSE).
@@ -0,0 +1,17 @@
1
+ fxsocket/__init__.py,sha256=KlqusRjj-pupxBBSh-AAi2H_IFu9Uxr9jIOuWzKU0cc,2565
2
+ fxsocket/_http.py,sha256=9qvAHt0e7kH3SqAOBBhg1FdKPGSDNAvl3v3zOBT_Kmo,1854
3
+ fxsocket/_version.py,sha256=Lgf9keBX7aG_JEFt6UYSyiFKcm-BYGtmk9ohpQhYpyk,20
4
+ fxsocket/client.py,sha256=bEU2spxWm8JAP3pBa3PQclVBS9REOweupMLaOLgRJU8,8406
5
+ fxsocket/config.py,sha256=VwYq3s2ldeJ1EipB-bjAfkvLAmHAhesUq7BkmYx4eRw,366
6
+ fxsocket/enums.py,sha256=kezIrvGg6N0xJbMLhs6cRrRqpag-Ryxqe-tcJTsCQb8,2723
7
+ fxsocket/errors.py,sha256=eL9aQ8r5uCAoe-Et0ZlEPChgXPJMAZIJpc5F4cwrNGk,4837
8
+ fxsocket/management.py,sha256=MGt7dIiRvVj2w03fnSAGjaOblDNbzLmWfPhetgSIZSE,3544
9
+ fxsocket/models.py,sha256=DsP5-RTDtCLFNScuVaa3y8j-Uk53gyXN_HucTpj4jcU,9496
10
+ fxsocket/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ fxsocket/terminal/__init__.py,sha256=-riDIGbR7z1Czm1W_GepNRecGCz3IhLfJvJWzfiX9OE,947
12
+ fxsocket/terminal/client.py,sha256=T0ZGfQooKgl3WSsrCgdufO8GL86x0BJmfXycThOQg3c,24876
13
+ fxsocket/terminal/stream.py,sha256=nKb_6J5HGyFZ0xOMIbeqoIKquc-UOvanhloP0VCpAJU,19331
14
+ fxsocket-0.1.dist-info/METADATA,sha256=UBCuLCpPUQXtbKrSWwxvbCFo7REEuHBpghfRSiwuIxE,9089
15
+ fxsocket-0.1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
16
+ fxsocket-0.1.dist-info/licenses/LICENSE,sha256=ZWF3UfwdZzyCuL0kqyJ8PFjAD4XjENumu0dGzo0o9GE,1065
17
+ fxsocket-0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FxSocket
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.