Class: Rubyists::Kalshi::Client
- Inherits:
-
Object
- Object
- Rubyists::Kalshi::Client
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/kalshi/client.rb
Overview
HTTP Client for Kalshi API
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
- #events ⇒ Object
-
#get(path, params: {}) ⇒ Hash
Get response from a path, adding the base_url, and a prefix, if set on the client.
-
#get_url(url, params: {}) ⇒ Hash
Get response from a URL Must pass a full URL, including scheme (http/https), host, etc.
-
#initialize(base_url: Kalshi.config.base_url) ⇒ Client
constructor
A new instance of Client.
- #market ⇒ Object
- #search ⇒ Object
- #series ⇒ Object
Constructor Details
#initialize(base_url: Kalshi.config.base_url) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 |
# File 'lib/kalshi/client.rb', line 16 def initialize(base_url: Kalshi.config.base_url) @base_url = base_url @http = HTTPX.plugin(:persistent) .plugin(:rate_limiter) .with(origin: base_url) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
13 14 15 |
# File 'lib/kalshi/client.rb', line 13 def base_url @base_url end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
13 14 15 |
# File 'lib/kalshi/client.rb', line 13 def http @http end |
#prefix ⇒ Object
Returns the value of attribute prefix.
14 15 16 |
# File 'lib/kalshi/client.rb', line 14 def prefix @prefix end |
Instance Method Details
#events ⇒ Object
60 61 62 |
# File 'lib/kalshi/client.rb', line 60 def events @events ||= Events::Client.new(clone) end |
#get(path, params: {}) ⇒ Hash
Get response from a path, adding the base_url, and a prefix, if set on the client.
see #full_path for details
31 32 33 |
# File 'lib/kalshi/client.rb', line 31 def get(path, params: {}) get_url(full_url(path), params:) end |
#get_url(url, params: {}) ⇒ Hash
Get response from a URL Must pass a full URL, including scheme (http/https), host, etc.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kalshi/client.rb', line 41 def get_url(url, params: {}) uri = URI.parse(url) raise ArgumentError, 'URL must be http or https' unless %w[http https].include?(uri.scheme) response = @http.get(url, params:) handle_response(response) rescue ArgumentError => e logger.error('Invalid URL', url:, exception: e) raise Error, "Invalid URL: #{e.}" end |
#market ⇒ Object
52 53 54 |
# File 'lib/kalshi/client.rb', line 52 def market @market ||= Market::Client.new(clone) end |