Class: Binance::SDK::Orders

Inherits:
Object
  • Object
show all
Defined in:
lib/binance/sdk/orders.rb

Class Method Summary collapse

Class Method Details

.cancel_order!(symbol:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/binance/sdk/orders.rb', line 63

def cancel_order!(symbol:)
  params = {
    recvWindow: 60000,
    timestamp: Configuration.timestamp.to_i - 1000,
    symbol: symbol,
    type: 'MARKET'
  }

  Request.send!(
    method: :delete,
    api_key_type: :read_info, path: Endpoints.fetch(:put_order),
    params: params.delete_if { |_, value| value.nil? },
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end

.cancel_orders!(symbol:) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/binance/sdk/orders.rb', line 79

def cancel_orders!(symbol:)
  params = {
    recvWindow: 60000,
    timestamp: Configuration.timestamp.to_i - 1000,
    symbol: symbol
  }

  Request.send!(
    method: :delete,
    api_key_type: :read_info, path: Endpoints.fetch(:cancel_orders),
    params: params.delete_if { |_, value| value.nil? },
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end

.change_leverage(symbol:, leverage:) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/binance/sdk/orders.rb', line 94

def change_leverage(symbol:, leverage:)
  params = {
    symbol: symbol,
    leverage: leverage.to_i,
    timestamp: Configuration.timestamp
  }

  Request.send!(
    method: :post,
    api_key_type: :read_info, path: Endpoints.fetch(:change_leverage),
    params: params,
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end

.close_position!(symbol:, side:, quantity:) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/binance/sdk/orders.rb', line 26

def close_position!(symbol:, side:, quantity:)
  params = {
    recvWindow: 60000,
    timestamp: Configuration.timestamp.to_i - 1000,
    symbol: symbol,
    side: side,
    type: 'MARKET',
    quantity: quantity,
    positionSide: side,
  }

  Request.send!(
    method: :post,
    api_key_type: :read_info, path: Endpoints.fetch(:put_order),
    params: params.delete_if { |_, value| value.nil? },
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end

.put_order!(symbol:, type: 'TRAILING_STOP_MARKET', side: 'BUY', callback_rate: 4, quantity: 1.0, working_type: nil, position_side: 'BOTH') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/binance/sdk/orders.rb', line 5

def put_order!(symbol:, type: 'TRAILING_STOP_MARKET', side: 'BUY', callback_rate: 4, quantity: 1.0, working_type: nil, position_side: 'BOTH')
  params = {
    recvWindow: 60000,
    timestamp: Configuration.timestamp.to_i - 1000,
    symbol: symbol,
    side: side,
    type: type,
    quantity: quantity,
    callbackRate: callback_rate,
    workingType: working_type,
    positionSide: position_side,
  }

  Request.send!(
    method: :post,
    api_key_type: :read_info, path: Endpoints.fetch(:put_order),
    params: params.delete_if { |_, value| value.nil? },
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end

.stop_loss(symbol:, side:, stop_price:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/binance/sdk/orders.rb', line 45

def stop_loss(symbol:, side:, stop_price:)
  params = {
    recvWindow: 60000,
    timestamp: Configuration.timestamp.to_i - 1000,
    symbol: symbol,
    type: 'STOP',
    side: side,
    stopPrice: stop_price
  }

  Request.send!(
    method: :post,
    api_key_type: :read_info, path: Endpoints.fetch(:put_order),
    params: params.delete_if { |_, value| value.nil? },
    security_type: :user_data, api_key: Configuration.api_key, api_secret_key: Configuration.secret_key
  )
end