Class: Cryptohopper::Client
- Inherits:
-
Object
- Object
- Cryptohopper::Client
- Defined in:
- lib/cryptohopper/client.rb
Overview
Synchronous Cryptohopper API client.
Instance Attribute Summary collapse
-
#ai ⇒ Object
readonly
Returns the value of attribute ai.
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#arbitrage ⇒ Object
readonly
Returns the value of attribute arbitrage.
-
#backtest ⇒ Object
readonly
Returns the value of attribute backtest.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#chart ⇒ Object
readonly
Returns the value of attribute chart.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#hoppers ⇒ Object
readonly
Returns the value of attribute hoppers.
-
#market ⇒ Object
readonly
Returns the value of attribute market.
-
#marketmaker ⇒ Object
readonly
Returns the value of attribute marketmaker.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#signals ⇒ Object
readonly
Returns the value of attribute signals.
-
#social ⇒ Object
readonly
Returns the value of attribute social.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#subscription ⇒ Object
readonly
Returns the value of attribute subscription.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#tournaments ⇒ Object
readonly
Returns the value of attribute tournaments.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#webhooks ⇒ Object
readonly
Returns the value of attribute webhooks.
Instance Method Summary collapse
-
#_request(method, path, params: nil, body: nil, max_retries: nil) ⇒ Object
private
Internal transport.
-
#initialize(api_key:, app_key: nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, user_agent: nil) ⇒ Client
constructor
rubocop:disable Metrics/ParameterLists – keyword args; readability wins over splitting into a value-object struct.
Constructor Details
#initialize(api_key:, app_key: nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, user_agent: nil) ⇒ Client
rubocop:disable Metrics/ParameterLists – keyword args; readability wins over splitting into a value-object struct.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cryptohopper/client.rb', line 56 def initialize(api_key:, app_key: nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, user_agent: nil) raise ArgumentError, "api_key is required" if api_key.nil? || api_key.empty? @api_key = api_key @app_key = app_key @base_url = (base_url || DEFAULT_BASE_URL).chomp("/") @timeout = timeout @max_retries = max_retries @user_agent_suffix = user_agent @user = Resources::User.new(self) @hoppers = Resources::Hoppers.new(self) @exchange = Resources::Exchange.new(self) @strategy = Resources::Strategies.new(self) @backtest = Resources::Backtests.new(self) @market = Resources::Market.new(self) @signals = Resources::Signals.new(self) @arbitrage = Resources::Arbitrage.new(self) @marketmaker = Resources::MarketMaker.new(self) @template = Resources::Templates.new(self) @ai = Resources::AI.new(self) @platform = Resources::Platform.new(self) @chart = Resources::Chart.new(self) @subscription = Resources::Subscription.new(self) @social = Resources::Social.new(self) @tournaments = Resources::Tournaments.new(self) @webhooks = Resources::Webhooks.new(self) @app = Resources::App.new(self) end |
Instance Attribute Details
#ai ⇒ Object (readonly)
Returns the value of attribute ai.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def ai @ai end |
#app ⇒ Object (readonly)
Returns the value of attribute app.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def app @app end |
#arbitrage ⇒ Object (readonly)
Returns the value of attribute arbitrage.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def arbitrage @arbitrage end |
#backtest ⇒ Object (readonly)
Returns the value of attribute backtest.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def backtest @backtest end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def base_url @base_url end |
#chart ⇒ Object (readonly)
Returns the value of attribute chart.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def chart @chart end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def exchange @exchange end |
#hoppers ⇒ Object (readonly)
Returns the value of attribute hoppers.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def hoppers @hoppers end |
#market ⇒ Object (readonly)
Returns the value of attribute market.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def market @market end |
#marketmaker ⇒ Object (readonly)
Returns the value of attribute marketmaker.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def marketmaker @marketmaker end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def platform @platform end |
#signals ⇒ Object (readonly)
Returns the value of attribute signals.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def signals @signals end |
#social ⇒ Object (readonly)
Returns the value of attribute social.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def @social end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def strategy @strategy end |
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def subscription @subscription end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def template @template end |
#tournaments ⇒ Object (readonly)
Returns the value of attribute tournaments.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def tournaments @tournaments end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def user @user end |
#webhooks ⇒ Object (readonly)
Returns the value of attribute webhooks.
41 42 43 |
# File 'lib/cryptohopper/client.rb', line 41 def webhooks @webhooks end |
Instance Method Details
#_request(method, path, params: nil, body: nil, max_retries: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal transport. Resources call this. Users shouldn’t.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cryptohopper/client.rb', line 91 def _request(method, path, params: nil, body: nil, max_retries: nil) retries = max_retries || @max_retries attempt = 0 loop do return do_request(method, path, params: params, body: body) rescue Error => e raise unless e.code == "RATE_LIMITED" && attempt < retries wait = e.retry_after_ms ? e.retry_after_ms / 1000.0 : (2**attempt) sleep(wait) attempt += 1 end end |