Class: Melaya::MarketAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/melaya/market.rb

Overview

REST market-data API — normalized across all 70+ venues.

Every method maps to a documented endpoint under api.melaya.org/api/v1/market/*. Unwraps the inner data key from the <data> envelope.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ MarketAPI

Returns a new instance of MarketAPI.



10
11
12
# File 'lib/melaya/market.rb', line 10

def initialize(http)
  @http = http
end

Instance Method Details

#catalog_countsObject

Live platform catalog counts (agentic tools, subagents, by category). Public.



146
147
148
# File 'lib/melaya/market.rb', line 146

def catalog_counts
  @http.get("/api/v1/public/catalog-counts")
end

#currencies(exchange:) ⇒ Object

Listed currencies on a venue. (Not supported on every venue.)



57
58
59
# File 'lib/melaya/market.rb', line 57

def currencies(exchange:)
  @http.get("/api/v1/market/currencies", "exchange" => exchange)["currencies"]
end

#funding_rate_history(exchange:, symbol:, hours: nil, market: nil) ⇒ Object

Funding-rate history.



86
87
88
89
# File 'lib/melaya/market.rb', line 86

def funding_rate_history(exchange:, symbol:, hours: nil, market: nil)
  body = compact("exchange" => exchange, "symbol" => symbol, "hours" => hours, "market" => market)
  @http.post("/api/v1/market/funding-rate-history", body)["history"]
end

#funding_rate_history_multi(exchanges:, symbol:, hours: nil) ⇒ Object

Funding-rate history for one symbol across several venues. Keyed by exchange.



129
130
131
132
# File 'lib/melaya/market.rb', line 129

def funding_rate_history_multi(exchanges:, symbol:, hours: nil)
  body = compact("exchanges" => exchanges, "symbol" => symbol, "hours" => hours)
  @http.post("/api/v1/market/funding-rate-history-multi", body)["perExchange"]
end

#funding_rates(exchange:, symbols:, market: nil) ⇒ Object

Latest funding rates for perpetuals. Keyed by symbol.



80
81
82
83
# File 'lib/melaya/market.rb', line 80

def funding_rates(exchange:, symbols:, market: nil)
  body = compact("exchange" => exchange, "symbols" => symbols, "market" => market)
  @http.post("/api/v1/market/funding-rates", body)["rates"]
end

#instruments(exchange:, market: nil) ⇒ Object

Instrument list + trading constraints (tick size, min notional, qty step).



104
105
106
107
# File 'lib/melaya/market.rb', line 104

def instruments(exchange:, market: nil)
  body = compact("exchange" => exchange, "market" => market)
  @http.post("/api/v1/market/instruments", body)
end

#liquidation_events(exchange: nil, symbol: nil, since_ms: nil, limit: nil) ⇒ Object

Cross-exchange liquidation events (historical query).



110
111
112
113
# File 'lib/melaya/market.rb', line 110

def liquidation_events(exchange: nil, symbol: nil, since_ms: nil, limit: nil)
  body = compact("exchange" => exchange, "symbol" => symbol, "sinceMs" => since_ms, "limit" => limit)
  @http.post("/api/v1/market/liquidation-events", body)["events"]
end

#list_exchangesObject

List the exchanges Melaya supports right now (the source of truth).



15
16
17
# File 'lib/melaya/market.rb', line 15

def list_exchanges
  @http.get("/api/v1/market/list-exchanges")["exchanges"]
end

#market_constraints(exchange:, symbol:, market: nil) ⇒ Object

Trading constraints for one symbol (tick size, min notional, qty step, leverage).



123
124
125
126
# File 'lib/melaya/market.rb', line 123

def market_constraints(exchange:, symbol:, market: nil)
  body = compact("exchange" => exchange, "symbol" => symbol, "market" => market)
  @http.post("/api/v1/market/market-constraints", body)["constraints"]
end

#markets(exchange:) ⇒ Object

Tradable markets on a venue.



52
53
54
# File 'lib/melaya/market.rb', line 52

def markets(exchange:)
  @http.get("/api/v1/market/markets", "exchange" => exchange)["markets"]
end

#ohlcv(exchange:, symbol:, timeframe:, limit: nil, market: nil) ⇒ Object

OHLCV candles. Each candle is [timestamp, open, high, low, close, volume].



37
38
39
40
41
42
# File 'lib/melaya/market.rb', line 37

def ohlcv(exchange:, symbol:, timeframe:, limit: nil, market: nil)
  @http.get("/api/v1/market/ohlcv",
    "exchange" => exchange, "symbol" => symbol, "timeframe" => timeframe,
    "limit" => limit, "market" => market
  )["candles"]
end

#ohlcv_multi(exchange:, symbols:, timeframe:, limit: nil, market: nil) ⇒ Object

Multi-symbol OHLCV in one call. Returns candle arrays keyed by symbol.



116
117
118
119
120
# File 'lib/melaya/market.rb', line 116

def ohlcv_multi(exchange:, symbols:, timeframe:, limit: nil, market: nil)
  body = compact("exchange" => exchange, "symbols" => symbols, "timeframe" => timeframe,
                 "limit" => limit, "market" => market)
  @http.post("/api/v1/market/ohlcv-multi", body)["perSymbol"]
end

#open_interest(exchange:, symbols:, market: nil) ⇒ Object

Open interest for one or more perpetuals. Keyed by symbol.



92
93
94
95
# File 'lib/melaya/market.rb', line 92

def open_interest(exchange:, symbols:, market: nil)
  body = compact("exchange" => exchange, "symbols" => symbols, "market" => market)
  @http.post("/api/v1/market/open-interest", body)["openInterest"]
end

#open_interest_history(exchange:, symbol:, hours: nil, market: nil) ⇒ Object

Open-interest history.



98
99
100
101
# File 'lib/melaya/market.rb', line 98

def open_interest_history(exchange:, symbol:, hours: nil, market: nil)
  body = compact("exchange" => exchange, "symbol" => symbol, "hours" => hours, "market" => market)
  @http.post("/api/v1/market/open-interest-history", body)["history"]
end

#open_interest_history_multi(exchanges:, symbol:, hours: nil) ⇒ Object

Open-interest history for one symbol across several venues. Keyed by exchange.



135
136
137
138
# File 'lib/melaya/market.rb', line 135

def open_interest_history_multi(exchanges:, symbol:, hours: nil)
  body = compact("exchanges" => exchanges, "symbol" => symbol, "hours" => hours)
  @http.post("/api/v1/market/open-interest-history-multi", body)["perExchange"]
end

#orderbook(exchange:, symbol:, limit: nil, market: nil) ⇒ Object

Order book to a given depth.



30
31
32
33
34
# File 'lib/melaya/market.rb', line 30

def orderbook(exchange:, symbol:, limit: nil, market: nil)
  @http.get("/api/v1/market/orderbook",
    "exchange" => exchange, "symbol" => symbol, "limit" => limit, "market" => market
  )["orderbook"]
end

#prediction_markets(venue: "polymarket") ⇒ Object

Prediction-market listings for a venue (polymarket, kalshi, drift_pm, sxbet, azuro, overtime).



141
142
143
# File 'lib/melaya/market.rb', line 141

def prediction_markets(venue: "polymarket")
  @http.post("/api/v1/market/pm-markets", { "venue" => venue })["markets"]
end

#status(exchange:) ⇒ Object

Operational status: ok / maintenance / degraded.



62
63
64
# File 'lib/melaya/market.rb', line 62

def status(exchange:)
  @http.get("/api/v1/market/status", "exchange" => exchange)["status"]
end

#ticker(exchange:, symbol:, market: nil) ⇒ Object

Best bid/ask, last price, and 24h aggregates for one symbol.

Parameters:

  • exchange (String)
  • symbol (String)
  • market (String, nil) (defaults to: nil)

    e.g. “spot”, “future”, “swap”



23
24
25
26
27
# File 'lib/melaya/market.rb', line 23

def ticker(exchange:, symbol:, market: nil)
  @http.get("/api/v1/market/ticker",
    "exchange" => exchange, "symbol" => symbol, "market" => market
  )["ticker"]
end

#tickers(exchange:, symbols:, market: nil) ⇒ Object

Tickers for many symbols on one venue in a single call. Keyed by symbol.



74
75
76
77
# File 'lib/melaya/market.rb', line 74

def tickers(exchange:, symbols:, market: nil)
  body = compact("exchange" => exchange, "symbols" => symbols, "market" => market)
  @http.post("/api/v1/market/tickers", body)["tickers"]
end

#time(exchange:) ⇒ Object

Exchange server time.



67
68
69
# File 'lib/melaya/market.rb', line 67

def time(exchange:)
  @http.get("/api/v1/market/time", "exchange" => exchange)["time"]
end

#trades(exchange:, symbol:, market: nil) ⇒ Object

Recent public trades.



45
46
47
48
49
# File 'lib/melaya/market.rb', line 45

def trades(exchange:, symbol:, market: nil)
  @http.get("/api/v1/market/trades",
    "exchange" => exchange, "symbol" => symbol, "market" => market
  )["trades"]
end