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
A new instance of Client.
Constructor Details
#initialize(api_key:, app_key: nil, base_url: nil, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, user_agent: nil) ⇒ Client
Returns a new instance of Client.
53 54 55 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 |
# File 'lib/cryptohopper/client.rb', line 53 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.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def ai @ai end |
#app ⇒ Object (readonly)
Returns the value of attribute app.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def app @app end |
#arbitrage ⇒ Object (readonly)
Returns the value of attribute arbitrage.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def arbitrage @arbitrage end |
#backtest ⇒ Object (readonly)
Returns the value of attribute backtest.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def backtest @backtest end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def base_url @base_url end |
#chart ⇒ Object (readonly)
Returns the value of attribute chart.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def chart @chart end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def exchange @exchange end |
#hoppers ⇒ Object (readonly)
Returns the value of attribute hoppers.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def hoppers @hoppers end |
#market ⇒ Object (readonly)
Returns the value of attribute market.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def market @market end |
#marketmaker ⇒ Object (readonly)
Returns the value of attribute marketmaker.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def marketmaker @marketmaker end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def platform @platform end |
#signals ⇒ Object (readonly)
Returns the value of attribute signals.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def signals @signals end |
#social ⇒ Object (readonly)
Returns the value of attribute social.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def @social end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def strategy @strategy end |
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def subscription @subscription end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def template @template end |
#tournaments ⇒ Object (readonly)
Returns the value of attribute tournaments.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def tournaments @tournaments end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 def user @user end |
#webhooks ⇒ Object (readonly)
Returns the value of attribute webhooks.
40 41 42 |
# File 'lib/cryptohopper/client.rb', line 40 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cryptohopper/client.rb', line 87 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 |