Module: Bibox::Rest::Private::Orders

Included in:
Client
Defined in:
lib/bibox/rest/private/orders.rb

Instance Method Summary collapse

Instance Method Details

#buy(pair:, price:, amount:, order_type: :limit, pay_fees_with_bix: true, options: {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bibox/rest/private/orders.rb', line 6

def buy(pair:, price:, amount:, order_type: :limit, pay_fees_with_bix: true, options: {})
  perform_order(
    pair:               pair,
    price:              price,
    amount:             amount,
    order_side:         :buy,
    order_type:         order_type,
    pay_fees_with_bix:  pay_fees_with_bix,
    options:            options
  )
end

#cancel_order(order_id, options: {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bibox/rest/private/orders.rb', line 52

def cancel_order(order_id, options: {})
  payload     =   [
    {
      cmd:  "orderpending/cancelTrade",
      body: {orders_id: order_id}
    }
  ]
  
  response    =   parse(post("/orderpending", data: payload, options: options))
  
  return true
end

#list_orders(type: :pending, params: {}, options: {}) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bibox/rest/private/orders.rb', line 97

def list_orders(type: :pending, params: {}, options: {})          
  params[:page]            ||=   1
  params[:size]            ||=   10
  
  command   =   case type
    when :pending
      "orderpending/orderPendingList"
    when :history
      "orderpending/orderHistoryList"
  end
  
  params.delete_if { |key, value| value.nil? }
  
  case params[:order_side]
    when 1, :buy
      params[:order_side] = ::Bibox::Constants::BUY_ORDER
    when 2, :sell
      params[:order_side] = ::Bibox::Constants::SELL_ORDER
  end
  
  payload     =   [
    {
      cmd:  command,
      body: params
    }
  ]
  
  response    =   parse(post("/orderpending", data: payload, options: options))&.fetch("result", [])&.first&.fetch("result", {})&.fetch("items", [])
  ::Bibox::Models::Order.parse(response) if response&.any?
end

#order_history(pair: nil, page: 1, size: 10, hide_cancel: nil, coin_symbol: nil, currency_symbol: nil, order_side: nil, account_type: nil, options: {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bibox/rest/private/orders.rb', line 82

def order_history(pair: nil, page: 1, size: 10, hide_cancel: nil, coin_symbol: nil, currency_symbol: nil, order_side: nil, account_type: nil, options: {})
  params      =   {
    pair:             pair,
    page:             page,
    size:             size,
    hide_cancel:      hide_cancel,
    coin_symbol:      coin_symbol,
    currency_symbol:  currency_symbol,
    order_side:       order_side,
    account_type:     ,
  }
  
  return list_orders(type: :history, params: params, options: options)
end

#pending_orders(pair: nil, page: 1, size: 10, coin_symbol: nil, currency_symbol: nil, order_side: nil, account_type: nil, options: {}) ⇒ Object

A currency pair can be specified using its code, e.g. BIX_ETH Or separately using coin_symbol and currency_symbol (which the Bibox UI seems to use)



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/bibox/rest/private/orders.rb', line 68

def pending_orders(pair: nil, page: 1, size: 10, coin_symbol: nil, currency_symbol: nil, order_side: nil, account_type: nil, options: {})          
  params      =   {
    pair:             pair,
    page:             page,
    size:             size,
    coin_symbol:      coin_symbol,
    currency_symbol:  currency_symbol,
    order_side:       order_side,
    account_type:     ,
  }
  
  return list_orders(type: :pending, params: params, options: options)
end

#perform_order(pair:, price:, amount:, order_side: :buy, order_type: :limit, account_type: 0, pay_fees_with_bix: true, options: {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bibox/rest/private/orders.rb', line 30

def perform_order(pair:, price:, amount:, order_side: :buy, order_type: :limit, account_type: 0, pay_fees_with_bix: true, options: {})
  params      =   {
    pair:           pair,
    account_type:   ,
    order_type:     Bibox::Models::Order::ORDER_TYPES[order_type],
    order_side:     Bibox::Models::Order::ORDER_SIDES[order_side],
    pay_bix:        pay_fees_with_bix.eql?(true) ? 1 : 0,
    price:          price,
    amount:         amount,
    money:          (price * amount),
  }
  
  payload     =   [
    {
      cmd:  "orderpending/trade",
      body: params
    }
  ]
  
  response    =   parse(post("/orderpending", data: payload, options: options))&.fetch("result", [])&.first&.fetch("result", {})&.to_s
end

#sell(pair:, price:, amount:, order_type: :limit, pay_fees_with_bix: true, options: {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bibox/rest/private/orders.rb', line 18

def sell(pair:, price:, amount:, order_type: :limit, pay_fees_with_bix: true, options: {})
  perform_order(
    pair:               pair,
    price:              price,
    amount:             amount,
    order_side:         :sell,
    order_type:         order_type,
    pay_fees_with_bix:  pay_fees_with_bix,
    options:            options
  )
end