melaya 0.1.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 +7 -0
- data/README.md +163 -0
- data/lib/melaya/account.rb +30 -0
- data/lib/melaya/backtest.rb +101 -0
- data/lib/melaya/errors.rb +15 -0
- data/lib/melaya/http_client.rb +97 -0
- data/lib/melaya/market.rb +156 -0
- data/lib/melaya/sim.rb +110 -0
- data/lib/melaya/strategies.rb +155 -0
- data/lib/melaya/stream.rb +336 -0
- data/lib/melaya/trade.rb +168 -0
- data/lib/melaya/version.rb +5 -0
- data/lib/melaya.rb +79 -0
- data/melaya.gemspec +23 -0
- metadata +54 -0
data/lib/melaya.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "melaya/version"
|
|
4
|
+
require_relative "melaya/errors"
|
|
5
|
+
require_relative "melaya/http_client"
|
|
6
|
+
require_relative "melaya/market"
|
|
7
|
+
require_relative "melaya/account"
|
|
8
|
+
require_relative "melaya/sim"
|
|
9
|
+
require_relative "melaya/strategies"
|
|
10
|
+
require_relative "melaya/backtest"
|
|
11
|
+
require_relative "melaya/stream"
|
|
12
|
+
require_relative "melaya/trade"
|
|
13
|
+
|
|
14
|
+
module Melaya
|
|
15
|
+
# The Melaya client.
|
|
16
|
+
#
|
|
17
|
+
# @example
|
|
18
|
+
# require "melaya"
|
|
19
|
+
# melaya = Melaya::Client.new(api_key: ENV["MK"])
|
|
20
|
+
#
|
|
21
|
+
# # Market data
|
|
22
|
+
# t = melaya.market.ticker(exchange: "binance", symbol: "BTC/USDT", market: "spot")
|
|
23
|
+
# puts t["last"]
|
|
24
|
+
#
|
|
25
|
+
# # Paper strategy
|
|
26
|
+
# result = melaya.strategies.create(
|
|
27
|
+
# name: "my-bot", strategy_type: "custom", exchange: "binanceusdm",
|
|
28
|
+
# symbol: "BTC/USDT:USDT", market: "FUTURES", dry_run: true,
|
|
29
|
+
# params: { language: "rhai", definition: 'fn evaluate() { emit_long(param("qty")); }', qty: 0.001 }
|
|
30
|
+
# )
|
|
31
|
+
# sid = result["strategyId"]
|
|
32
|
+
# melaya.strategies.stop(sid)
|
|
33
|
+
# melaya.strategies.delete(sid)
|
|
34
|
+
class Client
|
|
35
|
+
# REST market-data + reference endpoints (public plane).
|
|
36
|
+
attr_reader :market
|
|
37
|
+
# Authenticated account reads: connected keys, tier limits, usage.
|
|
38
|
+
attr_reader :account
|
|
39
|
+
# Paper trading (sim broker): virtual balance, positions, and orders.
|
|
40
|
+
attr_reader :sim
|
|
41
|
+
# Launch, control, and inspect trading strategies (paper + live).
|
|
42
|
+
attr_reader :strategies
|
|
43
|
+
# Historical backtests + parameter sweeps on the Rust engine.
|
|
44
|
+
attr_reader :backtest
|
|
45
|
+
# WebSocket streaming endpoints (public market data + private feeds).
|
|
46
|
+
attr_reader :stream
|
|
47
|
+
# Live trading — credentialed order placement and account state on a connected exchange. WARNING: real funds.
|
|
48
|
+
attr_reader :trade
|
|
49
|
+
|
|
50
|
+
# @param api_key [String] your Melaya API key, prefixed +mk_+
|
|
51
|
+
# @param base_url [String] override the REST base URL
|
|
52
|
+
# @param ws_url [String] override the WebSocket base URL
|
|
53
|
+
# @param verify_ssl [Boolean] set false to skip TLS verification (dev-box only).
|
|
54
|
+
# Prefer using ENV["MELAYA_INSECURE_TLS"]="1" rather than passing this directly.
|
|
55
|
+
def initialize(api_key:, base_url: HttpClient::DEFAULT_BASE_URL,
|
|
56
|
+
ws_url: StreamAPI::DEFAULT_WS_URL, verify_ssl: nil)
|
|
57
|
+
raise ArgumentError, "Melaya: api_key is required (create one at melaya.org -> Settings -> API Keys)." \
|
|
58
|
+
if api_key.nil? || api_key.empty?
|
|
59
|
+
raise ArgumentError, "Melaya: API keys must be prefixed 'mk_'." \
|
|
60
|
+
unless api_key.start_with?("mk_")
|
|
61
|
+
|
|
62
|
+
ssl = if verify_ssl.nil?
|
|
63
|
+
ENV["MELAYA_INSECURE_TLS"] != "1"
|
|
64
|
+
else
|
|
65
|
+
verify_ssl
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
http = HttpClient.new(api_key: api_key, base_url: base_url, verify_ssl: ssl)
|
|
69
|
+
|
|
70
|
+
@market = MarketAPI.new(http)
|
|
71
|
+
@account = AccountAPI.new(http)
|
|
72
|
+
@sim = SimAPI.new(http)
|
|
73
|
+
@strategies = StrategiesAPI.new(http)
|
|
74
|
+
@backtest = BacktestAPI.new(http)
|
|
75
|
+
@stream = StreamAPI.new(api_key, ws_url, http, verify_ssl: ssl)
|
|
76
|
+
@trade = TradeAPI.new(http)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/melaya.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/melaya/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "melaya"
|
|
7
|
+
spec.version = Melaya::VERSION
|
|
8
|
+
spec.authors = ["Melaya"]
|
|
9
|
+
spec.email = ["sdk@melaya.org"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Official Ruby SDK for the Melaya unified market-data & trading API"
|
|
12
|
+
spec.description = "Access 70+ exchanges via Melaya's normalized REST and WebSocket API. " \
|
|
13
|
+
"Market data, strategies, backtesting, sim trading, and streaming."
|
|
14
|
+
spec.homepage = "https://melaya.org"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
18
|
+
|
|
19
|
+
spec.files = Dir["lib/**/*.rb", "README.md", "melaya.gemspec"]
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
# stdlib only — no runtime gem dependencies
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: melaya
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Melaya
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Access 70+ exchanges via Melaya's normalized REST and WebSocket API.
|
|
13
|
+
Market data, strategies, backtesting, sim trading, and streaming.
|
|
14
|
+
email:
|
|
15
|
+
- sdk@melaya.org
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- README.md
|
|
21
|
+
- lib/melaya.rb
|
|
22
|
+
- lib/melaya/account.rb
|
|
23
|
+
- lib/melaya/backtest.rb
|
|
24
|
+
- lib/melaya/errors.rb
|
|
25
|
+
- lib/melaya/http_client.rb
|
|
26
|
+
- lib/melaya/market.rb
|
|
27
|
+
- lib/melaya/sim.rb
|
|
28
|
+
- lib/melaya/strategies.rb
|
|
29
|
+
- lib/melaya/stream.rb
|
|
30
|
+
- lib/melaya/trade.rb
|
|
31
|
+
- lib/melaya/version.rb
|
|
32
|
+
- melaya.gemspec
|
|
33
|
+
homepage: https://melaya.org
|
|
34
|
+
licenses:
|
|
35
|
+
- MIT
|
|
36
|
+
metadata: {}
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: 3.0.0
|
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
requirements: []
|
|
51
|
+
rubygems_version: 4.0.3
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: Official Ruby SDK for the Melaya unified market-data & trading API
|
|
54
|
+
test_files: []
|