class MercadoBitcoin::Console

Attributes

options[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 4
def initialize(opts = {})
  @options = default_options.merge(opts)
end

Public Instance Methods

cancel_order(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 92
def cancel_order(*args)
  raise ArgumentError.new("faltando ORDER_ID") if args.count < 1
  ret = args.map do |id|
    trade_api.cancel_order(coin_pair: options[:coin_pair], order_id: id)
  end
  if ret.size > 1
    ret
  else
    ret[0]
  end
end
default_options() click to toggle source
# File lib/mercado_bitcoin/console.rb, line 16
def default_options
  @options ||= {
    key: ENV['MB_API_KEY'],
    code: ENV['MB_SECRET_KEY'],
    coin_pair: ENV['MB_COIN_PAIR'] || MercadoBitcoin::TradeApi::BTC,
    pretty_print: true,
    status_list: '2'
  }
end
exec(command, opts) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 26
def exec(command, opts)
  print send(command, *opts)
end
get_account_info(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 41
def get_account_info(*args)
  trade_api.get_account_info
end
get_order(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 45
def get_order(*args)
  raise ArgumentError.new("faltando ORDER_ID") if args.count < 1
  ret = args.map do |id|
    trade_api.get_order(order_id: id)
  end
  if ret.size > 1
    ret
  else
    ret[0]
  end
end
get_withdrawal(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 104
def get_withdrawal(*args)
  raise ArgumentError.new("faltando withdrawal_id") if args.count < 1
  ret = args.map do |id|
    trade_api.get_withdrawal(coin_pair: params[:coin_pair], withdrawal_id: id)
  end
  if ret.size > 1
    ret
  else
    ret[0]
  end
end
list_orderbook(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 69
def list_orderbook(*args)
  trade_api.list_orderbook(
    coin_pair: options[:coin_pair],
    full: options[:full]
  )
end
list_orders(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 57
def list_orders(*args)
  trade_api.list_orders(
    coin_pair: options[:coin_pair],
    order_type: options[:order_type],
    status_list: options[:status_list],
    has_fills: options[:has_fills],
    from_id: options[:from_id],
    to_id: options[:to_id],
    from_timestamp: options[:from_timestamp],
    to_timestamp: options[:to_timestamp])
end
list_system_messages(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 37
def list_system_messages(*args)
  trade_api.list_system_messages
end
option_parser() click to toggle source
# File lib/mercado_bitcoin/console.rb, line 12
def option_parser
  @option_parser ||= MercadoBitcoin::Console::CommandParse.new
end
place_buy_order(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 76
def place_buy_order(*args)
  trade_api.place_buy_order(
    coin_pair: options[:coin_pair],
    quantity: options[:quantity],
    limit_price: options[:limit_price]
  )
end
place_sell_order(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 84
def place_sell_order(*args)
  trade_api.place_sell_order(
    coin_pair: options[:coin_pair],
    quantity: options[:quantity],
    limit_price: options[:limit_price]
  )
end
run!() click to toggle source
# File lib/mercado_bitcoin/console.rb, line 8
def run!
  option_parser.parse(self)
end
ticker(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 30
def ticker(*args)
  MercadoBitcoin::Ticker
    .new(options[:coin_pair] == MercadoBitcoin::TradeApi::BTC ? :bitcoin : :litecoin)
    .tap { |t| t.fetch }
    .parsed
end
withdrawal_coin(*args) click to toggle source
# File lib/mercado_bitcoin/console.rb, line 116
def withdrawal_coin(*args)
  prms = params.dup
  prms = params.merge(args.first) if args.count == 1 and args.first.is_a?(Hash)
  trade_api.withdrawal_coin(**prms)
end

Private Instance Methods

pretty_print?() click to toggle source
# File lib/mercado_bitcoin/console.rb, line 132
def pretty_print?
  @options[:pretty_print]
end
print(value) click to toggle source
trade_api() click to toggle source
# File lib/mercado_bitcoin/console.rb, line 136
def trade_api
  @trade_api ||= MercadoBitcoin::TradeApi.new(
    key: options[:key],
    code: options[:code],
    debug: options[:debug]
  )
end