Class: HuobiClient::Client

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/huobi_client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#get, #post

Constructor Details

#initialize(access, secret, account_id = nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/huobi_client/client.rb', line 12

def initialize(access, secret, =nil)
  @access = access
  @secret = secret
  @account_id = 
end

Instance Attribute Details

#accessObject (readonly)

Returns the value of attribute access.



8
9
10
# File 'lib/huobi_client/client.rb', line 8

def access
  @access
end

#account_idObject (readonly)

Returns the value of attribute account_id.



8
9
10
# File 'lib/huobi_client/client.rb', line 8

def 
  @account_id
end

#secretObject (readonly)

Returns the value of attribute secret.



8
9
10
# File 'lib/huobi_client/client.rb', line 8

def secret
  @secret
end

Instance Method Details

#accountsObject

用户资产API



65
66
67
# File 'lib/huobi_client/client.rb', line 65

def accounts
  get '/v1/account/accounts'
end

#all_match_results(symbol: nil, states:, types: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) ⇒ Object

查询当前成交、历史成交



115
116
117
# File 'lib/huobi_client/client.rb', line 115

def all_match_results(symbol: nil, states:, types: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) # 查询当前成交、历史成交
  get '/v1/order/matchresults', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#balance(account_id: @account_id) ⇒ Object



69
70
71
# File 'lib/huobi_client/client.rb', line 69

def balance(account_id: @account_id)
  get "/v1/account/accounts/#{}/balance"
end

#batch_cancel(order_ids:) ⇒ Object

批量撤销订单



97
98
99
# File 'lib/huobi_client/client.rb', line 97

def batch_cancel(order_ids:) # 批量撤销订单
  post '/v1/order/orders/batchcancel', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#currencysObject



52
53
54
# File 'lib/huobi_client/client.rb', line 52

def currencys
  get '/v1/common/currencys'
end

#depth(symbol:, type:) ⇒ Object



27
28
29
# File 'lib/huobi_client/client.rb', line 27

def depth(symbol:, type:)
  get '/market/depth', fun_params(__method__, binding)
end

#dw_transfer_in(symbol:, currency:, amount:) ⇒ Object

借贷交易API (重要:如果使用借贷资产交易,请在下单接口/v1/order/orders/place请求参数source中填写‘margin-api’)



121
122
123
# File 'lib/huobi_client/client.rb', line 121

def dw_transfer_in(symbol:, currency:, amount:) # 现货账户划入至借贷账户
  post '/v1/dw/transfer-in/margin', fun_params(__method__, binding)
end

#dw_transfer_out(symbol:, currency:, amount:) ⇒ Object

借贷账户划出至现货账户



125
126
127
# File 'lib/huobi_client/client.rb', line 125

def dw_transfer_out(symbol:, currency:, amount:) # 借贷账户划出至现货账户
  post '/v1/dw/transfer-out/margin', fun_params(__method__, binding)
end

#hadax_balance(account_id: @account_id) ⇒ Object



73
74
75
# File 'lib/huobi_client/client.rb', line 73

def hadax_balance(account_id: @account_id)
  get "/v1/hadax/account/accounts/#{}/balance"
end

#hadax_currencysObject



56
57
58
# File 'lib/huobi_client/client.rb', line 56

def hadax_currencys
  get '/v1/hadax/common/currencys'
end

#hadax_place(account_id: @account_id, symbol:, type:, amount:, price: nil, source: 'api') ⇒ Object

HADAX站下单



89
90
91
# File 'lib/huobi_client/client.rb', line 89

def hadax_place(account_id: @account_id, symbol:, type:, amount:, price: nil, source: 'api') # HADAX站下单
  post '/v1/hadax/order/orders/place', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#hadax_symbolsObject



48
49
50
# File 'lib/huobi_client/client.rb', line 48

def hadax_symbols
  get '/v1/hadax/common/symbols'
end

#kline(symbol:, period:, size: 150) ⇒ Object

行情API



19
20
21
# File 'lib/huobi_client/client.rb', line 19

def kline(symbol:, period:, size: 150) # 获取K线数据
  get '/market/history/kline', fun_params(__method__, binding)
end

#loan_orders(symbol:, states: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) ⇒ Object

借贷订单



137
138
139
# File 'lib/huobi_client/client.rb', line 137

def loan_orders(symbol:, states: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) # 借贷订单
  get '/v1/margin/loan-orders', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#margin_apply(symbol:, currency:, amount:) ⇒ Object

申请借贷



129
130
131
# File 'lib/huobi_client/client.rb', line 129

def margin_apply(symbol:, currency:, amount:) # 申请借贷
  post '/v1/margin/orders', fun_params(__method__, binding)
end

#margin_balance(symbol:) ⇒ Object

借贷账户详情



141
142
143
# File 'lib/huobi_client/client.rb', line 141

