socketrade 0.1.0__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,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: socketrade
3
+ Version: 0.1.0
4
+ Summary: Minimal Python client for the Socketrade MT5 API
5
+ Author-email: Socketrade <support@socketrade.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Socketrade
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://www.socketrade.com
29
+ Project-URL: Documentation, https://www.socketrade.com/developers/quickstart
30
+ Project-URL: Source, https://github.com/respondsetausi-del/socketrade-sdks/tree/main/python
31
+ Project-URL: Issues, https://github.com/respondsetausi-del/socketrade-sdks/issues
32
+ Keywords: mt5,metatrader,trading,api,forex
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Topic :: Office/Business :: Financial :: Investment
37
+ Requires-Python: >=3.9
38
+ Description-Content-Type: text/markdown
39
+ License-File: LICENSE
40
+ Requires-Dist: requests>=2.28
41
+ Dynamic: license-file
42
+
43
+ # Socketrade Python client
44
+
45
+ Minimal client for the Socketrade MT5 API. Only `requests` is required.
46
+
47
+ ```bash
48
+ pip install socketrade
49
+ ```
50
+
51
+ ```python
52
+ import os
53
+ from socketrade import Socketrade
54
+
55
+ sr = Socketrade(os.environ["SOCKETRADE_KEY"])
56
+
57
+ print(sr.usage())
58
+
59
+ account = sr.add_account(
60
+ number="41299492",
61
+ password=os.environ["MT5_PASSWORD"],
62
+ server="Deriv-Demo",
63
+ name="Demo",
64
+ )
65
+ sr.connect(account["id"])
66
+
67
+ print(sr.status(account["id"]))
68
+ for p in sr.positions(account["id"])["positions"]:
69
+ print(p["symbol"], p["volume"], p["profit"])
70
+
71
+ order = sr.order_send(account["id"], "EURUSD", 0.01, "buy")
72
+ sr.position_close(account["id"], order["ticket"])
73
+ ```
74
+
75
+ - One seat covers one MT5 account.
76
+ - Wait for `status == "ready"` before placing an order.
77
+ - Use a demo account first.
78
+ - The WebSocket streams price ticks; positions and history are REST reads.
79
+ - Docs: https://www.socketrade.com/developers
@@ -0,0 +1,6 @@
1
+ socketrade.py,sha256=zplACJlFeZ0LZPJKx2oxBkZAaxAB3zvYlCj5V3pC5DU,3870
2
+ socketrade-0.1.0.dist-info/licenses/LICENSE,sha256=BKcibgv6Rxt2XIooZkxGLshtBz7Aug3zl3wyP1hk4bM,1067
3
+ socketrade-0.1.0.dist-info/METADATA,sha256=GHCH5ZJtzWvfff8z7nRPG8nzxiBO3SVhnsTJ9ZEQ-cg,3085
4
+ socketrade-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ socketrade-0.1.0.dist-info/top_level.txt,sha256=Yxb7Rjx4qncUjC4IXzLBRFyV5d125iNUN5kbh-DLJpw,11
6
+ socketrade-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Socketrade
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
+ socketrade
socketrade.py ADDED
@@ -0,0 +1,107 @@
1
+ """Minimal Socketrade client.
2
+
3
+ No dependency beyond requests. One API key, one base URL, one method per call.
4
+ Docs: https://www.socketrade.com/developers
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from typing import Any
9
+
10
+ import requests
11
+
12
+ __version__ = "0.1.0"
13
+
14
+ __all__ = ["Socketrade", "SocketradeError"]
15
+
16
+
17
+ class SocketradeError(Exception):
18
+ """A non-2xx answer from the API, with the status and the parsed body."""
19
+
20
+ def __init__(self, status: int, body: Any):
21
+ self.status = status
22
+ self.body = body
23
+ super().__init__(f"Socketrade {status}: {body}")
24
+
25
+
26
+ class Socketrade:
27
+ def __init__(
28
+ self,
29
+ api_key: str,
30
+ base: str = "https://api.socketrade.com",
31
+ timeout: float = 30,
32
+ ) -> None:
33
+ if not api_key:
34
+ raise ValueError("api_key is required")
35
+ self.api_key = api_key
36
+ self.base = base.rstrip("/")
37
+ self.timeout = timeout
38
+ self.session = requests.Session()
39
+ self.session.headers.update(
40
+ {"X-API-Key": api_key, "Accept": "application/json"}
41
+ )
42
+
43
+ # -- transport -----------------------------------------------------
44
+ def _request(self, method: str, path: str, **kwargs: Any) -> Any:
45
+ res = self.session.request(
46
+ method, f"{self.base}{path}", timeout=self.timeout, **kwargs
47
+ )
48
+ if not res.ok:
49
+ try:
50
+ body: Any = res.json()
51
+ except ValueError:
52
+ body = res.text
53
+ raise SocketradeError(res.status_code, body)
54
+ return res.json() if res.content else {}
55
+
56
+ # -- account -------------------------------------------------------
57
+ def usage(self) -> dict:
58
+ """Seats bought and seats used."""
59
+ return self._request("GET", "/v2/usage")
60
+
61
+ def add_account(
62
+ self, number: str | int, password: str, server: str, name: str | None = None
63
+ ) -> dict:
64
+ """Add an account. One seat per account. The password is sent once and encrypted."""
65
+ payload = {
66
+ "accountNumber": str(number),
67
+ "accountPassword": password,
68
+ "accountServerHost": server,
69
+ }
70
+ if name:
71
+ payload["name"] = name
72
+ return self._request("POST", "/v2/accounts", json=payload)
73
+
74
+ def connect(self, account_id: str) -> dict:
75
+ """Bring the account online. Wait for status == 'ready' before trading."""
76
+ return self._request("POST", f"/v2/accounts/{account_id}/connect")
77
+
78
+ # -- read ----------------------------------------------------------
79
+ def status(self, account_id: str) -> dict:
80
+ return self._request("GET", f"/v2/{account_id}/status")
81
+
82
+ def positions(self, account_id: str) -> dict:
83
+ return self._request("GET", f"/v2/{account_id}/positions")
84
+
85
+ def history(self, account_id: str, **params: Any) -> dict:
86
+ return self._request("GET", f"/v2/{account_id}/history", params=params)
87
+
88
+ # -- trade ---------------------------------------------------------
89
+ def order_send(
90
+ self, account_id: str, symbol: str, volume: float, side: str, **extra: Any
91
+ ) -> dict:
92
+ """side is 'buy' or 'sell', sent as operation 0 or 1.
93
+
94
+ Extra fields pass through (sl, tp, deviation, magic, comment). Only market orders
95
+ are sent: the v2 contract has no pending-order path today.
96
+ """
97
+ op = {"buy": 0, "sell": 1}.get(str(side).lower())
98
+ if op is None:
99
+ raise ValueError("side must be 'buy' or 'sell'")
100
+ extra.pop("type", None)
101
+ payload = {"symbol": symbol, "volume": volume, **extra, "operation": op}
102
+ return self._request("POST", f"/v2/{account_id}/OrderSend", json=payload)
103
+
104
+ def position_close(self, account_id: str, ticket: int) -> dict:
105
+ return self._request(
106
+ "POST", f"/v2/{account_id}/PositionClose", json={"ticket": ticket}
107
+ )