Module: Binance::Api
- Defined in:
- lib/binance/api.rb,
lib/binance/api/error.rb,
lib/binance/api/order.rb,
lib/binance/api/trade.rb,
lib/binance/api/margin.rb,
lib/binance/api/account.rb,
lib/binance/api/request.rb,
lib/binance/api/version.rb,
lib/binance/api/margin/order.rb,
lib/binance/api/configuration.rb,
lib/binance/api/market_stream.rb,
lib/binance/api/margin/account.rb,
lib/binance/api/user_data_stream.rb
Defined Under Namespace
Modules: Margin
Classes: Account, Configuration, Error, MarketStream, Order, Request, Trade, UserDataStream
Constant Summary
collapse
- VERSION =
"1.4.1"
Class Method Summary
collapse
-
.all_coins_info!(recvWindow: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.avg!(symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.candlesticks!(endTime: nil, interval: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
Valid limits:[5, 10, 20, 50, 100, 500, 1000].
-
.compressed_aggregate_trades!(endTime: nil, fromId: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.depth!(symbol: nil, limit: 100, api_key: nil, api_secret_key: nil) ⇒ Object
-
.exchange_info!(api_key: nil, api_secret_key: nil) ⇒ Object
-
.historical_trades!(symbol: nil, limit: 500, fromId: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.info!(recvWindow: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.ping! ⇒ Object
-
.ticker!(symbol: nil, symbols: nil, type: nil, api_key: nil, api_secret_key: nil) ⇒ Object
-
.time! ⇒ Object
-
.trades!(symbol: nil, limit: 500, api_key: nil, api_secret_key: nil) ⇒ Object
Class Method Details
.all_coins_info!(recvWindow: nil, api_key: nil, api_secret_key: nil) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/binance/api.rb', line 4
def all_coins_info!(recvWindow: nil, api_key: nil, api_secret_key: nil)
if Configuration.base_url.include?("testnet")
raise Error.new(message: "use mainnet for this method. testnet is meant for spot trading and order execution.")
end
timestamp = Configuration.timestamp
params = { recvWindow: recvWindow, timestamp: timestamp }
Request.send!(api_key_type: :read_info, security_type: :user_data,
path: "/sapi/v1/capital/config/getall", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.avg!(symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
91
92
93
94
95
96
|
# File 'lib/binance/api.rb', line 91
def avg!(symbol: nil, api_key: nil, api_secret_key: nil)
raise Error.new(message: "symbol is required") unless symbol
params = { symbol: symbol }
Request.send!(api_key_type: :read_info, path: "/api/v3/avgPrice", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.candlesticks!(endTime: nil, interval: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
Valid limits:[5, 10, 20, 50, 100, 500, 1000]
17
18
19
20
21
22
23
|
# File 'lib/binance/api.rb', line 17
def candlesticks!(endTime: nil, interval: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil)
raise Error.new(message: "interval is required") unless interval
raise Error.new(message: "symbol is required") unless symbol
params = { endTime: endTime, interval: interval, limit: limit, startTime: startTime, symbol: symbol }
Request.send!(api_key_type: :read_info, path: "/api/v1/klines", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.compressed_aggregate_trades!(endTime: nil, fromId: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/binance/api.rb', line 25
def compressed_aggregate_trades!(endTime: nil, fromId: nil, limit: 500, startTime: nil, symbol: nil, api_key: nil, api_secret_key: nil)
raise Error.new(message: "symbol is required") unless symbol
params = {
endTime: endTime, fromId: fromId, limit: limit, startTime: startTime, symbol: symbol,
}.delete_if { |key, value| value.nil? }
Request.send!(api_key_type: :read_info, path: "/api/v1/aggTrades", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.depth!(symbol: nil, limit: 100, api_key: nil, api_secret_key: nil) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/binance/api.rb', line 34
def depth!(symbol: nil, limit: 100, api_key: nil, api_secret_key: nil)
raise Error.new(message: "symbol is required") unless symbol
params = { limit: limit, symbol: symbol }
Request.send!(api_key_type: :read_info, path: "/api/v1/depth", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.exchange_info!(api_key: nil, api_secret_key: nil) ⇒ Object
41
42
43
44
|
# File 'lib/binance/api.rb', line 41
def exchange_info!(api_key: nil, api_secret_key: nil)
Request.send!(api_key_type: :read_info, path: "/api/v1/exchangeInfo",
api_key: api_key, api_secret_key: api_secret_key)
end
|
.historical_trades!(symbol: nil, limit: 500, fromId: nil, api_key: nil, api_secret_key: nil) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/binance/api.rb', line 46
def historical_trades!(symbol: nil, limit: 500, fromId: nil, api_key: nil, api_secret_key: nil)
raise Error.new(message: "symbol is required") unless symbol
params = { fromId: fromId, limit: limit, symbol: symbol }
Request.send!(api_key_type: :read_info, path: "/api/v1/historicalTrades", params: params,
security_type: :market_data, api_key: api_key, api_secret_key: api_secret_key)
end
|
.info!(recvWindow: nil, api_key: nil, api_secret_key: nil) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/binance/api.rb', line 53
def info!(recvWindow: nil, api_key: nil, api_secret_key: nil)
timestamp = Configuration.timestamp
params = { recvWindow: recvWindow, timestamp: timestamp }.delete_if { |key, value| value.nil? }
Request.send!(api_key_type: :read_info, path: "/api/v3/account", params: params, security_type: :user_data,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.ping! ⇒ Object
60
61
62
|
# File 'lib/binance/api.rb', line 60
def ping!
Request.send!(path: "/api/v1/ping")
end
|
.ticker!(symbol: nil, symbols: nil, type: nil, api_key: nil, api_secret_key: nil) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/binance/api.rb', line 64
def ticker!(symbol: nil, symbols: nil, type: nil, api_key: nil, api_secret_key: nil)
ticker_type = type&.to_sym
error_message = "type must be one of: #{ticker_types.join(", ")}. #{type} was provided."
raise Error.new(message: error_message) unless ticker_types.include? ticker_type
path = ticker_path(type: ticker_type)
params = if symbol
{ symbols: symbol }
elsif symbols
{ symbols: symbols.to_s.delete(' ') }
else
{}
end
Request.send!(api_key_type: :read_info, path: path, params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|
.time! ⇒ Object
80
81
82
|
# File 'lib/binance/api.rb', line 80
def time!
Request.send!(path: "/api/v1/time")
end
|
.trades!(symbol: nil, limit: 500, api_key: nil, api_secret_key: nil) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/binance/api.rb', line 84
def trades!(symbol: nil, limit: 500, api_key: nil, api_secret_key: nil)
raise Error.new(message: "symbol is required") unless symbol
params = { limit: limit, symbol: symbol }
Request.send!(api_key_type: :read_info, path: "/api/v1/trades", params: params,
api_key: api_key, api_secret_key: api_secret_key)
end
|