Class: MercadoBitcoin::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/mercado_bitcoin/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, code:, coin_pair:, **opts) ⇒ Console

Laizy way to check parameters :)



5
6
7
8
9
10
# File 'lib/mercado_bitcoin/console.rb', line 5

def initialize(key:, code:, coin_pair:, **opts)
  @options = opts || {}
  @options[:key]          = key
  @options[:code]         = code
  @options[:coin_pair]    = coin_pair
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/mercado_bitcoin/console.rb', line 2

def options
  @options
end

Instance Method Details

#cancel_order(*args) ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mercado_bitcoin/console.rb', line 71

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

#exec(command, opts) ⇒ Object



12
13
14
# File 'lib/mercado_bitcoin/console.rb', line 12

def exec(command, opts)
  print send(command, *opts)
end

#get_account_info(*args) ⇒ Object



20
21
22
# File 'lib/mercado_bitcoin/console.rb', line 20

def (*args)
  trade_api.
end

#get_order(*args) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mercado_bitcoin/console.rb', line 24

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) ⇒ Object

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mercado_bitcoin/console.rb', line 83

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) ⇒ Object



48
49
50
51
52
53
# File 'lib/mercado_bitcoin/console.rb', line 48

def list_orderbook(*args)
  trade_api.list_orderbook(
    coin_pair: options[:coin_pair],
    full: options[:full]
  )
end

#list_orders(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mercado_bitcoin/console.rb', line 36

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) ⇒ Object



16
17
18
# File 'lib/mercado_bitcoin/console.rb', line 16

def list_system_messages(*args)
  trade_api.list_system_messages
end

#place_buy_order(*args) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/mercado_bitcoin/console.rb', line 55

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) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/mercado_bitcoin/console.rb', line 63

def place_sell_order(*args)
  trade_api.place_sell_order(
    coin_pair: options[:coin_pair],
    quantity: options[:quantity],
    limit_price: options[:limit_price]
  )
end