def margin_balance(symbol:) # 借贷账户详情
  get '/v1/margin/accounts/balance', fun_params(__method__, binding)
end

#margin_repay(amount:, order_id:) ⇒ Object

归还借贷



133
134
135
# File 'lib/huobi_client/client.rb', line 133

def margin_repay(amount:, order_id:) # 归还借贷
  post "/v1/margin/orders/#{order_id}/repay", fun_params(__method__, binding)
end

#market_detail(symbol:) ⇒ Object



39
40
41
# File 'lib/huobi_client/client.rb', line 39

def market_detail(symbol:)
  get '/market/detail', fun_params(__method__, binding)
end

#match_results(order_id:) ⇒ Object

查询某个订单的成交明细



105
106
107
# File 'lib/huobi_client/client.rb', line 105

def match_results(order_id:) # 查询某个订单的成交明细
  get "/v1/order/orders/#{order_id}/matchresults"
end

#order_detail(order_id:) ⇒ Object

查询某个订单详情



101
102
103
# File 'lib/huobi_client/client.rb', line 101

def order_detail(order_id:) # 查询某个订单详情
  get "/v1/order/orders/#{order_id}"
end

#orders(symbol: nil, states:, types: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) ⇒ Object

查询当前委托、历史委托



109
110
111
112
113
# File 'lib/huobi_client/client.rb', line 109

def orders(symbol: nil, states:, types: nil, start_date: nil, end_date: nil, from: nil, direct: nil, size: nil) # 查询当前委托、历史委托
  # direct	false	string	查询方向		prev 向前,next 向后
  # states	true	string	查询的订单状态组合,使用','分割		pre-submitted 准备提交, submitted 已提交, partial-filled 部分成交, partial-canceled 部分成交撤销, filled 完全成交, canceled 已撤销
  get '/v1/order/orders', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#place(account_id: @account_id, symbol:, type:, amount:, price: nil, source: 'api') ⇒ Object

交易API



78
79
80
81
82
83
84
85
86
87
# File 'lib/huobi_client/client.rb', line 78

def place(account_id: @account_id, symbol:, type:, amount:, price: nil, source: 'api') # Pro站下单
  # types
  # buy-market:市价买,
  # sell-market:市价卖,
  # buy-limit:限价买,
  # sell-limit:限价卖,
  # buy-ioc:IOC买单,
  # sell-ioc:IOC卖单
  post '/v1/order/orders/place', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#submit_cancel(order_id:) ⇒ Object

申请撤销一个订单请求



93
94
95
# File 'lib/huobi_client/client.rb', line 93

def submit_cancel(order_id:) # 申请撤销一个订单请求
  post "/v1/order/orders/#{order_id}/submitcancel"
end

#symbolsObject

公共API



44
45
46
# File 'lib/huobi_client/client.rb', line 44

def symbols
  get '/v1/common/symbols'
end

#ticker(symbol:) ⇒ Object



23
24
25
# File 'lib/huobi_client/client.rb', line 23

def ticker(symbol:)
  get '/market/detail/merged', fun_params(__method__, binding)
end

#timestampObject



60
61
62
# File 'lib/huobi_client/client.rb', line 60

def timestamp
  get '/v1/common/timestamp'
end

#trade_detail(symbol:) ⇒ Object



31
32
33
# File 'lib/huobi_client/client.rb', line 31

def trade_detail(symbol:)
  get '/market/trade', fun_params(__method__, binding)
end

#trade_list(symbol:, size: 1) ⇒ Object



35
36
37
# File 'lib/huobi_client/client.rb', line 35

def trade_list(symbol:, size: 1)
  get '/market/history/trade', fun_params(__method__, binding)
end

#withdraw(address:, amount:, currency:, fee: nil, addr_tag: nil) ⇒ Object

虚拟币提现API



146
147
148
# File 'lib/huobi_client/client.rb', line 146

def withdraw(address:, amount:, currency:, fee: nil, addr_tag: nil) # 申请提现虚拟币
  post '/v1/dw/withdraw/api/create', fun_params(__method__, binding).transform_keys {|key| key.to_s.sub('_', '-')}
end

#withdraw_cancelObject

申请取消提现虚拟币



150
151
152
# File 'lib/huobi_client/client.rb', line 150

def withdraw_cancel # 申请取消提现虚拟币
  post '/v1/dw/withdraw-virtual/{withdraw-id}/cancel'
end

#withdraw_query(currency:, type:, from: nil, size: nil) ⇒ Object

查询虚拟币充提记录



154
155
156
157
# File 'lib/huobi_client/client.rb', line 154

def withdraw_query(currency:, type:, from: nil, size: nil) # 查询虚拟币充提记录
  # type	true	string	'deposit' or 'withdraw'
  get '/v1/query/deposit-withdraw', fun_params(__method__, binding)
end