Class: Melaya::BacktestAPI
- Inherits:
-
Object
- Object
- Melaya::BacktestAPI
- Defined in:
- lib/melaya/backtest.rb
Overview
Backtest API — run strategies against historical data on the Rust engine.
Start a single run or a parameter sweep (grid / random), poll the job, then pull metrics, the equity curve, and the trade list. All backtests run natively on Melaya’s in-house engine — no per-venue SDK in the loop.
Maps to api.melaya.org/api/v1/private/backtest/* on the private plane.
Instance Method Summary collapse
-
#cancel(job_id) ⇒ Object
Cancel an in-flight job.
-
#delete(job_id) ⇒ Object
Soft-delete a single job.
-
#delete_all ⇒ Object
Soft-delete every non-favorited job.
-
#favorites(limit: nil, offset: nil) ⇒ Object
Your favorited backtest jobs (Forge tier and above).
-
#funding_range(exchange:, symbol:) ⇒ Object
Earliest funding-rate timestamp available for an exchange+symbol (ms, or nil).
-
#initialize(http) ⇒ BacktestAPI
constructor
A new instance of BacktestAPI.
-
#job(job_id) ⇒ Object
Job status + progress (
status,progress_pct, …). -
#list(limit: nil, offset: nil) ⇒ Object
Your backtest jobs, newest first.
-
#results(job_id) ⇒ Object
Metrics, equity curve, and OHLCV for a completed job.
-
#start(body) ⇒ Object
Start a backtest.
-
#sweep(parent_id, objective: nil, limit: nil) ⇒ Object
Ranked children of a sweep parent (default objective: sharpe DESC).
-
#trades(job_id, limit: nil, offset: nil) ⇒ Object
The trade list for a completed job (default 500, max 5000 per call).
Constructor Details
#initialize(http) ⇒ BacktestAPI
Returns a new instance of BacktestAPI.
12 13 14 |
# File 'lib/melaya/backtest.rb', line 12 def initialize(http) @http = http end |
Instance Method Details
#cancel(job_id) ⇒ Object
Cancel an in-flight job.
86 87 88 |
# File 'lib/melaya/backtest.rb', line 86 def cancel(job_id) @http.post("/api/v1/private/backtest/#{job_id}/cancel") end |
#delete(job_id) ⇒ Object
Soft-delete a single job.
92 93 94 |
# File 'lib/melaya/backtest.rb', line 92 def delete(job_id) @http.delete("/api/v1/private/backtest/#{job_id}") end |
#delete_all ⇒ Object
Soft-delete every non-favorited job. Returns a hash with “deleted” count.
97 98 99 |
# File 'lib/melaya/backtest.rb', line 97 def delete_all @http.delete("/api/v1/private/backtest") end |
#favorites(limit: nil, offset: nil) ⇒ Object
Your favorited backtest jobs (Forge tier and above).
69 70 71 72 73 |
# File 'lib/melaya/backtest.rb', line 69 def favorites(limit: nil, offset: nil) @http.get("/api/v1/private/backtest/favorites", "limit" => limit, "offset" => offset ).dig("data", "jobs") end |
#funding_range(exchange:, symbol:) ⇒ Object
Earliest funding-rate timestamp available for an exchange+symbol (ms, or nil).
78 79 80 81 82 |
# File 'lib/melaya/backtest.rb', line 78 def funding_range(exchange:, symbol:) @http.get("/api/v1/private/backtest/funding-range", "exchange" => exchange, "symbol" => symbol )["earliest_ms"] end |
#job(job_id) ⇒ Object
Job status + progress (status, progress_pct, …).
27 28 29 |
# File 'lib/melaya/backtest.rb', line 27 def job(job_id) @http.get("/api/v1/private/backtest/jobs/#{job_id}") end |
#list(limit: nil, offset: nil) ⇒ Object
Your backtest jobs, newest first.
60 61 62 63 64 |
# File 'lib/melaya/backtest.rb', line 60 def list(limit: nil, offset: nil) @http.get("/api/v1/private/backtest", "limit" => limit, "offset" => offset ).dig("data", "jobs") end |
#results(job_id) ⇒ Object
Metrics, equity curve, and OHLCV for a completed job.
33 34 35 |
# File 'lib/melaya/backtest.rb', line 33 def results(job_id) @http.get("/api/v1/private/backtest/results/#{job_id}")["result"] end |
#start(body) ⇒ Object
Start a backtest. mode defaults to a single run; pass “grid_sweep” / “random_sweep” with param_ranges to fan out a parameter search. Returns a hash with “job_id” (and optionally “count”).
21 22 23 |
# File 'lib/melaya/backtest.rb', line 21 def start(body) @http.post("/api/v1/private/backtest/start", body) end |
#sweep(parent_id, objective: nil, limit: nil) ⇒ Object
Ranked children of a sweep parent (default objective: sharpe DESC).
51 52 53 54 55 |
# File 'lib/melaya/backtest.rb', line 51 def sweep(parent_id, objective: nil, limit: nil) @http.get("/api/v1/private/backtest/sweep/#{parent_id}", "objective" => objective, "limit" => limit ) end |
#trades(job_id, limit: nil, offset: nil) ⇒ Object
The trade list for a completed job (default 500, max 5000 per call).
41 42 43 44 45 |
# File 'lib/melaya/backtest.rb', line 41 def trades(job_id, limit: nil, offset: nil) @http.get("/api/v1/private/backtest/trades/#{job_id}", "limit" => limit, "offset" => offset )["trades"] end |