Class: Cobinhood::Client::REST

Inherits:
Object
  • Object
show all
Includes:
ChartAPI, MarketAPI, SystemAPI, TradingAPI, WalletAPI
Defined in:
lib/cobinhood/client/rest.rb,
lib/cobinhood/client/rest/chart_api.rb,
lib/cobinhood/client/rest/market_api.rb,
lib/cobinhood/client/rest/system_api.rb,
lib/cobinhood/client/rest/wallet_api.rb,
lib/cobinhood/client/rest/trading_api.rb,
lib/cobinhood/client/rest/api_endpoints.rb

Overview

Public: Client with methods mirroring the Cobinhood REST APIs

Defined Under Namespace

Modules: ChartAPI, MarketAPI, SystemAPI, TradingAPI, WalletAPI

Constant Summary collapse

BASE_URL =

Public: String base url for REST client to use

"https://api.cobinhood.com".freeze
API_ENDPOINTS =
{
  system: {
    time:           'v1/system/time',
    info:           'v1/system/info',
  },

  market: {
    currencies:     '/v1/market/currencies',
    trading_pairs:  '/v1/market/trading_pairs',
    order_book:     '/v1/market/orderbooks/:trading_pair_id',
    precisions:     '/v1/market/orderbook/precisions/:trading_pair_id',
    stats:          '/v1/market/stats',
    tickers:        '/v1/market/tickers/:trading_pair_id',
    trades:         '/v1/market/trades/:trading_pair_id',
  },

  chart: {
    candles:        '/v1/chart/candles/:trading_pair_id',
  },

  trading: {
    order:          '/v1/trading/orders/:order_id',
    order_trades:   '/v1/trading/orders/:order_id/trades',
    orders:         '/v1/trading/orders',
    order_history:  '/v1/trading/order_history',
    get_trade:      '/v1/trading/trades/:trade_id',
    trades:         '/v1/trading/trades',
  },

  wallet: {
    balances:             '/v1/wallet/balances',
    ledger:               '/v1/wallet/ledger',
    deposit_addresses:    '/v1/wallet/deposit_addresses',
    withdrawal_addresses: '/v1/wallet/withdrawal_addresses',
    withdrawal:           '/v1/wallet/withdrawals/:withdrawal_id',
    withdrawals:          '/v1/wallet/withdrawals',
    deposit:              '/v1/wallet/deposits/:deposit_id',
    deposits:             '/v1/wallet/deposits',
  },
}.freeze

Instance Method Summary collapse

Methods included from WalletAPI

#balances, #deposit, #deposit_addresses, #deposits, #ledger, #withdrawal, #withdrawal_addresses, #withdrawals

Methods included from TradingAPI

#cancel_order, #get_trade, #modify_order, #order, #order_history, #order_trades, #orders, #place_order, #trades

Methods included from ChartAPI

#candles

Methods included from MarketAPI

#currencies, #market_trades, #order_book, #precisions, #stats, #tickers, #trading_pairs

Methods included from SystemAPI

#info, #localtime, #time

Constructor Details

#initialize(api_key: default_api_key, adapter: Faraday.default_adapter) ⇒ REST

Public: Initialize a REST Client

:api_key - The String API key to authenticate (Default = ”).

:adapter - The Faraday::Adapter to be used for the client

(Default = Faraday.default_adapter).


40
41
42
43
44
45
46
47
48
49
# File 'lib/cobinhood/client/rest.rb', line 40

def initialize api_key: default_api_key, adapter: Faraday.default_adapter

  @library = {
      system: public_client(adapter),
      market: public_client(adapter),
       chart: public_client(adapter),
     trading: auth_client(api_key, adapter),
      wallet: auth_client(api_key, adapter),
  }
end

Instance Method Details

#assert_param_is_one_of(options, param, valid_values) ⇒ Object



56
57
58
59
# File 'lib/cobinhood/client/rest.rb', line 56

def assert_param_is_one_of options, param, valid_values
  return if valid_values.include? options[param].to_s
  raise Cobinhood::InvalidParamError.new("#{param} must be one of #{valid_values.inspect}")
end

#assert_required_param(options, param, valid_values = nil) ⇒ Object



51
52
53
54
# File 'lib/cobinhood/client/rest.rb', line 51

def assert_required_param options, param, valid_values=nil
  raise Cobinhood::MissingParamError.new("#{param} is required") unless options.has_key?(param)
  assert_param_is_one_of options, param, valid_values if valid_values
end

#default_api_keyObject



30
31
32
# File 'lib/cobinhood/client/rest.rb', line 30

def default_api_key
  ENV["COBINHOOD_API_KEY"].to_s
end