melaya 0.1.4 → 0.2.0
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.
- checksums.yaml +4 -4
- data/LICENSE +158 -0
- data/README.md +96 -15
- data/lib/melaya/accounts.rb +42 -0
- data/lib/melaya/assistant.rb +41 -0
- data/lib/melaya/auth.rb +137 -0
- data/lib/melaya/backtest.rb +38 -0
- data/lib/melaya/billing.rb +75 -0
- data/lib/melaya/bugs.rb +67 -0
- data/lib/melaya/connectors.rb +71 -0
- data/lib/melaya/credentials.rb +255 -0
- data/lib/melaya/errors.rb +36 -2
- data/lib/melaya/evals.rb +78 -0
- data/lib/melaya/events.rb +425 -0
- data/lib/melaya/hitl.rb +114 -0
- data/lib/melaya/http_client.rb +159 -30
- data/lib/melaya/market.rb +42 -0
- data/lib/melaya/namespaces.rb +115 -0
- data/lib/melaya/phone.rb +75 -0
- data/lib/melaya/pipelines.rb +342 -0
- data/lib/melaya/projects.rb +58 -0
- data/lib/melaya/runner.rb +44 -0
- data/lib/melaya/strategies.rb +15 -0
- data/lib/melaya/stream.rb +5 -3
- data/lib/melaya/team.rb +102 -0
- data/lib/melaya/templates.rb +148 -0
- data/lib/melaya/version.rb +1 -1
- data/lib/melaya.rb +261 -30
- data/melaya.gemspec +10 -5
- metadata +28 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0422c0d8f2f64f64d6641922f92d3364a6eabfb8c91863fdd9a4d59d7b552a0
|
|
4
|
+
data.tar.gz: 8a1aab35e1c76376d3357790636b32a6e3975219d57cc5d6eff7008bb54f9c5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbbf35e9a198eda11dba80ef9483d0bb40690f42bfb845bfcdb7ac0139a91b9c95b358e070b1f81768bb345305397319877b6837eb85e0fe9d17326ae572c06a
|
|
7
|
+
data.tar.gz: 07bf7a75bf51ef0bfa1c8199471ccdada0125e69ba938d0ac7adeb62c36adb0bdcdeccb2b7a43a18f6090c467f1d564a13b2d0c7db52678806f944fc59c212df
|
data/LICENSE
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but not
|
|
32
|
+
limited to compiled object code, generated documentation, and
|
|
33
|
+
conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the
|
|
48
|
+
original version of the Work and any modifications or additions
|
|
49
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
50
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
51
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
52
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
53
|
+
means any form of electronic, verbal, or written communication sent
|
|
54
|
+
to the Licensor or its representatives, including but not limited to
|
|
55
|
+
communication on electronic mailing lists, source code control systems,
|
|
56
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
57
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
58
|
+
excluding communication that is conspicuously marked or otherwise
|
|
59
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
62
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
63
|
+
subsequently incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
66
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
67
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
68
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
69
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
70
|
+
Work and such Derivative Works in Source or Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
(except as stated in this section) patent license to make, have made,
|
|
76
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
77
|
+
where such license applies only to those patent claims licensable
|
|
78
|
+
by such Contributor that are necessarily infringed by their
|
|
79
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
80
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
81
|
+
institute patent litigation against any entity (including a
|
|
82
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
83
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
84
|
+
or contributory patent infringement, then any patent licenses
|
|
85
|
+
granted to You under this License for that Work shall terminate
|
|
86
|
+
as of the date such litigation is filed.
|
|
87
|
+
|
|
88
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
89
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
90
|
+
modifications, and in Source or Object form, provided that You
|
|
91
|
+
meet the following conditions:
|
|
92
|
+
|
|
93
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
94
|
+
Works a copy of this License; and
|
|
95
|
+
|
|
96
|
+
(b) You must cause any modified files to carry prominent notices
|
|
97
|
+
stating that You changed the files; and
|
|
98
|
+
|
|
99
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
100
|
+
that You distribute, all copyright, patent, trademark, and
|
|
101
|
+
attribution notices from the Source form of the Work; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, then any Derivative Works that You distribute must
|
|
105
|
+
include a readable copy of the attribution notices contained
|
|
106
|
+
within such NOTICE file.
|
|
107
|
+
|
|
108
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
109
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
110
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
111
|
+
this License, without any additional terms or conditions.
|
|
112
|
+
|
|
113
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
114
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
115
|
+
except as required for reasonable and customary use in describing the
|
|
116
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
117
|
+
|
|
118
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
119
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
120
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
121
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
122
|
+
without limitation, any warranties or conditions of TITLE,
|
|
123
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
124
|
+
PURPOSE. You are solely responsible for determining the
|
|
125
|
+
appropriateness of using or redistributing the Work.
|
|
126
|
+
|
|
127
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
128
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
129
|
+
unless required by applicable law (such as deliberate and grossly
|
|
130
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
131
|
+
liable to You for damages, including any direct, indirect, special,
|
|
132
|
+
incidental, or consequential damages of any character arising as a
|
|
133
|
+
result of this License or out of the use or inability to use the
|
|
134
|
+
Work.
|
|
135
|
+
|
|
136
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
137
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
138
|
+
charge a fee for, acceptance of support, warranty, indemnity, or
|
|
139
|
+
other liability obligations and/or rights consistent with this
|
|
140
|
+
License. However, in accepting such obligations, You may act only
|
|
141
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
142
|
+
of any other Contributor.
|
|
143
|
+
|
|
144
|
+
END OF TERMS AND CONDITIONS
|
|
145
|
+
|
|
146
|
+
Copyright 2026 Melaya (Antoine Roche)
|
|
147
|
+
|
|
148
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
149
|
+
you may not use this file except in compliance with the License.
|
|
150
|
+
You may obtain a copy of the License at
|
|
151
|
+
|
|
152
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
153
|
+
|
|
154
|
+
Unless required by applicable law or agreed to in writing, software
|
|
155
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
156
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
157
|
+
See the License for the specific language governing permissions and
|
|
158
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# melaya
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Current production scope:** Agent Builder and Mobile Device Control are available now. Melaya Trading namespaces are preview-only and not generally available; do not use them with real funds.
|
|
4
|
+
|
|
5
|
+
Official SDK for the **[Melaya](https://melaya.org)** Agent Builder and flagship Mobile Device Control APIs. Trading namespaces are included only as a preview of a later product.
|
|
4
6
|
|
|
5
7
|
- Zero runtime gem dependencies (stdlib `net/http`, `openssl`, `json` only).
|
|
8
|
+
- Full Agent Builder lifecycle: projects, pipelines, templates, Connectors, HITL, evals, events, billing, team, and runner management.
|
|
9
|
+
- Catalogs of **1,500+ scoped tools**, **100+ specialized subagents**, and **20+ model providers** (runtime catalog endpoints are the source of truth).
|
|
6
10
|
- Pure Ruby WebSocket client (RFC 6455) — no external gem required for streaming.
|
|
7
|
-
- Full market data, strategies, sim trading, backtesting, and streaming from one client.
|
|
8
11
|
|
|
9
12
|
## Install
|
|
10
13
|
|
|
@@ -20,7 +23,66 @@ Or once published to RubyGems:
|
|
|
20
23
|
gem install melaya
|
|
21
24
|
```
|
|
22
25
|
|
|
23
|
-
##
|
|
26
|
+
## Agent Builder & Device Control
|
|
27
|
+
|
|
28
|
+
### Quick start: pair a phone
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
require "melaya"
|
|
32
|
+
|
|
33
|
+
melaya = Melaya::Client.new(api_key: ENV["MELAYA_API_KEY"]) # keys are prefixed mk_
|
|
34
|
+
|
|
35
|
+
pairing = melaya.agents.phone.pair
|
|
36
|
+
puts "Pairing code: #{pairing["code"]} (expires in #{pairing["expiresInSeconds"]}s)"
|
|
37
|
+
# Enter the code in the Melaya APK on the phone
|
|
38
|
+
|
|
39
|
+
devices = melaya.agents.phone.list_devices
|
|
40
|
+
apps = melaya.agents.phone.list_apps
|
|
41
|
+
|
|
42
|
+
melaya.agents.phone.set_allowed_apps(["com.android.chrome"])
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
A Melaya platform key is required. "No app API required" means Device Control operates the target app through its user interface; it does not mean the Melaya SDK is unauthenticated.
|
|
46
|
+
|
|
47
|
+
### Quick start: run an agent pipeline
|
|
48
|
+
|
|
49
|
+
Configure provider credentials through Melaya Connectors first. Never include a provider key in pipeline configuration or per-run overrides.
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
melaya.agents.pipelines.create(
|
|
53
|
+
name: "mobile-review",
|
|
54
|
+
project: "Operations",
|
|
55
|
+
model_provider: "anthropic",
|
|
56
|
+
model_name: "claude-sonnet-4-6",
|
|
57
|
+
agents: [{
|
|
58
|
+
"name" => "mobile-operator",
|
|
59
|
+
"role" => "Careful mobile operator",
|
|
60
|
+
"instruction" => "Read before acting. Never send, publish, or delete.",
|
|
61
|
+
"agent_tools" => [
|
|
62
|
+
"phone_get_screen_tree",
|
|
63
|
+
"phone_current_app",
|
|
64
|
+
"phone_open_app",
|
|
65
|
+
"phone_click_text",
|
|
66
|
+
"phone_back",
|
|
67
|
+
"phone_wait"
|
|
68
|
+
]
|
|
69
|
+
}],
|
|
70
|
+
steps: [{ "kind" => "agent", "agent" => { "name" => "mobile-operator" } }],
|
|
71
|
+
maxCostUsd: 1.00
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
run = melaya.agents.pipelines.run("mobile-review", project: "Operations")
|
|
75
|
+
run_id = run["run_id"]
|
|
76
|
+
|
|
77
|
+
melaya.agents.phone.register_active_run(run_id)
|
|
78
|
+
|
|
79
|
+
status = melaya.agents.pipelines.run_status("mobile-review", run_id)
|
|
80
|
+
|
|
81
|
+
# Real-time run events over Socket.IO (connects lazily on first use)
|
|
82
|
+
melaya.events.on_run_update(run_id) { |e| puts e["event_type"] }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Trading quick start (preview)
|
|
24
86
|
|
|
25
87
|
```ruby
|
|
26
88
|
require "melaya"
|
|
@@ -38,7 +100,7 @@ ob = melaya.market.orderbook(exchange: "bybit", symbol: "BTC/USDT", market: "spo
|
|
|
38
100
|
candles = melaya.market.ohlcv(exchange: "okx", symbol: "ETH/USDT", timeframe: "1h", limit: 200)
|
|
39
101
|
```
|
|
40
102
|
|
|
41
|
-
## Streaming
|
|
103
|
+
## Streaming (preview)
|
|
42
104
|
|
|
43
105
|
```ruby
|
|
44
106
|
# Live ticker (block form — closes when block returns)
|
|
@@ -54,7 +116,7 @@ melaya.stream.liquidations(exchange: "binance") do |ev|
|
|
|
54
116
|
end
|
|
55
117
|
```
|
|
56
118
|
|
|
57
|
-
## Trading
|
|
119
|
+
## Trading (preview)
|
|
58
120
|
|
|
59
121
|
```ruby
|
|
60
122
|
# Account: connected exchange keys and usage
|
|
@@ -126,21 +188,40 @@ melaya.strategies.delete(sid)
|
|
|
126
188
|
|
|
127
189
|
## Authentication
|
|
128
190
|
|
|
129
|
-
Create an API key in the dashboard (**melaya.org → Settings → API Keys**). Keys are prefixed `mk_
|
|
191
|
+
Create an API key in the dashboard (**melaya.org → Settings → API Keys**). Keys are prefixed `mk_`. Every REST call sends the key **only** as an `Authorization: Bearer mk_...` header — never in the URL query string. Public WebSocket market-data streams authenticate with `?apiKey=` in the `wss://` URL (server protocol); private WebSocket streams instead use a short-lived `?wsTicket=` that the SDK mints automatically.
|
|
130
192
|
|
|
131
193
|
Public market-data and account/strategy reads work with the `mk_` key alone. **Live** order placement and live strategy launches additionally require a connected exchange key — connect one in **Settings → Connectors**, then reference it by `apiKeyId`. Paper trading and backtesting never touch a venue and need no exchange credentials.
|
|
132
194
|
|
|
133
|
-
##
|
|
134
|
-
|
|
135
|
-
The SDK verifies TLS certificates by default. To disable on a dev box with TLS interception:
|
|
136
|
-
|
|
137
|
-
```bash
|
|
138
|
-
MELAYA_INSECURE_TLS=1 ruby your_script.rb
|
|
139
|
-
```
|
|
195
|
+
## API surface
|
|
140
196
|
|
|
141
|
-
|
|
197
|
+
### Agent Builder & platform (GA)
|
|
142
198
|
|
|
143
|
-
|
|
199
|
+
| Area | Methods |
|
|
200
|
+
|---|---|
|
|
201
|
+
| Auth | `auth.login`, `verify_mfa`, `register`, `verify_signup`, `resend_verification`, `me`, `check`, `change_password`, `forgot_password`, `reset_password`, `mobile_handoff`, `permissions`, `refresh` |
|
|
202
|
+
| MFA | `auth.mfa_status`, `mfa_setup`, `mfa_confirm` (also via `melaya.platform.mfa`) |
|
|
203
|
+
| Projects | `projects.list`, `create`, `rename`, `runner_projects` |
|
|
204
|
+
| Connectors | `connectors.connected_services`, `set`, `delete`, `env_handle`, `google_oauth_start` |
|
|
205
|
+
| Credentials | `credentials.list`, `connected_services`, `get`, `set`, `delete`, `test`, `list_models`, plus operator-profile, OAuth, and RAG helpers |
|
|
206
|
+
| Pipelines | `pipelines.create`, `get`, `update`, `delete_pipeline`, `list_pipelines`, `run`, `run_ids`, `run_status`, `cancel_run`, `outputs`, `output`, `preview_code`, `tools`, `subagents`, `instantiate_template`, `build_with_ai` |
|
|
207
|
+
| Runs & traces | `pipelines.list`, `recent`, `count`, `traces`, `trace`, `trace_stats`, `delete_traces` |
|
|
208
|
+
| Schedules | `pipelines.list_schedules`, `get_schedule`, `upsert_schedule`, `pause_schedule`, `resume_schedule` |
|
|
209
|
+
| Overview | `pipelines.overview`, `model_prices`, `chart_data`, `cost_breakdown`, `server_version` |
|
|
210
|
+
| Templates | `templates.list`, `list_global`, `list_validated`, `save`, `update`, `duplicate`, `delete`, `share`, `share_targets`, `list_assignments`, `assign(id, user_id:` \| `project_id:)`, `unassign(id, user_id:` \| `project_id:)` |
|
|
211
|
+
| Phone | `phone.pair`, `list_devices`, `revoke_device`, `screen_tree`, `list_apps`, `set_allowed_apps`, `register_active_run` |
|
|
212
|
+
| HITL | `hitl.pending`, `history`, `approve`, `reject`, `bulk_decide`, `run_tool_stats`, `run_tool_stats_by_agent`, `run_messages`, `run_tool_calls` |
|
|
213
|
+
| Evals | `evals.list_runs`, `summary`, `run_detail`, `compare`, `memory_graph`, `run_memory`, `crew_memory`, `benchmarks` |
|
|
214
|
+
| Events | `events.on_run_update`, `on_init_phase`, `on_project_event`, `on_hitl_approval`, `on_pipeline_created`, `on_pipeline_updated`, `on_pipeline_deleted`, `leave_run`, `leave_project`, `close` |
|
|
215
|
+
| Billing | `billing.subscription`, `create_checkout`, `create_portal`, `plans`, `credits`, `ai_credits`, `portfolio_ideas_credits`, `risk_monitoring_credits` |
|
|
216
|
+
| Accounts | `accounts.export_data`, `remove_key`, `update_profile` |
|
|
217
|
+
| Runner | `runner.create_token`, `list_tokens`, `revoke_token` |
|
|
218
|
+
| Team | `team.list_members`, `invite`, `create_invite_link`, `accept_invite`, `update_member_role`, `remove_member`, `get_pipeline_visibility`, `set_pipeline_visibility` |
|
|
219
|
+
| Assistant | `assistant.get_profile`, `set_profile` |
|
|
220
|
+
| Bugs | `bugs.create`, `list_mine`, `get`, `add_comment`, `list_notifications`, `mark_notifications_read` |
|
|
221
|
+
|
|
222
|
+
Every area is also reachable through the domain namespaces: `melaya.agents.*` (pipelines/runs, hitl, assistant, phone, evals, models) and `melaya.platform.*` (projects, credentials, connectors, billing, team, templates, overview, runner, auth, mfa, accounts, bugs, events).
|
|
223
|
+
|
|
224
|
+
### Trading (preview — not generally available)
|
|
144
225
|
|
|
145
226
|
| Area | Methods |
|
|
146
227
|
|---|---|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Melaya
|
|
4
|
+
# Accounts API — GDPR data export, API key management, and profile updates.
|
|
5
|
+
#
|
|
6
|
+
# Maps to /api/v1/private/accounts/* and /api/v1/private/keys/*.
|
|
7
|
+
#
|
|
8
|
+
# Note: credit balance endpoints live in BillingAPI to keep billing concerns
|
|
9
|
+
# co-located. Key listing is in AccountAPI (trading plane) for backward
|
|
10
|
+
# compatibility; this module covers the write/management side.
|
|
11
|
+
class AccountsAPI
|
|
12
|
+
def initialize(http)
|
|
13
|
+
@http = http
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# POST /api/v1/private/accounts/export
|
|
17
|
+
# GDPR Art 15/20 data export; returns JSON blob of all user data.
|
|
18
|
+
def export_data
|
|
19
|
+
@http.post("/api/v1/private/accounts/export")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# DELETE /api/v1/private/keys/:keyId
|
|
23
|
+
# Remove a stored CEX API key.
|
|
24
|
+
# @param key_id [String]
|
|
25
|
+
def remove_key(key_id)
|
|
26
|
+
@http.delete("/api/v1/private/keys/#{enc(key_id)}")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# PATCH /api/v1/private/accounts/profile
|
|
30
|
+
# Update user display name, avatar, or settings.
|
|
31
|
+
# @param body [Hash]
|
|
32
|
+
def update_profile(body = {})
|
|
33
|
+
@http.patch("/api/v1/private/accounts/profile", body)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def enc(s)
|
|
39
|
+
URI.encode_www_form_component(s.to_s)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Melaya
|
|
4
|
+
# Assistant API — get and save the caller's onboarding / persona profile.
|
|
5
|
+
#
|
|
6
|
+
# The profile is stored envelope-encrypted (service=assistant_profile) and
|
|
7
|
+
# used to personalise the in-app assistant experience.
|
|
8
|
+
#
|
|
9
|
+
# Maps to /api/v1/private/assistant/profile.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# profile = melaya.assistant.get_profile
|
|
13
|
+
# melaya.assistant.set_profile(name: "Antoine", goals: ["grow my trading edge"])
|
|
14
|
+
class AssistantAPI
|
|
15
|
+
def initialize(http)
|
|
16
|
+
@http = http
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# GET /api/v1/private/assistant/profile
|
|
20
|
+
# Get the caller's assistant onboarding profile.
|
|
21
|
+
def get_profile
|
|
22
|
+
@http.get("/api/v1/private/assistant/profile")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# PUT /api/v1/private/assistant/profile
|
|
26
|
+
# Save the caller's assistant onboarding profile.
|
|
27
|
+
# @param name [String, nil]
|
|
28
|
+
# @param goals [Array<String>, nil]
|
|
29
|
+
# @param context [String, nil]
|
|
30
|
+
# @param preferences [Hash, nil]
|
|
31
|
+
# @param extra [Hash] any additional profile fields
|
|
32
|
+
def set_profile(name: nil, goals: nil, context: nil, preferences: nil, **extra)
|
|
33
|
+
profile = extra.transform_keys(&:to_s)
|
|
34
|
+
profile["name"] = name unless name.nil?
|
|
35
|
+
profile["goals"] = goals unless goals.nil?
|
|
36
|
+
profile["context"] = context unless context.nil?
|
|
37
|
+
profile["preferences"] = preferences unless preferences.nil?
|
|
38
|
+
@http.put("/api/v1/private/assistant/profile", profile)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/melaya/auth.rb
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Melaya
|
|
4
|
+
# Auth API — login, MFA, registration, password management, and session tokens.
|
|
5
|
+
#
|
|
6
|
+
# Most endpoints are public (no Bearer token needed for login/register).
|
|
7
|
+
# However, the SDK HttpClient always sends the mk_* API key which is fine —
|
|
8
|
+
# the server simply ignores it for public routes.
|
|
9
|
+
#
|
|
10
|
+
# Maps to /api/v1/private/auth/* and /api/v1/auth/*.
|
|
11
|
+
class AuthAPI
|
|
12
|
+
def initialize(http)
|
|
13
|
+
@http = http
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# POST /api/v1/private/auth/login
|
|
17
|
+
# Password + username login; returns session JWT + optional MFA challenge token.
|
|
18
|
+
# @param username [String]
|
|
19
|
+
# @param password [String]
|
|
20
|
+
def login(username:, password:)
|
|
21
|
+
@http.post("/api/v1/private/auth/login",
|
|
22
|
+
"username" => username,
|
|
23
|
+
"password" => password)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# POST /api/v1/private/auth/mfa/verify
|
|
27
|
+
# Resolve MFA challenge after login.
|
|
28
|
+
# @param challenge_token [String]
|
|
29
|
+
# @param code [String] TOTP or recovery code
|
|
30
|
+
def verify_mfa(challenge_token:, code:)
|
|
31
|
+
@http.post("/api/v1/private/auth/mfa/verify",
|
|
32
|
+
"challengeToken" => challenge_token,
|
|
33
|
+
"code" => code)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# POST /api/v1/private/auth/register
|
|
37
|
+
# Create a new user account; sends email verification.
|
|
38
|
+
def register(username:, email:, password:)
|
|
39
|
+
@http.post("/api/v1/private/auth/register",
|
|
40
|
+
"username" => username,
|
|
41
|
+
"email" => email,
|
|
42
|
+
"password" => password)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# POST /api/v1/private/auth/verify-signup
|
|
46
|
+
# Confirm email address from signup link token.
|
|
47
|
+
# @param token [String]
|
|
48
|
+
def verify_signup(token:)
|
|
49
|
+
@http.post("/api/v1/private/auth/verify-signup", "token" => token)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# POST /api/v1/private/auth/resend-verification
|
|
53
|
+
# Re-send email verification message.
|
|
54
|
+
# @param email [String]
|
|
55
|
+
def resend_verification(email:)
|
|
56
|
+
@http.post("/api/v1/private/auth/resend-verification", "email" => email)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# GET /api/v1/private/auth/me
|
|
60
|
+
# Return current authenticated user profile.
|
|
61
|
+
def me
|
|
62
|
+
@http.get("/api/v1/private/auth/me")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# GET /api/v1/private/auth/check
|
|
66
|
+
# Lightweight session validity check; returns ok: true.
|
|
67
|
+
def check
|
|
68
|
+
@http.get("/api/v1/private/auth/check")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# POST /api/v1/private/auth/change-password
|
|
72
|
+
# Change password (current + new).
|
|
73
|
+
# @param current_password [String]
|
|
74
|
+
# @param new_password [String]
|
|
75
|
+
def change_password(current_password:, new_password:)
|
|
76
|
+
@http.post("/api/v1/private/auth/change-password",
|
|
77
|
+
"currentPassword" => current_password,
|
|
78
|
+
"newPassword" => new_password)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# POST /api/v1/private/auth/forgot-password
|
|
82
|
+
# Initiate password reset flow; sends email with reset token.
|
|
83
|
+
# @param email [String]
|
|
84
|
+
def forgot_password(email:)
|
|
85
|
+
@http.post("/api/v1/private/auth/forgot-password", "email" => email)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# POST /api/v1/private/auth/reset-password
|
|
89
|
+
# Complete password reset using token from email.
|
|
90
|
+
# @param token [String]
|
|
91
|
+
# @param new_password [String]
|
|
92
|
+
def reset_password(token:, new_password:)
|
|
93
|
+
@http.post("/api/v1/private/auth/reset-password",
|
|
94
|
+
"token" => token,
|
|
95
|
+
"newPassword" => new_password)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# POST /api/v1/private/auth/mobile-handoff
|
|
99
|
+
# Create a short-lived handoff token for mobile app deep-link auth.
|
|
100
|
+
def mobile_handoff
|
|
101
|
+
@http.post("/api/v1/private/auth/mobile-handoff")
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# GET /api/v1/private/auth/permissions
|
|
105
|
+
# Return caller's permission flags (capabilities, tier, feature gates).
|
|
106
|
+
def permissions
|
|
107
|
+
@http.get("/api/v1/private/auth/permissions")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# POST /api/v1/private/auth/refresh
|
|
111
|
+
# Rotate session JWT (sliding expiry); returns new token.
|
|
112
|
+
def refresh
|
|
113
|
+
@http.post("/api/v1/private/auth/refresh")
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# ── MFA ───────────────────────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
# GET /api/v1/private/mfa/status
|
|
119
|
+
# Return MFA enrollment status for the caller.
|
|
120
|
+
def mfa_status
|
|
121
|
+
@http.get("/api/v1/private/mfa/status")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# POST /api/v1/private/mfa/setup
|
|
125
|
+
# Initiate TOTP setup; returns QR/secret.
|
|
126
|
+
def mfa_setup
|
|
127
|
+
@http.post("/api/v1/private/mfa/setup")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# POST /api/v1/private/mfa/confirm
|
|
131
|
+
# Confirm TOTP setup with first valid code; activates MFA.
|
|
132
|
+
# @param code [String]
|
|
133
|
+
def mfa_confirm(code:)
|
|
134
|
+
@http.post("/api/v1/private/mfa/confirm", "code" => code)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
data/lib/melaya/backtest.rb
CHANGED
|
@@ -97,5 +97,43 @@ module Melaya
|
|
|
97
97
|
def delete_all
|
|
98
98
|
@http.delete("/api/v1/private/backtest")
|
|
99
99
|
end
|
|
100
|
+
|
|
101
|
+
# ── Parameter sweep optimizer (restRoutes.ts /api/v1/private/backtest/optimize) ──
|
|
102
|
+
|
|
103
|
+
# POST /api/v1/private/backtest/optimize
|
|
104
|
+
# Start a parameter sweep optimization (genetic/grid) over a strategy config.
|
|
105
|
+
# @param body [Hash] strategy config + param ranges + objective
|
|
106
|
+
def optimize_start(body)
|
|
107
|
+
@http.post("/api/v1/private/backtest/optimize", body)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# GET /api/v1/private/backtest/optimize
|
|
111
|
+
# List optimization sweep runs.
|
|
112
|
+
# @param params [Hash]
|
|
113
|
+
def optimize_list(params = {})
|
|
114
|
+
@http.get("/api/v1/private/backtest/optimize", params)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# GET /api/v1/private/backtest/optimize/:optRunId/status
|
|
118
|
+
# Get the status/progress of an optimization sweep run.
|
|
119
|
+
# @param opt_run_id [String]
|
|
120
|
+
def optimize_status(opt_run_id)
|
|
121
|
+
@http.get("/api/v1/private/backtest/optimize/#{URI.encode_www_form_component(opt_run_id.to_s)}/status")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# POST /api/v1/private/backtest/optimize/:optRunId/cancel
|
|
125
|
+
# Cancel an in-progress optimization sweep.
|
|
126
|
+
# @param opt_run_id [String]
|
|
127
|
+
def optimize_cancel(opt_run_id)
|
|
128
|
+
@http.post("/api/v1/private/backtest/optimize/#{URI.encode_www_form_component(opt_run_id.to_s)}/cancel")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# POST /api/v1/private/backtest/optimize/:optRunId/apply
|
|
132
|
+
# Apply best params from a completed optimization sweep to a strategy.
|
|
133
|
+
# @param opt_run_id [String]
|
|
134
|
+
# @param body [Hash]
|
|
135
|
+
def optimize_apply(opt_run_id, body = {})
|
|
136
|
+
@http.post("/api/v1/private/backtest/optimize/#{URI.encode_www_form_component(opt_run_id.to_s)}/apply", body)
|
|
137
|
+
end
|
|
100
138
|
end
|
|
101
139
|
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Melaya
|
|
4
|
+
# Billing API — subscription status, Stripe checkout/portal sessions,
|
|
5
|
+
# public pricing plans, and credit balances.
|
|
6
|
+
#
|
|
7
|
+
# Maps to /api/v1/private/billing/* (authenticated) and
|
|
8
|
+
# /api/v1/billing/plans (public), and /api/v1/private/accounts/* for credits.
|
|
9
|
+
class BillingAPI
|
|
10
|
+
def initialize(http)
|
|
11
|
+
@http = http
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# GET /api/v1/private/billing/subscription
|
|
15
|
+
# Get caller's current Stripe subscription status and tier.
|
|
16
|
+
def subscription
|
|
17
|
+
@http.get("/api/v1/private/billing/subscription")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# POST /api/v1/private/billing/checkout
|
|
21
|
+
# Create Stripe Checkout session for tier upgrade.
|
|
22
|
+
# Returns a URL to redirect the user to.
|
|
23
|
+
# @param price_id [String, nil] Stripe price ID
|
|
24
|
+
# @param tier [String, nil]
|
|
25
|
+
def create_checkout(price_id: nil, tier: nil)
|
|
26
|
+
body = compact("priceId" => price_id, "tier" => tier)
|
|
27
|
+
@http.post("/api/v1/private/billing/checkout", body)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# POST /api/v1/private/billing/portal
|
|
31
|
+
# Create Stripe Customer Portal session for subscription management.
|
|
32
|
+
# Returns a URL to redirect the user to.
|
|
33
|
+
def create_portal
|
|
34
|
+
@http.post("/api/v1/private/billing/portal")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# GET /api/v1/billing/plans (public)
|
|
38
|
+
# Return public pricing plan details (price IDs for forge/bastion/citadel tiers).
|
|
39
|
+
def plans
|
|
40
|
+
@http.get("/api/v1/billing/plans")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# ── Credits ───────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
# GET /api/v1/private/accounts/credits
|
|
46
|
+
# Return current credit balance and transaction history.
|
|
47
|
+
def credits
|
|
48
|
+
@http.get("/api/v1/private/accounts/credits")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# GET /api/v1/private/accounts/credits/ai
|
|
52
|
+
# Return AI/LLM credit balance.
|
|
53
|
+
def ai_credits
|
|
54
|
+
@http.get("/api/v1/private/accounts/credits/ai")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# GET /api/v1/private/accounts/credits/portfolio-ideas
|
|
58
|
+
# Return portfolio-ideas feature credit balance.
|
|
59
|
+
def portfolio_ideas_credits
|
|
60
|
+
@http.get("/api/v1/private/accounts/credits/portfolio-ideas")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# GET /api/v1/private/accounts/credits/risk-monitoring
|
|
64
|
+
# Return risk-monitoring feature credit balance.
|
|
65
|
+
def risk_monitoring_credits
|
|
66
|
+
@http.get("/api/v1/private/accounts/credits/risk-monitoring")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def compact(hash)
|
|
72
|
+
hash.reject { |_, v| v.nil? }
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|