Class: Kucoin::Rest::Client
- Inherits:
-
Object
- Object
- Kucoin::Rest::Client
- Includes:
- Authentication, Errors, Private::Balances, Private::Invitations, Private::Languages, Private::Trading, Private::Transfers, Private::User, Public::Currencies, Public::Klines, Public::Languages, Public::Markets, Public::Orders, Public::Ticker, Public::Trades
- Defined in:
- lib/kucoin/rest/client.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #check_credentials! ⇒ Object
- #configured? ⇒ Boolean
- #get(path, params: {}, options: {}) ⇒ Object
-
#initialize(configuration: ::Kucoin.configuration) ⇒ Client
constructor
A new instance of Client.
- #parse(response) ⇒ Object
- #post(path, params: {}, data: {}, options: {}) ⇒ Object
- #request(path, method: :get, params: {}, data: {}, options: {}) ⇒ Object
- #signature_path(path) ⇒ Object
- #to_uri(path) ⇒ Object
Methods included from Private::Trading
#active_orders, #cancel_all_orders, #cancel_order, #create_buy_order, #create_order, #create_sell_order, #dealt_orders, #order_detail, #symbol_dealt_orders
Methods included from Private::Balances
#balance, #coin_balance, #wallet_records
Methods included from Private::Transfers
#cancel_withdrawal, #create_withdrawal, #get_coin_address
Methods included from Private::Invitations
#invitation_count, #promotion_reward, #promotion_summary
Methods included from Private::Languages
Methods included from Private::User
Methods included from Public::Klines
#chart_kline_data, #chart_symbol, #kline_config, #kline_data
Methods included from Public::Markets
#coin_info, #coins, #market_symbols, #markets, #trending_symbols
Methods included from Public::Trades
Methods included from Public::Orders
#buy_orders, #orders, #sell_orders
Methods included from Public::Ticker
Methods included from Public::Languages
Methods included from Public::Currencies
Methods included from Authentication
#authenticate!, #compose_params, #nonce, #sign_message
Methods included from Errors
Constructor Details
#initialize(configuration: ::Kucoin.configuration) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/kucoin/rest/client.rb', line 6 def initialize(configuration: ::Kucoin.configuration) self.configuration = configuration self.url = "#{self.configuration.api_url}/v#{self.configuration.api_version}" end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/kucoin/rest/client.rb', line 4 def configuration @configuration end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/kucoin/rest/client.rb', line 4 def url @url end |
Instance Method Details
#check_credentials! ⇒ Object
33 34 35 36 37 |
# File 'lib/kucoin/rest/client.rb', line 33 def check_credentials! unless configured? raise ::Kucoin::Errors::MissingConfigError.new("Kucoin gem hasn't been properly configured.") end end |
#configured? ⇒ Boolean
29 30 31 |
# File 'lib/kucoin/rest/client.rb', line 29 def configured? !self.configuration.key.to_s.empty? && !self.configuration.secret.to_s.empty? end |
#get(path, params: {}, options: {}) ⇒ Object
52 53 54 |
# File 'lib/kucoin/rest/client.rb', line 52 def get(path, params: {}, options: {}) request path, method: :get, params: params, options: end |
#parse(response) ⇒ Object
47 48 49 50 |
# File 'lib/kucoin/rest/client.rb', line 47 def parse(response) error?(response) response end |
#post(path, params: {}, data: {}, options: {}) ⇒ Object
56 57 58 |
# File 'lib/kucoin/rest/client.rb', line 56 def post(path, params: {}, data: {}, options: {}) request path, method: :post, params: params, data: data, options: end |
#request(path, method: :get, params: {}, data: {}, options: {}) ⇒ Object
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 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kucoin/rest/client.rb', line 60 def request(path, method: :get, params: {}, data: {}, options: {}) should_auth = .fetch(:authenticate, false) user_agent = .fetch(:user_agent, self.configuration.faraday.fetch(:user_agent, nil)) proxy = .fetch(:proxy, nil) connection = Faraday.new(url: to_uri(path)) do |builder| builder.headers["User-Agent"] = user_agent if !user_agent.to_s.empty? builder.headers["Accept-Language"] = "en_EN" builder.headers.merge!(authenticate!(path, params)) if should_auth && method.eql?(:get) builder.headers.merge!(authenticate!(path, data)) if should_auth && method.eql?(:post) builder.request :url_encoded if method.eql?(:post) builder.response :logger if self.configuration.verbose_faraday? builder.response :json if proxy puts "[Kucoin::Rest::Client] - Will connect to Kucoin using proxy: #{proxy.inspect}" if self.configuration.verbose_faraday? builder.proxy = proxy end builder.adapter self.configuration.faraday.fetch(:adapter, :net_http) end case method when :get connection.get do |request| request.params = params if params && !params.empty? end&.body when :post connection.post do |request| request.body = data request.params = params if params && !params.empty? end&.body end end |
#signature_path(path) ⇒ Object
43 44 45 |
# File 'lib/kucoin/rest/client.rb', line 43 def signature_path(path) "/v#{self.configuration.api_version}#{path}" end |
#to_uri(path) ⇒ Object
39 40 41 |
# File 'lib/kucoin/rest/client.rb', line 39 def to_uri(path) "#{self.url}#{path}" end |