Class: ViaBTC::HTTP::Client

Inherits:
Object
  • Object
show all
Includes:
ViaBTC::Helpers
Defined in:
lib/viabtc/http.rb

Instance Method Summary collapse

Methods included from ViaBTC::Helpers

#amount_valid?, #fee_rate_valid?, #now, #raise_exchange_error, #response_invalid?

Constructor Details

#initialize(url: nil, http_response: nil, http_adapter: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
# File 'lib/viabtc/http.rb', line 8

def initialize(url: nil, http_response: nil, http_adapter: nil)
  if ViaBTC.configuration
    url ||= ViaBTC.configuration.http_base_url
    http_response ||= ViaBTC.configuration.http_response
    http_adapter ||= ViaBTC.configuration.http_adapter
  end

  @connection ||= connection(url, http_response, http_adapter)
end

Instance Method Details

#asset_listObject



48
49
50
# File 'lib/viabtc/http.rb', line 48

def asset_list
  request(method: "asset.list", params: [])
end

#asset_summaryObject



52
53
54
# File 'lib/viabtc/http.rb', line 52

def asset_summary
  request(method: "asset.summary", params: [])
end

#balance(user_id:, id: 0) ⇒ Object

Asset API



20
21
22
# File 'lib/viabtc/http.rb', line 20

def balance(user_id:, id: 0)
  request(id: id, method: "balance.query", params: [user_id])
end

#balance_history(user_id:, asset:, business: "", start_time: 0, end_time: 0, offset: 0, limit: 100, id: 0) ⇒ Object



44
45
46
# File 'lib/viabtc/http.rb', line 44

def balance_history(user_id:, asset:, business: "", start_time: 0, end_time: 0, offset: 0, limit: 100, id: 0)
  request(id: id, method: "balance.history", params: [user_id, asset, business, start_time, end_time, offset, limit])
end

#buy_orders(market:, offset: 0, limit: 100, id: 0) ⇒ Object



116
117
118
# File 'lib/viabtc/http.rb', line 116

def buy_orders(market:, offset: 0, limit: 100, id: 0)
  request(id: id, method: "order.book", params: [market, 2, offset, limit])
end

#cancel_order(user_id:, market:, order_id:, id: 0) ⇒ Object



104
105
106
# File 'lib/viabtc/http.rb', line 104

def cancel_order(user_id:, market:, order_id:, id: 0)
  request(id: id, method: "order.cancel", params: [user_id, market, order_id])
end

#deposit(user_id:, asset:, deposit_id:, amount:, source: "web", id: 0) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/viabtc/http.rb', line 34

def deposit(user_id:, asset:, deposit_id:, amount:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)

  request(
    id: id,
    method: "balance.update",
    params: [user_id, asset, "deposit", deposit_id, amount, {source: source}]
  )
end

#finished_buy_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 2, id: 0) ⇒ Object



140
141
142
# File 'lib/viabtc/http.rb', line 140

def finished_buy_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 2, id: 0)
  request(id: id, method: "order.finished", params: [user_id, market, start_time, end_time, offset, limit, side])
end

#finished_order_detail(order_id:, id: 0) ⇒ Object



144
145
146
# File 'lib/viabtc/http.rb', line 144

def finished_order_detail(order_id:, id: 0)
  request(id: id, method: "order.finished_detail", params: [order_id])
end

#finished_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 0, id: 0) ⇒ Object



132
133
134
# File 'lib/viabtc/http.rb', line 132

def finished_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 0, id: 0)
  request(id: id, method: "order.finished", params: [user_id, market, start_time, end_time, offset, limit, side])
end

#finished_sell_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 1, id: 0) ⇒ Object



136
137
138
# File 'lib/viabtc/http.rb', line 136

def finished_sell_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side: 1, id: 0)
  request(id: id, method: "order.finished", params: [user_id, market, start_time, end_time, offset, limit, side])
end

#limit_buy(user_id:, market:, amount:, price:, taker_fee_rate:, maker_fee_rate:, source: "web", id: 0) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/viabtc/http.rb', line 70

