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.3.6"

Class Method Summary collapse

Class Method Details

.all_coins_info!(recvWindow: nil, api_key: nil, api_secret_key: nil) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/binance/api.rb', line 4

def all_coins_info!(recvWindow: nil, api_key: nil, api_secret_key: nil)
  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

.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]

Raises:



13
14
15
16
17
18
19
# File 'lib/binance/api.rb', line 13

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

Raises:



21
22
23
24
25
26
27
28
# File 'lib/binance/api.rb', line 21

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

Raises:



30
31
32
33
34
35
# File 'lib/binance/api.rb', line 30

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



37
38
39
40
# File 'lib/binance/api.rb', line 37

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

Raises:



42
43
44
45
46
47
# File 'lib/binance/api.rb', line 42

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



49
50
51
52
53
54
# File 'lib/binance/api.rb', line 49

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



56
57
58
# File 'lib/binance/api.rb', line 56

def ping!
  Request.send!(path: "/api/v1/ping")
end

.ticker!(symbol: nil, type: nil, api_key: nil, api_secret_key: nil) ⇒ Object

Raises:



60
61
62
63
64
65
66
67
68
# File 'lib/binance/api.rb', line 60

def ticker!(symbol: 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 = symbol ? { symbol: symbol } : {}
  Request.send!(api_key_type: :read_info, path: path, params: params,
                api_key: api_key, api_secret_key: api_secret_key)
end

.time!Object



70
71
72
# File 'lib/binance/api.rb', line 70

def time!
  Request.send!(path: "/api/v1/time")
end

.trades!(symbol: nil, limit: 500, api_key: nil, api_secret_key: nil) ⇒ Object

Raises:



74
75
76
77
78
79
# File 'lib/binance/api.rb', line 74

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