socketrade 0.1.0__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.
- socketrade-0.1.0/LICENSE +21 -0
- socketrade-0.1.0/PKG-INFO +79 -0
- socketrade-0.1.0/README.md +37 -0
- socketrade-0.1.0/pyproject.toml +29 -0
- socketrade-0.1.0/setup.cfg +4 -0
- socketrade-0.1.0/socketrade.egg-info/PKG-INFO +79 -0
- socketrade-0.1.0/socketrade.egg-info/SOURCES.txt +9 -0
- socketrade-0.1.0/socketrade.egg-info/dependency_links.txt +1 -0
- socketrade-0.1.0/socketrade.egg-info/requires.txt +1 -0
- socketrade-0.1.0/socketrade.egg-info/top_level.txt +1 -0
- socketrade-0.1.0/socketrade.py +107 -0
socketrade-0.1.0/LICENSE
ADDED
|
@@ -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,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,37 @@
|
|
|
1
|
+
# Socketrade Python client
|
|
2
|
+
|
|
3
|
+
Minimal client for the Socketrade MT5 API. Only `requests` is required.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install socketrade
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import os
|
|
11
|
+
from socketrade import Socketrade
|
|
12
|
+
|
|
13
|
+
sr = Socketrade(os.environ["SOCKETRADE_KEY"])
|
|
14
|
+
|
|
15
|
+
print(sr.usage())
|
|
16
|
+
|
|
17
|
+
account = sr.add_account(
|
|
18
|
+
number="41299492",
|
|
19
|
+
password=os.environ["MT5_PASSWORD"],
|
|
20
|
+
server="Deriv-Demo",
|
|
21
|
+
name="Demo",
|
|
22
|
+
)
|
|
23
|
+
sr.connect(account["id"])
|
|
24
|
+
|
|
25
|
+
print(sr.status(account["id"]))
|
|
26
|
+
for p in sr.positions(account["id"])["positions"]:
|
|
27
|
+
print(p["symbol"], p["volume"], p["profit"])
|
|
28
|
+
|
|
29
|
+
order = sr.order_send(account["id"], "EURUSD", 0.01, "buy")
|
|
30
|
+
sr.position_close(account["id"], order["ticket"])
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- One seat covers one MT5 account.
|
|
34
|
+
- Wait for `status == "ready"` before placing an order.
|
|
35
|
+
- Use a demo account first.
|
|
36
|
+
- The WebSocket streams price ticks; positions and history are REST reads.
|
|
37
|
+
- Docs: https://www.socketrade.com/developers
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "socketrade"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Minimal Python client for the Socketrade MT5 API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "Socketrade", email = "support@socketrade.com" }]
|
|
13
|
+
keywords = ["mt5", "metatrader", "trading", "api", "forex"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["requests>=2.28"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://www.socketrade.com"
|
|
24
|
+
Documentation = "https://www.socketrade.com/developers/quickstart"
|
|
25
|
+
Source = "https://github.com/respondsetausi-del/socketrade-sdks/tree/main/python"
|
|
26
|
+
Issues = "https://github.com/respondsetausi-del/socketrade-sdks/issues"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools]
|
|
29
|
+
py-modules = ["socketrade"]
|
|
@@ -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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
socketrade
|
|
@@ -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
|
+
)
|