def limit_buy(user_id:, market:, amount:, price:, taker_fee_rate:, maker_fee_rate:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{maker_fee_rate}" unless fee_rate_valid?(maker_fee_rate)

  request(
    id: id,
    method: "order.put_limit",
    params: [user_id, market, 2, amount, price, taker_fee_rate, maker_fee_rate, source]
  )
end

#limit_sell(user_id:, market:, amount:, price:, taker_fee_rate:, maker_fee_rate:, source: "web", id: 0) ⇒ Object

Trade API



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/viabtc/http.rb', line 58

def limit_sell(user_id:, market:, amount:, price:, taker_fee_rate:, maker_fee_rate:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{maker_fee_rate}" unless fee_rate_valid?(maker_fee_rate)

  request(
    id: id,
    method: "order.put_limit",
    params: [user_id, market, 1, amount, price, taker_fee_rate, maker_fee_rate, source]
  )
end

#market_buy(user_id:, market:, amount:, taker_fee_rate:, source: "web", id: 0) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/viabtc/http.rb', line 93

def market_buy(user_id:, market:, amount:, taker_fee_rate:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)

  request(
    id: id,
    method: "order.put_market",
    params: [user_id, market, 2, amount, taker_fee_rate.to_s, source]
  )
end

#market_deals(market:, limit: 10_000, last_id: 0, id: 0) ⇒ Object



154
155
156
# File 'lib/viabtc/http.rb', line 154

def market_deals(market:, limit: 10_000, last_id: 0, id: 0)
  request(id: id, method: "market.deals", params: [market, limit, last_id])
end

#market_kline(market:, start_time: now - 86_400, end_time: now, interval: 3600, id: 0) ⇒ Object



162
163
164
# File 'lib/viabtc/http.rb', line 162

def market_kline(market:, start_time: now - 86_400, end_time: now, interval: 3600, id: 0)
  request(id: id, method: "market.kline", params: [market, start_time, end_time, interval])
end

#market_last(market:, id: 0) ⇒ Object

Market API



150
151
152
# File 'lib/viabtc/http.rb', line 150

def market_last(market:, id: 0)
  request(id: id, method: "market.last", params: [market])
end

#market_list(id: 0) ⇒ Object



174
175
176
# File 'lib/viabtc/http.rb', line 174

def market_list(id: 0)
  request(id: id, method: "market.list", params: [])
end

#market_sell(user_id:, market:, amount:, taker_fee_rate:, source: "web", id: 0) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/viabtc/http.rb', line 82

def market_sell(user_id:, market:, amount:, taker_fee_rate:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
  raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)

  request(
    id: id,
    method: "order.put_market",
    params: [user_id, market, 1, amount, taker_fee_rate.to_s, source]
  )
end

#market_status(market:, period: 86_400, id: 0) ⇒ Object



166
167
168
# File 'lib/viabtc/http.rb', line 166

def market_status(market:, period: 86_400, id: 0)
  request(id: id, method: "market.status", params: [market, period])
end

#market_status_today(market:, id: 0) ⇒ Object



170
171
172
# File 'lib/viabtc/http.rb', line 170

def market_status_today(market:, id: 0)
  market_status(market: market, period: 86_400, id: id)
end

#market_summary(id: 0) ⇒ Object



178
179
180
# File 'lib/viabtc/http.rb', line 178

def market_summary(id: 0)
  request(id: id, method: "market.summary", params: [])
end

#order_deals(order_id:, offset: 0, limit: 100, id: 0) ⇒ Object



108
109
110
# File 'lib/viabtc/http.rb', line 108

def order_deals(order_id:, offset: 0, limit: 100, id: 0)
  request(id: id, method: "order.deals", params: [order_id, offset, limit])
end

#order_depth(market:, limit: 100, interval: "0", id: 0) ⇒ Object



120
121
122
# File 'lib/viabtc/http.rb', line 120

def order_depth(market:, limit: 100, interval: "0", id: 0)
  request(id: id, method: "order.depth", params: [market, limit, interval])
end

#pending_order_details(order_id:, market:, id: 0) ⇒ Object



128
129
130
# File 'lib/viabtc/http.rb', line 128

def pending_order_details(order_id:, market:, id: 0)
  request(id: id, method: "order.pending_detail", params: [market, order_id])
end

#pending_orders(user_id:, market:, offset: 0, limit: 100, id: 0) ⇒ Object



124
125
126
# File 'lib/viabtc/http.rb', line 124

def pending_orders(user_id:, market:, offset: 0, limit: 100, id: 0)
  request(id: id, method: "order.pending", params: [user_id, market, offset, limit])
end

#sell_orders(market:, offset: 0, limit: 100, id: 0) ⇒ Object



112
113
114
# File 'lib/viabtc/http.rb', line 112

def sell_orders(market:, offset: 0, limit: 100, id: 0)
  request(id: id, method: "order.book", params: [market, 1, offset, limit])
end

#user_executed_orders(user_id:, market:, offset: 0, limit: 100, id: 0) ⇒ Object



158
159
160
# File 'lib/viabtc/http.rb', line 158

def user_executed_orders(user_id:, market:, offset: 0, limit: 100, id: 0)
  request(id: id, method: "market.user_deals", params: [user_id, market, offset, limit])
end

#withdraw(user_id:, asset:, withdraw_id:, amount:, source: "web", id: 0) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/viabtc/http.rb', line 24

def withdraw(user_id:, asset:, withdraw_id:, amount:, source: "web", id: 0)
  raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)

  request(
    id: id,
    method: "balance.update",
    params: [user_id, asset, "withdraw", withdraw_id, amount, {source: source}]
  )
end