tickwire-cli 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.
- tickwire_cli/__init__.py +4 -0
- tickwire_cli/__main__.py +14 -0
- tickwire_cli/_version.py +1 -0
- tickwire_cli/app.py +174 -0
- tickwire_cli/commands/__init__.py +11 -0
- tickwire_cli/commands/accounts.py +51 -0
- tickwire_cli/commands/login.py +81 -0
- tickwire_cli/commands/logs.py +272 -0
- tickwire_cli/commands/sandbox.py +74 -0
- tickwire_cli/commands/trade.py +153 -0
- tickwire_cli/commands/trigger.py +44 -0
- tickwire_cli/commands/webhooks_listen.py +112 -0
- tickwire_cli/credentials.py +259 -0
- tickwire_cli/errors.py +6 -0
- tickwire_cli/output.py +96 -0
- tickwire_cli-0.1.0.dist-info/METADATA +93 -0
- tickwire_cli-0.1.0.dist-info/RECORD +21 -0
- tickwire_cli-0.1.0.dist-info/WHEEL +5 -0
- tickwire_cli-0.1.0.dist-info/entry_points.txt +2 -0
- tickwire_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- tickwire_cli-0.1.0.dist-info/top_level.txt +1 -0
tickwire_cli/output.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Human or ``--json`` output. Data goes to stdout; notes and errors to stderr.
|
|
2
|
+
|
|
3
|
+
**Terminal safety.** Human output carries strings the server sent (paths, error
|
|
4
|
+
codes, excerpts, account names). Before anything reaches the terminal, every
|
|
5
|
+
control character that could move the cursor or talk to the terminal is
|
|
6
|
+
rendered visibly instead: C0 controls (ESC, CR, TAB, BEL, …), DEL, C1 controls
|
|
7
|
+
(``\\x9b`` CSI, …) and the Unicode line separators and bidi overrides become
|
|
8
|
+
``\\xNN`` / ``\\uNNNN``. So ``\\x1b[2J``, an OSC 52 clipboard write or a ``\\r``
|
|
9
|
+
overwrite prints as text. A newline is kept only between the lines a command
|
|
10
|
+
composes itself: a stream line (:meth:`Output.line`), each line of a list, a
|
|
11
|
+
table cell and an error message are single lines, so a ``\\n`` inside a value
|
|
12
|
+
cannot forge an extra line. ``--json`` is unchanged (``json.dumps`` escapes).
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import sys
|
|
18
|
+
from collections.abc import Callable, Sequence
|
|
19
|
+
from typing import Any, TextIO
|
|
20
|
+
|
|
21
|
+
# Unicode characters that reorder or break lines without being C0/C1 controls.
|
|
22
|
+
_UNICODE_UNSAFE = frozenset([0x2028, 0x2029, 0x200E, 0x200F, *range(0x202A, 0x202F), *range(0x2066, 0x206A)])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _escape(ch: str) -> str:
|
|
26
|
+
o = ord(ch)
|
|
27
|
+
return f"\\x{o:02x}" if o < 0x100 else f"\\u{o:04x}"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _unsafe(ch: str) -> bool:
|
|
31
|
+
o = ord(ch)
|
|
32
|
+
return o < 0x20 or 0x7F <= o <= 0x9F or o in _UNICODE_UNSAFE
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def clean(text: Any, *, newlines: bool = False) -> str:
|
|
36
|
+
"""``text`` made safe to print on a terminal. ``newlines=True`` keeps ``\\n`` (for text
|
|
37
|
+
the CLI composed from lines it already cleaned, or wrote itself)."""
|
|
38
|
+
s = str(text)
|
|
39
|
+
if not any(_unsafe(c) for c in s):
|
|
40
|
+
return s
|
|
41
|
+
return "".join(c if (c == "\n" and newlines) or not _unsafe(c) else _escape(c) for c in s)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Human = str | Sequence[str] | None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _render(human: Human) -> str | None:
|
|
48
|
+
if human is None:
|
|
49
|
+
return None
|
|
50
|
+
if isinstance(human, str):
|
|
51
|
+
return clean(human, newlines=True)
|
|
52
|
+
return "\n".join(clean(line) for line in human)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Output:
|
|
56
|
+
def __init__(self, json_mode: bool = False, stdout: TextIO | None = None,
|
|
57
|
+
stderr: TextIO | None = None) -> None:
|
|
58
|
+
self.json = json_mode
|
|
59
|
+
self.stdout = stdout or sys.stdout
|
|
60
|
+
self.stderr = stderr or sys.stderr
|
|
61
|
+
|
|
62
|
+
def result(self, data: Any, human: Human | Callable[[], Human] = None) -> None:
|
|
63
|
+
"""One result: JSON in ``--json`` mode, else the human text (a string, or a list of
|
|
64
|
+
lines each printed as one line)."""
|
|
65
|
+
if self.json:
|
|
66
|
+
self.stdout.write(json.dumps(data, default=str, sort_keys=True) + "\n")
|
|
67
|
+
else:
|
|
68
|
+
text = _render(human() if callable(human) else human)
|
|
69
|
+
if text is None:
|
|
70
|
+
text = json.dumps(data, default=str, indent=2, sort_keys=True) # escapes controls
|
|
71
|
+
self.stdout.write(text.rstrip("\n") + "\n")
|
|
72
|
+
self.stdout.flush()
|
|
73
|
+
|
|
74
|
+
def line(self, data: dict, human: str | Sequence[str]) -> None:
|
|
75
|
+
"""One record of a stream (``listen``, ``logs tail``): NDJSON in ``--json`` mode. The
|
|
76
|
+
human form is one line (a string), or a list of lines, never a line broken by data."""
|
|
77
|
+
self.result(data, [human] if isinstance(human, str) else list(human))
|
|
78
|
+
|
|
79
|
+
def note(self, text: str) -> None:
|
|
80
|
+
"""Progress and advice, never data (stderr, also in ``--json`` mode)."""
|
|
81
|
+
self.stderr.write(clean(text, newlines=True).rstrip("\n") + "\n")
|
|
82
|
+
self.stderr.flush()
|
|
83
|
+
|
|
84
|
+
def error(self, code: str, message: str, **extra: Any) -> None:
|
|
85
|
+
if self.json:
|
|
86
|
+
self.stdout.write(json.dumps({"error": code, "message": message, **extra}, default=str,
|
|
87
|
+
sort_keys=True) + "\n")
|
|
88
|
+
self.stdout.flush()
|
|
89
|
+
else:
|
|
90
|
+
self.note(clean(f"error: {message}" + (f" ({code})" if code else "")))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def table(rows: Sequence[Sequence[Any]], headers: Sequence[str]) -> str:
|
|
94
|
+
cells = [[clean(h) for h in headers]] + [["" if c is None else clean(c) for c in r] for r in rows]
|
|
95
|
+
widths = [max(len(r[i]) for r in cells) for i in range(len(headers))]
|
|
96
|
+
return "\n".join(" ".join(c.ljust(w) for c, w in zip(r, widths)).rstrip() for r in cells)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tickwire-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tickwire CLI: sign in, create a sandbox, list accounts, trade with a reason and a truthful outcome, and forward webhooks to localhost, for the Tickwire MT4/MT5 cloud API.
|
|
5
|
+
Author-email: Tickwire <hello@tickwire.io>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://tickwire.io/
|
|
8
|
+
Project-URL: Documentation, https://tickwire.io/docs/cli/
|
|
9
|
+
Project-URL: Changelog, https://tickwire.io/docs/changelog/
|
|
10
|
+
Keywords: metatrader,mt4,mt5,trading,api,cli,webhooks
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: tickwire<0.2,>=0.1.0
|
|
25
|
+
Requires-Dist: httpx<1,>=0.27
|
|
26
|
+
Provides-Extra: keyring
|
|
27
|
+
Requires-Dist: keyring<26,>=24; extra == "keyring"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# tickwire-cli
|
|
33
|
+
|
|
34
|
+
The `tickwire` command for the Tickwire MT4/MT5 cloud API, built on the
|
|
35
|
+
[`tickwire` Python SDK](https://tickwire.io/docs/sdk-python/).
|
|
36
|
+
|
|
37
|
+
**Not published yet.** `pip install tickwire-cli` won't find it. Install from source, from the
|
|
38
|
+
repository root (the SDK first, because the CLI needs it):
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pip install ./sdk/python ./cli
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Once it is published:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pip install tickwire-cli # or "tickwire-cli[keyring]" to keep keys in the OS keychain
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Python 3.11 or newer. MIT licensed.
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
A free sandbox (no sign-in, no card) against the public API:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
export TICKWIRE_SANDBOX_URL=https://api.tickwire.io
|
|
58
|
+
tickwire sandbox create # one simulated MT5 account; the key is stored, never printed
|
|
59
|
+
tickwire --sandbox accounts list
|
|
60
|
+
tickwire --sandbox trade open <account-id> --side buy --symbol EURUSD --volume 0.01 --reason "test"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
With your own API key:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
export TICKWIRE_API_URL=https://api.tickwire.io
|
|
67
|
+
tickwire login # hidden prompt; the key is checked, then stored
|
|
68
|
+
tickwire accounts list
|
|
69
|
+
tickwire listen --forward-to http://localhost:3000/webhooks
|
|
70
|
+
tickwire trigger trade.outcome
|
|
71
|
+
tickwire logs tail -f --status errors # your request log, new calls as they happen
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The sandbox key from `sandbox create` is restricted: it can manage accounts,
|
|
75
|
+
trade and read, but not use webhooks (`listen`, `trigger`). For those, use your
|
|
76
|
+
own key, or a sandbox key made from it (`POST /v1/sandbox/keys`) with
|
|
77
|
+
`tickwire login --sandbox`.
|
|
78
|
+
|
|
79
|
+
## Commands
|
|
80
|
+
|
|
81
|
+
- `login`: the key comes from a hidden prompt or stdin, never from an argument, and is never
|
|
82
|
+
printed. It is stored in the OS keychain or in a `0600` file.
|
|
83
|
+
- `trade open|close`: `--reason` is mandatory and an `Idempotency-Key` is sent automatically.
|
|
84
|
+
The result is `applied`, `no_change`, `rejected`, `held` or `unknown` (exit codes 0, 0, 3,
|
|
85
|
+
4, 5). An `unknown` result is never retried.
|
|
86
|
+
- `listen --forward-to`: events are signed by the server, verified by the CLI, then forwarded
|
|
87
|
+
byte for byte.
|
|
88
|
+
- `logs tail`: your request log, oldest first, `--follow` for new calls. Redacted bodies of
|
|
89
|
+
failed calls only with `--bodies`, and only when the API returns them to your key. Waits for
|
|
90
|
+
`Retry-After` on `429`.
|
|
91
|
+
- `--json` works with every command.
|
|
92
|
+
|
|
93
|
+
Full documentation: [tickwire.io/docs/cli](https://tickwire.io/docs/cli/).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
tickwire_cli/__init__.py,sha256=8vRSf1lud54qzxZ6aH3QC5U_IUkMLn1DlEe3p9hNgDg,123
|
|
2
|
+
tickwire_cli/__main__.py,sha256=ieIS3NGH4kkAwgI1fT8aEte3kkRmkM879XOmW3iHxKY,241
|
|
3
|
+
tickwire_cli/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
4
|
+
tickwire_cli/app.py,sha256=QvnCyynPgSEWrzG55bfEbWWgIP29NmQT-vzC9Uj0ZVc,7344
|
|
5
|
+
tickwire_cli/credentials.py,sha256=ZOpltxcJflUM8TbJT-hjG5f78sNLQFrAEj04zMHJxf4,10335
|
|
6
|
+
tickwire_cli/errors.py,sha256=bEHhVzUZg7xkeG7dZDkd7TBOt5M670CZoqcsnf1rOAI,217
|
|
7
|
+
tickwire_cli/output.py,sha256=j4uEhhZ0DY2sx6lwrPJ3s6ZHQCsKWT4WjD7oU903tjY,4226
|
|
8
|
+
tickwire_cli/commands/__init__.py,sha256=Zyso0z33_ACJjQ5DHbP3XZ7GCgVZbBHD4kUTMpoX4Vs,453
|
|
9
|
+
tickwire_cli/commands/accounts.py,sha256=15U5QEWL4tbip8PIbO6QpNLCn7XDh_IC9Du1JCH_5bE,1871
|
|
10
|
+
tickwire_cli/commands/login.py,sha256=3eTh5rW0bgYJivSdsLrU0b3bYNzL2lC67TaGj8a3rDQ,3506
|
|
11
|
+
tickwire_cli/commands/logs.py,sha256=JlMjCmxqU2GVzFL1A7RSuVDVLxQx54CeeythmTAqZNY,12898
|
|
12
|
+
tickwire_cli/commands/sandbox.py,sha256=dKBd2cpjFXA49JvDwgQWXv5cPrOJGCzSzYW1NHnvzMA,3882
|
|
13
|
+
tickwire_cli/commands/trade.py,sha256=i7hTFFJquj-RalDF6Wf0Bvz40FP_VgHVL-Oc_Z9Z_To,7266
|
|
14
|
+
tickwire_cli/commands/trigger.py,sha256=H1T80FaPvzMN38UF-PVSMZXEHaEreQiWo6OyfMChqh0,2164
|
|
15
|
+
tickwire_cli/commands/webhooks_listen.py,sha256=QM2Xg2G1x4x3bExiM-0QCLb9EAx_e6Unar7y755X8vY,5807
|
|
16
|
+
tickwire_cli-0.1.0.dist-info/licenses/LICENSE,sha256=ExGtsuI2oFkv3x2tdhpsThL23NXsfHG0kE0oJK8uew0,1065
|
|
17
|
+
tickwire_cli-0.1.0.dist-info/METADATA,sha256=oibjT7MOowvox7L8c7Ea36vj2nGCEJaWT3rBz_-LVRg,3678
|
|
18
|
+
tickwire_cli-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
19
|
+
tickwire_cli-0.1.0.dist-info/entry_points.txt,sha256=1v4i21yQWMGHfEtBY9_GowTArfc6P2G5AxytKIMDuJs,56
|
|
20
|
+
tickwire_cli-0.1.0.dist-info/top_level.txt,sha256=p0oMVP3yU-_LeyfKwdk3vPPzO_uBqtTgCQ7iPHyaqXM,13
|
|
21
|
+
tickwire_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tickwire
|
|
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
|
+
tickwire_cli
|