Module: BitflyerApi::Methods::Private::Trade

Included in:
Client
Defined in:
lib/bitflyer_api/methods/private/trade.rb

Instance Method Summary collapse

Instance Method Details

#my_cancel_all_child_orders(product_code:) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bitflyer_api/methods/private/trade.rb', line 49

def my_cancel_all_child_orders(product_code:)
  body = "{
    'product_code': \"#{product_code}\"
  }"

  res = conn.post do |req|
    req.url "/v1/me/cancelallchildorders"
    req.body = body
  end

  res.body
end

#my_cancel_child_order(product_code:, child_order_id: nil, child_order_acceptance_id: nil) ⇒ Object

TODO: merge child_order_id and child_order_acceptance_id



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bitflyer_api/methods/private/trade.rb', line 25

def my_cancel_child_order(product_code:, child_order_id: nil, child_order_acceptance_id: nil)
  return unless child_order_id || child_order_acceptance_id

  body =
    if child_order_id
      "{
        'product_code': \"#{product_code}\",
        'child_order_id': \"#{child_order_id}\"
      }"
    elsif child_order_acceptance_id
      "{
        'product_code': \"#{product_code}\",
        'child_order_acceptance_id': \"#{child_order_acceptance_id}\"
      }"
    end

  res = conn.post do |req|
    req.url "/v1/me/cancelchildorder"
    req.body = body
  end

  res.body
end

#my_cancel_parent_order(product_code:, parent_order_id: nil, parent_order_acceptance_id: nil) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/bitflyer_api/methods/private/trade.rb', line 214

def my_cancel_parent_order(product_code:, parent_order_id: nil, parent_order_acceptance_id: nil)
  return unless parent_order_id || parent_order_acceptance_id

  body =
    if parent_order_id
      "{
        'product_code': \"#{product_code}\",
        'parent_order_id': \"#{parent_order_id}\",
      }"
    elsif parent_order_acceptance_id
      "{
        'product_code': \"#{product_code}\",
        'parent_order_acceptance_id': \"#{parent_order_acceptance_id}\",
      }"
    end

  res = conn.post do |req|
    req.url "/v1/me/cancelparentorder"
    req.body = body
  end

  res.body
end

#my_child_orders(product_code:, count: 100, before: nil, after: nil, child_order_state: nil, child_order_id: nil, child_order_acceptance_id: nil, parent_order_id: nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bitflyer_api/methods/private/trade.rb', line 62

def my_child_orders(product_code:, count: 100, before: nil, after: nil, child_order_state: nil, child_order_id: nil, child_order_acceptance_id: nil, parent_order_id: nil)
  query = prepare_query(
    product_code: product_code,
    count: count,
    before: before,
    after: after,
    child_order_state: child_order_state,
    child_order_id: child_order_id,
    child_order_acceptance_id: child_order_acceptance_id,
    parent_order_id: parent_order_id
  )

  res = conn.get("/v1/me/getchildorders", query)
  res.body
end

#my_collateral_history(count: 100, before: nil, after: nil) ⇒ Object



259
260
261
262
263
264
265
266
267
268
# File 'lib/bitflyer_api/methods/private/trade.rb', line 259

def my_collateral_history(count: 100, before: nil, after: nil)
  query = prepare_query(
    count: count,
    before: before,
    after: after
  )

  res = conn.get("/v1/me/getcollateralhistory", query)
  res.body
end

#my_executions(product_code:, count: 100, before: nil, after: nil, child_order_id: nil, child_order_acceptance_id: nil) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/bitflyer_api/methods/private/trade.rb', line 238

def my_executions(product_code:, count: 100, before: nil, after: nil, child_order_id: nil, child_order_acceptance_id: nil)
  query = prepare_query(
    product_code: product_code,
    count: count,
    before: before,
    after: after,
    child_order_id: child_order_id,
    child_order_acceptance_id: child_order_acceptance_id
  )

  res = conn.get("/v1/me/getexecutions", query)
  res.body
end

#my_parent_order(parent_order_id: nil, parent_order_acceptance_id: nil) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/bitflyer_api/methods/private/trade.rb', line 200

def my_parent_order(parent_order_id: nil, parent_order_acceptance_id: nil)
  return unless parent_order_id || parent_order_acceptance_id

  query =
    if parent_order_id
      {parent_order_id: parent_order_id}
    else
      {parent_order_acceptance_id: parent_order_acceptance_id}
    end

  res = conn.get("/v1/me/getparentorder", query)
  res.body
end

#my_parent_orders(product_code:, count: 100, before: nil, after: nil, parent_order_state: nil) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/bitflyer_api/methods/private/trade.rb', line 187

def my_parent_orders(product_code:, count: 100, before: nil, after: nil, parent_order_state: nil)
  query = prepare_query(
    product_code: product_code,
    count: count,
    before: before,
    after: after,
    parent_order_state: parent_order_state
  )

  res = conn.get("/v1/me/getparentorders", query)
  res.body
