Class: BudaApi::PublicClient
- Includes:
- Models
- Defined in:
- lib/buda_api/public_client.rb
Overview
Public API client for endpoints that don't require authentication
Direct Known Subclasses
Constant Summary
Constants inherited from Client
Instance Attribute Summary
Attributes inherited from Client
#base_url, #debug_mode, #retries, #timeout
Instance Method Summary collapse
-
#average_prices_report(market_id, start_at: nil, end_at: nil) ⇒ Array<AveragePrice>
Get average prices report.
-
#candlestick_report(market_id, start_at: nil, end_at: nil) ⇒ Array<Candlestick>
Get candlestick report.
-
#market_details(market_id) ⇒ Market
Get details for a specific market.
-
#markets ⇒ Array<Market>
Get all available markets.
-
#order_book(market_id) ⇒ OrderBook
Get order book for a market.
-
#quotation(market_id, quotation_type, amount, limit: nil) ⇒ Quotation
Get a quotation for a potential trade.
-
#quotation_limit(market_id, quotation_type, amount, limit) ⇒ Quotation
Get a limit quotation (with limit price).
-
#quotation_market(market_id, quotation_type, amount) ⇒ Quotation
Get a market quotation (no limit price).
-
#ticker(market_id) ⇒ Ticker
Get ticker information for a market.
-
#trades(market_id, timestamp: nil, limit: nil) ⇒ Trades
Get recent trades for a market.
Methods inherited from Client
Constructor Details
This class inherits a constructor from BudaApi::Client
Instance Method Details
#average_prices_report(market_id, start_at: nil, end_at: nil) ⇒ Array<AveragePrice>
Get average prices report
179 180 181 182 183 |
# File 'lib/buda_api/public_client.rb', line 179 def average_prices_report(market_id, start_at: nil, end_at: nil) get_report(market_id, ReportType::AVERAGE_PRICES, start_at, end_at) do |report_data| AveragePrice.new(report_data) end end |
#candlestick_report(market_id, start_at: nil, end_at: nil) ⇒ Array<Candlestick>
Get candlestick report
195 196 197 198 199 |
# File 'lib/buda_api/public_client.rb', line 195 def candlestick_report(market_id, start_at: nil, end_at: nil) get_report(market_id, ReportType::CANDLESTICK, start_at, end_at) do |report_data| Candlestick.new(report_data) end end |
#market_details(market_id) ⇒ Market
Get details for a specific market
35 36 37 38 39 40 41 42 43 |
# File 'lib/buda_api/public_client.rb', line 35 def market_details(market_id) validate_required_params({ market_id: market_id }, [:market_id]) validate_param_values({ market_id: market_id }, { market_id: Market::ALL }) BudaApi::Logger.info("Fetching market details for #{market_id}") response = get("markets/#{market_id}") Market.new(response["market"]) end |
#markets ⇒ Array<Market>
Get all available markets
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/buda_api/public_client.rb', line 15 def markets BudaApi::Logger.info("Fetching all markets") response = get("markets") markets_data = response["markets"] || [] markets = markets_data.map { |market_data| Market.new(market_data) } BudaApi::Logger.info("Retrieved #{markets.length} markets") markets end |
#order_book(market_id) ⇒ OrderBook
Get order book for a market
74 75 76 77 78 79 80 81 82 |
# File 'lib/buda_api/public_client.rb', line 74 def order_book(market_id) validate_required_params({ market_id: market_id }, [:market_id]) validate_param_values({ market_id: market_id }, { market_id: Market::ALL }) BudaApi::Logger.info("Fetching order book for #{market_id}") response = get("markets/#{market_id}/order_book") OrderBook.new(response["order_book"]) end |
#quotation(market_id, quotation_type, amount, limit: nil) ⇒ Quotation
Get a quotation for a potential trade
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/buda_api/public_client.rb', line 121 def quotation(market_id, quotation_type, amount, limit: nil) validate_required_params({ market_id: market_id, quotation_type: quotation_type, amount: amount }, [:market_id, :quotation_type, :amount]) validate_param_values({ market_id: market_id, quotation_type: quotation_type }, { market_id: Market::ALL, quotation_type: QuotationType::ALL }) quotation_payload = { type: quotation_type, amount: amount.to_s } quotation_payload[:limit] = limit.to_s if limit BudaApi::Logger.info("Getting quotation for #{market_id}: #{quotation_type} #{amount}") response = post("markets/#{market_id}/quotations", body: { quotation: quotation_payload }) Quotation.new(response["quotation"]) end |
#quotation_limit(market_id, quotation_type, amount, limit) ⇒ Quotation
Get a limit quotation (with limit price)
165 166 167 |
# File 'lib/buda_api/public_client.rb', line 165 def quotation_limit(market_id, quotation_type, amount, limit) quotation(market_id, quotation_type, amount, limit: limit) end |
#quotation_market(market_id, quotation_type, amount) ⇒ Quotation
Get a market quotation (no limit price)
154 155 156 |
# File 'lib/buda_api/public_client.rb', line 154 def quotation_market(market_id, quotation_type, amount) quotation(market_id, quotation_type, amount) end |
#ticker(market_id) ⇒ Ticker
Get ticker information for a market
54 55 56 57 58 59 60 61 62 |
# File 'lib/buda_api/public_client.rb', line 54 def ticker(market_id) validate_required_params({ market_id: market_id }, [:market_id]) validate_param_values({ market_id: market_id }, { market_id: Market::ALL }) BudaApi::Logger.info("Fetching ticker for #{market_id}") response = get("markets/#{market_id}/ticker") Ticker.new(response["ticker"]) end |
#trades(market_id, timestamp: nil, limit: nil) ⇒ Trades
Get recent trades for a market
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/buda_api/public_client.rb', line 94 def trades(market_id, timestamp: nil, limit: nil) validate_required_params({ market_id: market_id }, [:market_id]) validate_param_values({ market_id: market_id }, { market_id: Market::ALL }) params = normalize_params({ timestamp: , limit: limit }) BudaApi::Logger.info("Fetching trades for #{market_id} with params: #{params}") response = get("markets/#{market_id}/trades", params) Trades.new(response["trades"]) end |