class Trader::Account

Attributes

backend[R]
session[R]

Public Class Methods

new(_backend, _session) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 7
def initialize(_backend, _session)
  @backend = _backend
  @session = _session
end

Public Instance Methods

balance_for(_currency) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 29
def balance_for(_currency)
  _currency = Currency.for_code _currency
  ensure_supported_currency _currency

  # IDEA: cache balances by currency code.
  balance = Balance.new backend, session, _currency
  balance.refresh!
  balance
end
create_order(_order) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 39
def create_order(_order)
  ensure_supported_market _order.pair
  raw_order = backend.create_order(
    session,
    _order.pair,
    _order.volume.amount,
    _order.limit? ? _order.price.amount : nil,
    _order.instruction
  )

  AccountOrder.new backend, session, raw_order
end
find_order(_id) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 52
def find_order(_id)
  raw_order = backend.fetch_order session, _id
  # TODO: maybe Position.new(backend, session, Market.new(backend, raw_order.pair), raw_order)
  AccountOrder.new backend, session, raw_order
end
list_orders() click to toggle source
# File lib/trade-o-matic/core/account.rb, line 58
def list_orders
  # TODO.
end
using(_pair, _quote=nil, &_block) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 12
def using(_pair, _quote=nil, &_block)
  _pair = CurrencyPair.for_code _pair, _quote

  proxy_market = find_exact_market _pair
  proxy_market = find_compatible_market _pair if proxy_market.nil?
  backend.not_supported _pair if proxy_market.nil?

  proxy = AccountProxy.new self, proxy_market, _pair

  return proxy if _block.nil?
  _block.call proxy
end
using_default_pair(&_block) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 25
def using_default_pair(&_block)
  using available_markets.first, &_block
end

Private Instance Methods

find_compatible_market(_pair) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 70
def find_compatible_market(_pair)
  available_markets.find { |p| p.compatible_with? _pair }
end
find_exact_market(_pair) click to toggle source
# File lib/trade-o-matic/core/account.rb, line 66
def find_exact_market(_pair)
  available_markets.find { |p| p == _pair }
end