class Darwinex::Client

Constants

MAX_RETRIES

Attributes

consumer_key[R]
consumer_secret[R]
logger[R]
max_retries[R]

Public Class Methods

new(consumer_key:, consumer_secret:, max_retries: MAX_RETRIES, logger: Logger.new(STDOUT, progname: 'Darwinex')) click to toggle source
# File lib/darwinex/client.rb, line 15
def initialize(consumer_key:, consumer_secret:, max_retries: MAX_RETRIES, logger: Logger.new(STDOUT, progname: 'Darwinex'))
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @max_retries = max_retries
  @logger = logger
end

Public Instance Methods

investor_account(account_id) click to toggle source
# File lib/darwinex/client.rb, line 36
def investor_account(account_id)
  InvestorAccount.new(
    account_id: account_id,
    trading_api: trading_api,
    investor_account_info_api: investor_account_info_api
  )
end
list_investor_accounts() click to toggle source
# File lib/darwinex/client.rb, line 26
def list_investor_accounts
  investor_account_info_api.list_investor_accounts.map do |investor_account|
    InvestorAccount.new(
      account_id: investor_account['id'],
      trading_api: trading_api,
      investor_account_info_api: investor_account_info_api
    )
  end
end
list_products(status: nil, page: nil, per_page: nil) click to toggle source
# File lib/darwinex/client.rb, line 44
def list_products(status: nil, page: nil, per_page: nil)
  args = {
    status: status,
    page: page,
    per_page: per_page
  }

  api_response = info_api.list_products(args)

  products = api_response['content'].map { |product| product(product['productName']) }

  response = api_response.tap { |h| h.delete('content') }

  response['products'] = products

  response
end
product(product_name) click to toggle source
# File lib/darwinex/client.rb, line 62
def product(product_name)
  Product.new(
    product_name: product_name,
    info_api: info_api
  )
end
refresh_access_token(refresh_token) click to toggle source
# File lib/darwinex/client.rb, line 22
def refresh_access_token(refresh_token)
  config.refresh_access_token(refresh_token)
end

Private Instance Methods

config() click to toggle source
# File lib/darwinex/client.rb, line 87
def config
  @config ||= Config.new(
    token_api: token_api,
    consumer_key: consumer_key,
    consumer_secret: consumer_secret,
    max_retries: max_retries
  )
end
info_api() click to toggle source
# File lib/darwinex/client.rb, line 100
def info_api
  @info_api ||= Api::InfoApi.new(
    config: config,
    logger: logger
  )
end
investor_account_info_api() click to toggle source
# File lib/darwinex/client.rb, line 73
def investor_account_info_api
  @investor_account_info_api ||= Api::InvestorAccountInfoApi.new(
    config: config,
    logger: logger
  )
end
token_api() click to toggle source
# File lib/darwinex/client.rb, line 96
def token_api
  @token_api ||= Api::TokenApi.new(max_retries: max_retries, logger: logger)
end
trading_api() click to toggle source
# File lib/darwinex/client.rb, line 80
def trading_api
  @trading_api ||= Api::TradingApi.new(
    config: config,
    logger: logger
  )
end