Class: Binance::Api::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/binance/api/order.rb

Class Method Summary collapse

Class Method Details

.all!(limit: 500, order_id: nil, recv_window: 5000, symbol: nil) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
# File 'lib/binance/api/order.rb', line 5

def all!(limit: 500, order_id: nil, recv_window: 5000, symbol: nil)
  raise Error.new(message: "max limit is 500") unless limit <= 500
  raise Error.new(message: "symbol is required") if symbol.nil?
  timestamp = Configuration.timestamp
  params = { limit: limit, orderId: order_id, recvWindow: recv_window, symbol: symbol, timestamp: timestamp }
  Request.send!(api_key_type: :read_info, path: "/api/v3/allOrders",
                params: params.delete_if { |key, value| value.nil? },
                security_type: :user_data)
end

.all_open!(recv_window: 5000, symbol: nil) ⇒ Object

Be careful when accessing without a symbol!



16
17
18
19
20
21
# File 'lib/binance/api/order.rb', line 16

def all_open!(recv_window: 5000, symbol: nil)
  timestamp = Configuration.timestamp
  params = { recvWindow: recv_window, symbol: symbol, timestamp: timestamp }
  Request.send!(api_key_type: :read_info, path: '/api/v3/openOrders',
                params: params, security_type: :user_data)
end

.cancel!(order_id: nil, original_client_order_id: nil, new_client_order_id: nil, recv_window: nil, symbol: nil) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/binance/api/order.rb', line 23

def cancel!(order_id: nil, original_client_order_id: nil, new_client_order_id: nil, recv_window: nil, symbol: nil)
  raise Error.new(message: "symbol is required") if symbol.nil?
  raise Error.new(message: "either order_id or original_client_order_id " \
    "is required") if order_id.nil? && original_client_order_id.nil?
  timestamp = Configuration.timestamp
  params = { orderId: order_id, origClientOrderId: original_client_order_id,
             newClientOrderId: new_client_order_id, recvWindow: recv_window,
             symbol: symbol, timestamp: timestamp }.delete_if { |key, value| value.nil? }
  Request.send!(api_key_type: :trading, method: :delete, path: "/api/v3/order",
                params: params, security_type: :trade)
end

.create!(iceberg_quantity: nil, new_client_order_id: nil, new_order_response_type: nil, price: nil, quantity: nil, recv_window: nil, stop_price: nil, symbol: nil, side: nil, type: nil, time_in_force: nil, test: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/binance/api/order.rb', line 35

def create!(iceberg_quantity: nil, new_client_order_id: nil, new_order_response_type: nil,
            price: nil, quantity: nil, recv_window: nil, stop_price: nil, symbol: nil,
            side: nil, type: nil, time_in_force: nil, test: false)
  timestamp = Configuration.timestamp
  ensure_required_create_keys!(params: {
    iceberg_quantity: iceberg_quantity, new_client_order_id: new_client_order_id,
    new_order_response_type: new_order_response_type, price: price,
    quantity: quantity, recv_window: recv_window, stop_price: stop_price,
    symbol: symbol, side: side, type: type, time_in_force: time_in_force,
    timestamp: timestamp
  })
  params = { 
    icebergQty: iceberg_quantity, newClientOrderId: new_client_order_id,
    newOrderRespType: new_order_response_type, price: price, quantity: quantity,
    recvWindow: recv_window, stopPrice: stop_price, symbol: symbol, side: side,
    type: type, timeInForce: time_in_force, timestamp: timestamp
  }.delete_if { |key, value| value.nil? }
  path = "/api/v3/order#{'/test' if test}"
  Request.send!(api_key_type: :trading, method: :post, path: path,
                params: params, security_type: :trade)
end

.status!(order_id: nil, original_client_order_id: nil, recv_window: nil, symbol: nil) ⇒ Object

Raises:



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

def status!(order_id: nil, original_client_order_id: nil, recv_window: nil, symbol: nil)
  raise Error.new(message: "symbol is required") if symbol.nil?
  raise Error.new(message: "either order_id or original_client_order_id " \
    "is required") if order_id.nil? && original_client_order_id.nil?
  timestamp = Configuration.timestamp
  params = {
    orderId: order_id, origClientOrderId: original_client_order_id, recvWindow: recv_window,
    symbol: symbol, timestamp: timestamp
  }.delete_if { |key, value| value.nil? }
  Request.send!(api_key_type: :trading, path: "/api/v3/order",
                params: params, security_type: :user_data)
end