Class: Huo::Trade

Inherits:
Object
  • Object
show all
Defined in:
lib/huo/trade.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Trade

Returns a new instance of Trade.



12
13
14
15
16
17
# File 'lib/huo/trade.rb', line 12

def initialize(options = {})
  path = options[:tokens_path]
  config = path ? YAML.load_file(path) : {}
  @access_key = config['access_key'] || options[:access_key]
  @secret_key = config['secret_key'] || options[:secret_key]
end

Instance Method Details

#buy(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/huo/trade.rb', line 30

def buy(options = {})
  args = {
    method: __method__,
    coin_type: 1,
    price: options.fetch(:price),
    amount: options.fetch(:btc_amount, 0.001)
  }
  get(args)
end

#buy_market(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/huo/trade.rb', line 40

def buy_market(options = {})
  args = {
    method: __method__,
    coin_type: 1,
    amount: options.fetch(:rmb_amount, 1)
  }
  get(args)
end

#get(options) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/huo/trade.rb', line 68

def get(options)
  params = options.fetch(:params, options)
  digest = options.fetch(:digest, params)
  digest_keys = digest.is_a?(Hash) ? digest.keys : digest

  rest_options = {
    params: pack_params(params, digest_keys),
    header: REQUEST_HEADER,
    accept: :json
  }
  response = RestClient.get(REQUEST_URL, rest_options)
  normalize_json(response)
end

#get_account_infoObject



19
20
21
# File 'lib/huo/trade.rb', line 19

def 
  get(method: __method__)
end

#get_orders(options = {}) ⇒ Object



23
24
25
# File 'lib/huo/trade.rb', line 23

def get_orders(options = {})
  get(method: __method__, coin_type: 1)
end

#order_infoObject



27
28
# File 'lib/huo/trade.rb', line 27

def order_info
end

#sell(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/huo/trade.rb', line 49

def sell(options = {})
  args = {
    method: __method__,
    coin_type: 1,
    price: options.fetch(:price),
    amount: options.fetch(:amount, 0.001)
  }
  get(args)
end

#sell_market(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/huo/trade.rb', line 59

def sell_market(options = {})
  args = {
    method: __method__,
    coin_type: 1,
    amount: options.fetch(:btc_amount, 0.001)
  }
  get(args)
end