end

#my_positions(product_code:) ⇒ Object



252
253
254
255
256
257
# File 'lib/bitflyer_api/methods/private/trade.rb', line 252

def my_positions(product_code:)
  query = prepare_query(product_code: product_code)

  res = conn.get("/v1/me/getpositions", query)
  res.body
end

#my_send_child_order(product_code:, child_order_type:, side:, price: nil, size:, minute_to_expire: 43200, time_in_force: "GTC") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bitflyer_api/methods/private/trade.rb', line 3

def my_send_child_order(product_code:, child_order_type:, side:, price: nil, size:,
  minute_to_expire: 43200, time_in_force: "GTC")

  body = "{
    'product_code': \"#{product_code}\",
    'child_order_type': \"#{child_order_type}\",
    'side': \"#{side}\",
    'price': #{price},
    'size': #{size},
    'minute_to_expire': #{minute_to_expire},
    'time_in_force': \"#{time_in_force}\"
  }"

  res = conn.post do |req|
    req.url "/v1/me/sendchildorder"
    req.body = body
  end

  res.body
end

#my_send_parent_order(order_method: "SIMPLE", minute_to_expire: 43200, time_in_force: "GTC", product_code:, first_condition_type:, second_condition_type:, third_condition_type: nil, first_side:, second_side:, third_side: nil, size:, first_price: nil, second_price: nil, third_price: nil, first_trigger_price: nil, second_trigger_price: nil, third_trigger_price: nil, offset: nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/bitflyer_api/methods/private/trade.rb', line 78

def my_send_parent_order(
  order_method: "SIMPLE",
  minute_to_expire: 43200,
  time_in_force: "GTC",
  product_code:,
  first_condition_type:,
  second_condition_type:,
  third_condition_type: nil,
  first_side:,
  second_side:,
  third_side: nil,
  size:,
  first_price: nil,
  second_price: nil,
  third_price: nil,
  first_trigger_price: nil,
  second_trigger_price: nil,
  third_trigger_price: nil,
  offset: nil
)

  body =
    case order_method
    when "IFD"
      "{
         'order_method': \"#{order_method}\",
         'minute_to_expire': #{minute_to_expire},
         'time_in_force': \"#{time_in_force}\",
         'parameters': [{
           'product_code': \"#{product_code}\",
           'condition_type': \"#{first_condition_type}\",
           'side': \"#{first_side}\",
           'price': #{first_price},
           'trigger_price': #{first_trigger_price},
           'size': #{size}
         },
         {
           'product_code': \"#{product_code}\",
           'condition_type': \"#{second_condition_type}\",
           'side': \"#{second_side}\",
           'price': #{second_price},
           'trigger_price': #{second_trigger_price},
           'size': #{size}
         }]
       }"
    when "OCO"
      "{
         'order_method': \"#{order_method}\",
         'minute_to_expire': #{minute_to_expire},
         'time_in_force': \"#{time_in_force}\",
         'parameters': [{
           'product_code': \"#{product_code}\",
           'condition_type': \"#{first_condition_type}\",
           'side': \"#{first_side}\",
           'price': #{first_price},
           'trigger_price': #{first_trigger_price},
           'size': #{size}
         },
         {
           'product_code': \"#{order_method}\",
           'condition_type': \"#{second_condition_type}\",
           'side': \"#{second_side}\",
           'price': #{second_price},
           'trigger_price': #{second_trigger_price},
           'size': #{size}
         }]
       }"
    when "IFDOCO"
      "{
        'order_method': \'#{order_method}\',
        'minute_to_expire': #{minute_to_expire},
        'time_in_force': \"#{time_in_force}\",
        'parameters': [{
          'product_code': \"#{product_code}\",
          'condition_type': \"#{first_condition_type}\",
          'side': \"#{first_side}\",
          'price': #{first_price},
          'trigger_price': #{first_trigger_price},
          'size': #{size}
        },
        {
          'product_code': \"#{product_code}\",
          'condition_type': \"#{second_condition_type}\",
          'side': \"#{second_side}\",
          'price': #{second_price},
          'trigger_price': #{second_trigger_price},
          'size': #{size}
        },
        {
          'product_code': \"#{product_code}\",
          'condition_type': \"#{third_condition_type}\",
          'side': \"#{third_side}\",
          'price': #{third_price},
          'trigger_price': #{third_trigger_price},
          'size': #{size}
        }]
      }"

    else # SIMPLE
    end

  res = conn.post do |req|
    req.url "/v1/me/sendparentorder"
    req.body = body
  end

  res.body
end

#my_trading_commission(product_code:) ⇒ Object



270
271
272
273
274
275
# File 'lib/bitflyer_api/methods/private/trade.rb', line 270

def my_trading_commission(product_code:)
  query = prepare_query(product_code: product_code)

  res = conn.get("/v1/me/gettradingcommission", query)
  res.body
end