clickclient 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,728 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "runit/testcase"
4
+
5
+ #clickclientのテスト。
6
+ #約定なしに試せる機能(決済、建玉一覧、約定一覧以外の機能)のテストを実際のサーバーに接続し行う。
7
+ #実行時にユーザー名/パスワードを引数で指定すること。
8
+ #
9
+ # ruby connect_test_fx.rb <CLICK証券のユーザー名> <CLICK証券のパスワード>
10
+ #
11
+ class ClickClient_FxTest < RUNIT::TestCase
12
+
13
+ # ユーザー名
14
+ USER_NAME = ARGV[0]
15
+ # パスワード
16
+ PASSWORD = ARGV[1]
17
+
18
+ #待ち時間。
19
+ #注文変更後、即座に一覧を取得すると変更中の場合があるため、一定時間待つ。
20
+ WAIT = 5
21
+
22
+ CURRENCY_PAIRS = [
23
+ ClickClient::FX::USDJPY, ClickClient::FX::EURJPY, ClickClient::FX::GBPJPY,
24
+ ClickClient::FX::AUDJPY, ClickClient::FX::NZDJPY, ClickClient::FX::CADJPY,
25
+ ClickClient::FX::CHFJPY, ClickClient::FX::ZARJPY, ClickClient::FX::EURUSD,
26
+ ClickClient::FX::GBPUSD, ClickClient::FX::AUDUSD, ClickClient::FX::EURCHF,
27
+ ClickClient::FX::GBPCHF, ClickClient::FX::USDCHF]
28
+
29
+ def setup
30
+ @client = ClickClient::Client.new
31
+ end
32
+
33
+ def teardown
34
+ end
35
+
36
+ # 通貨ペア一覧取得のテスト
37
+ def test_list_currency_pairs
38
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
39
+ # 全一覧取得
40
+ list = fx.list_currency_pairs
41
+ CURRENCY_PAIRS.each {|code|
42
+ info = list[code]
43
+ assert_valid_currency_pair( info, code )
44
+ }
45
+
46
+ # ClickClient::FX::EURJPY, ClickClient::FX::CADJPY, ClickClient::FX::AUDUSDを取得
47
+ list = fx.list_currency_pairs( [ClickClient::FX::EURJPY, ClickClient::FX::CADJPY, ClickClient::FX::AUDUSD] )
48
+ assert_equals list.size, 3
49
+ assert_valid_currency_pair( list[ClickClient::FX::EURJPY], ClickClient::FX::EURJPY )
50
+ assert_valid_currency_pair( list[ClickClient::FX::CADJPY], ClickClient::FX::CADJPY )
51
+ assert_valid_currency_pair( list[ClickClient::FX::AUDUSD], ClickClient::FX::AUDUSD )
52
+ }
53
+ end
54
+
55
+ # 現在のレート一覧取得のテスト
56
+ def test_list_rates
57
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
58
+ list = fx.list_rates
59
+ CURRENCY_PAIRS.each {|code|
60
+ info = list[code]
61
+ assert_valid_rate( info, code )
62
+ }
63
+ }
64
+ end
65
+
66
+ # お知らせ一覧取得のテスト
67
+ def test_list_messages
68
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
69
+ list = fx.list_messages
70
+ list.each {|msg|
71
+ assert_not_nil msg.text
72
+ assert_not_nil msg.title
73
+ }
74
+ }
75
+ end
76
+
77
+ # 約定一覧取得のテスト
78
+ def test_list_execution_results
79
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
80
+ now = DateTime.now
81
+
82
+ # 範囲指定のみ
83
+ list = fx.list_execution_results now - 100, now
84
+ list.each {|execution_result|
85
+ assert_valid_execution_result( execution_result )
86
+ }
87
+
88
+ # 範囲指定、種別、通貨ペアコードを指定
89
+ list = fx.list_execution_results now - 100, now, ClickClient::FX::TRADE_TYPE_SETTLEMENT, ClickClient::FX::ZARJPY
90
+ list.each {|execution_result|
91
+ assert_valid_execution_result( execution_result )
92
+ }
93
+ }
94
+ end
95
+
96
+ # 余力情報取得のテスト
97
+ def test_get_margin
98
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
99
+ margin = fx.get_margin
100
+ assert_not_nil margin.margin
101
+ assert_not_nil margin.transferable_money_amount
102
+ assert_not_nil margin.guarantee_money_status
103
+ assert_not_nil margin.guarantee_money_maintenance_ratio
104
+ assert_not_nil margin.market_value
105
+ assert_not_nil margin.appraisal_profit_or_loss_of_open_interest
106
+ assert_not_nil margin.balance_in_account
107
+ assert_not_nil margin.balance_of_cach
108
+ assert_not_nil margin.settlement_profit_or_loss_of_today
109
+ assert_not_nil margin.settlement_profit_or_loss_of_next_business_day
110
+ assert_not_nil margin.settlement_profit_or_loss_of_next_next_business_day
111
+ assert_not_nil margin.swap_profit_or_loss
112
+ assert_not_nil margin.freezed_guarantee_money
113
+ assert_not_nil margin.required_guarantee_money
114
+ assert_not_nil margin.ordered_guarantee_money
115
+ margin.guarantee_money_list.each{|g|
116
+ assert_not_nil g.currency_pair_code
117
+ assert_not_nil g.guarantee_money
118
+ }
119
+ }
120
+ end
121
+
122
+ # 通常注文の発注、変更、キャンセルのテスト
123
+ def test_basic_order
124
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
125
+ list = fx.list_rates
126
+
127
+ # 注文
128
+ result = fx.order( ClickClient::FX::USDJPY, ClickClient::FX::BUY, 1, {
129
+ :rate=>list[ClickClient::FX::USDJPY].ask_rate - 5, # ask-5円で注文。5円急落しないと約定しないので大丈夫?
130
+ :execution_expression=>ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
131
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_TODAY
132
+ })
133
+ assert_not_nil result.order_no
134
+ order_no = result.order_no
135
+ begin
136
+
137
+ # 注文確認
138
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::USDJPY)
139
+ order = orders[order_no]
140
+ assert_equals order.order_no, result.order_no
141
+ assert_equals order.enable_change_or_cancel, true
142
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
143
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
144
+ assert_equals order.trade_quantity, 10000 # USDJPNなので1万単位
145
+ assert_equals order.rate, list[ClickClient::FX::USDJPY].ask - 5
146
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
147
+ assert_not_nil order.date
148
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_TODAY
149
+ assert_nil order.expiration_date
150
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
151
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
152
+ assert_nil order.settlement_rate
153
+ assert_nil order.settlement_date
154
+
155
+ #注文変更
156
+ new_rate = list[ClickClient::FX::USDJPY].ask_rate - 5.01
157
+ fx.edit_order( order_no, {
158
+ :rate=>new_rate,
159
+ :execution_expression=>ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
160
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_WEEK_END
161
+ })
162
+ sleep WAIT
163
+
164
+ # 注文確認
165
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::USDJPY)
166
+ order = orders[order_no]
167
+ assert_equals order.order_no, result.order_no
168
+ assert_equals order.enable_change_or_cancel, true
169
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
170
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
171
+ assert_equals order.trade_quantity, 10000 # USDJPNなので1万単位
172
+ assert_equals order.rate.to_s, new_rate.to_s
173
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
174
+ assert_not_nil order.date
175
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_WEEK_END
176
+ assert_nil order.expiration_date
177
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
178
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
179
+ assert_nil order.settlement_rate
180
+ assert_nil order.settlement_date
181
+
182
+ ensure
183
+ # キャンセル
184
+ fx.cancel_order order_no
185
+
186
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::USDJPY)
187
+ order = orders[order_no]
188
+ assert_equals order.order_no, result.order_no
189
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
190
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
191
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
192
+ assert_equals order.trade_quantity, 10000 # USDJPNなので1万単位
193
+ assert_equals order.rate.to_s, (list[ClickClient::FX::USDJPY].ask_rate - 5.01).to_s
194
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
195
+ assert_not_nil order.date
196
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_WEEK_END
197
+ assert_nil order.expiration_date
198
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
199
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
200
+ assert_nil order.settlement_rate
201
+ assert_nil order.settlement_date
202
+ end
203
+ }
204
+ end
205
+
206
+ # OCO注文の発注、変更、キャンセルのテスト
207
+ def test_oco_order
208
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
209
+ list = fx.list_rates
210
+
211
+ # 注文
212
+ limit_date = DateTime.now + 5
213
+ expect_limit = DateTime.new( limit_date.year, limit_date.mon, limit_date.day, limit_date.hour )
214
+
215
+ result = fx.order( ClickClient::FX::EURJPY, ClickClient::FX::BUY, 1, {
216
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate - 5,
217
+ :stop_order_rate=>list[ClickClient::FX::EURJPY].ask_rate + 5,
218
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
219
+ :expiration_date=>limit_date
220
+ })
221
+ assert_not_nil result.limit_order_no
222
+ limit_order_no = result.limit_order_no
223
+ stop_order_no = result.stop_order_no
224
+ begin
225
+
226
+ # 注文確認
227
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
228
+ order = orders[limit_order_no]
229
+ assert_equals order.order_no, result.limit_order_no
230
+ assert_equals order.enable_change_or_cancel, true
231
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
232
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
233
+ assert_equals order.trade_quantity, 10000
234
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5).to_s
235
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
236
+ assert_not_nil order.date
237
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
238
+ assert_equals order.expiration_date, expect_limit
239
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
240
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
241
+ assert_nil order.settlement_rate
242
+ assert_nil order.settlement_date
243
+
244
+ order = orders[stop_order_no]
245
+ assert_equals order.order_no, result.stop_order_no
246
+ assert_equals order.enable_change_or_cancel, true
247
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
248
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
249
+ assert_equals order.trade_quantity, 10000
250
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 5).to_s
251
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
252
+ assert_not_nil order.date
253
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
254
+ assert_equals order.expiration_date, expect_limit
255
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
256
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
257
+ assert_nil order.settlement_rate
258
+ assert_nil order.settlement_date
259
+
260
+ #注文変更
261
+ limit_date = DateTime.now + 6
262
+ expect_limit = DateTime.new( limit_date.year, limit_date.mon, limit_date.day, limit_date.hour )
263
+ fx.edit_order( limit_order_no, {
264
+ :stop_order_no=>stop_order_no,
265
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate - 5.01,
266
+ :stop_order_rate=>list[ClickClient::FX::EURJPY].ask_rate + 5.01,
267
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
268
+ :expiration_date=>limit_date
269
+ })
270
+ sleep WAIT
271
+
272
+ # 注文確認
273
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
274
+ order = orders[limit_order_no]
275
+ assert_equals order.order_no, result.limit_order_no
276
+ assert_equals order.enable_change_or_cancel, true
277
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
278
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
279
+ assert_equals order.trade_quantity, 10000
280
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5.01).to_s
281
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
282
+ assert_not_nil order.date
283
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
284
+ assert_equals order.expiration_date, expect_limit
285
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
286
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
287
+ assert_nil order.settlement_rate
288
+ assert_nil order.settlement_date
289
+
290
+ order = orders[stop_order_no]
291
+ assert_equals order.order_no, result.stop_order_no
292
+ assert_equals order.enable_change_or_cancel, true
293
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
294
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
295
+ assert_equals order.trade_quantity, 10000
296
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 5.01).to_s
297
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
298
+ assert_not_nil order.date
299
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
300
+ assert_equals order.expiration_date, expect_limit
301
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
302
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
303
+ assert_nil order.settlement_rate
304
+ assert_nil order.settlement_date
305
+
306
+ ensure
307
+ # キャンセル
308
+ fx.cancel_order limit_order_no
309
+
310
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
311
+ order = orders[limit_order_no]
312
+ assert_equals order.order_no, result.limit_order_no
313
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
314
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
315
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
316
+ assert_equals order.trade_quantity, 10000
317
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5.01).to_s
318
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
319
+ assert_not_nil order.date
320
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
321
+ assert_equals order.expiration_date, expect_limit
322
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
323
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
324
+ assert_nil order.settlement_rate
325
+ assert_nil order.settlement_date
326
+
327
+ order = orders[stop_order_no]
328
+ assert_equals order.order_no, result.stop_order_no
329
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
330
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
331
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
332
+ assert_equals order.trade_quantity, 10000
333
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 5.01).to_s
334
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
335
+ assert_not_nil order.date
336
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
337
+ assert_equals order.expiration_date, expect_limit
338
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
339
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
340
+ assert_nil order.settlement_rate
341
+ assert_nil order.settlement_date
342
+ end
343
+ }
344
+ end
345
+
346
+ # IFD注文の発注、変更、キャンセルのテスト
347
+ def test_ifd_order
348
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
349
+ list = fx.list_rates
350
+
351
+ # 注文
352
+ result = fx.order( ClickClient::FX::EURJPY, ClickClient::FX::SELL, 1, {
353
+ :rate=>list[ClickClient::FX::EURJPY].bid_rate + 5,
354
+ :execution_expression=>ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
355
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_INFINITY,
356
+ :settle=>{
357
+ :unit=>1,
358
+ :sell_or_buy=>ClickClient::FX::BUY,
359
+ :rate=>list[ClickClient::FX::EURJPY].bid_rate + 4,
360
+ :execution_expression=>ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
361
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_INFINITY,
362
+ }
363
+ })
364
+ assert_not_nil result.order_no
365
+ assert_not_nil result.settlement_order_no
366
+ order_no = result.order_no
367
+ settlement_order_no = result.settlement_order_no
368
+ begin
369
+
370
+ # 注文確認
371
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
372
+ order = orders[order_no]
373
+ assert_equals order.order_no, result.order_no
374
+ assert_equals order.enable_change_or_cancel, true
375
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
376
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
377
+ assert_equals order.trade_quantity, 10000
378
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 5).to_s
379
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
380
+ assert_not_nil order.date
381
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_INFINITY
382
+ assert_nil order.expiration_date
383
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
384
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
385
+ assert_nil order.settlement_rate
386
+ assert_nil order.settlement_date
387
+
388
+ order = orders[settlement_order_no]
389
+ assert_equals order.order_no, result.settlement_order_no
390
+ assert_equals order.enable_change_or_cancel, true
391
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
392
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
393
+ assert_equals order.trade_quantity, 10000
394
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 4).to_s
395
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
396
+ assert_not_nil order.date
397
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_INFINITY
398
+ assert_nil order.expiration_date
399
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
400
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
401
+ assert_nil order.settlement_rate
402
+ assert_nil order.settlement_date
403
+
404
+ #注文変更
405
+ limit_date = DateTime.now + 6
406
+ expect_limit = DateTime.new( limit_date.year, limit_date.mon, limit_date.day, limit_date.hour )
407
+ fx.edit_order( order_no, {
408
+ :rate=>list[ClickClient::FX::EURJPY].bid_rate + 5.01,
409
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
410
+ :expiration_date=>limit_date,
411
+ :settle=>{
412
+ :order_no=>settlement_order_no,
413
+ :rate=>list[ClickClient::FX::EURJPY].bid_rate + 4.01,
414
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
415
+ :expiration_date=>limit_date
416
+ }
417
+ })
418
+ sleep WAIT
419
+
420
+ # 注文確認
421
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
422
+ order = orders[order_no]
423
+ assert_equals order.order_no, result.order_no
424
+ assert_equals order.enable_change_or_cancel, true
425
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
426
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
427
+ assert_equals order.trade_quantity, 10000
428
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 5.01).to_s
429
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
430
+ assert_not_nil order.date
431
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
432
+ assert_equals order.expiration_date, expect_limit
433
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
434
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
435
+ assert_nil order.settlement_rate
436
+ assert_nil order.settlement_date
437
+
438
+ order = orders[settlement_order_no]
439
+ assert_equals order.order_no, result.settlement_order_no
440
+ assert_equals order.enable_change_or_cancel, true
441
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
442
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
443
+ assert_equals order.trade_quantity, 10000
444
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 4.01).to_s
445
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
446
+ assert_not_nil order.date
447
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
448
+ assert_equals order.expiration_date, expect_limit
449
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
450
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
451
+ assert_nil order.settlement_rate
452
+ assert_nil order.settlement_date
453
+
454
+ ensure
455
+ # キャンセル
456
+ fx.cancel_order order_no
457
+
458
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
459
+ order = orders[order_no]
460
+ assert_equals order.order_no, result.order_no
461
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
462
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
463
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
464
+ assert_equals order.trade_quantity, 10000
465
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 5.01).to_s
466
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
467
+ assert_not_nil order.date
468
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
469
+ assert_equals order.expiration_date, expect_limit
470
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
471
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
472
+ assert_nil order.settlement_rate
473
+ assert_nil order.settlement_date
474
+
475
+ order = orders[settlement_order_no]
476
+ assert_equals order.order_no, result.settlement_order_no
477
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
478
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
479
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
480
+ assert_equals order.trade_quantity, 10000
481
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].bid_rate + 4.01).to_s
482
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
483
+ assert_not_nil order.date
484
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
485
+ assert_equals order.expiration_date, expect_limit
486
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
487
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
488
+ assert_nil order.settlement_rate
489
+ assert_nil order.settlement_date
490
+ end
491
+ }
492
+ end
493
+
494
+ # IFD-OCO
495
+ def test_ifdoco_order
496
+ @client.fx_session(USER_NAME, PASSWORD){|fx|
497
+ list = fx.list_rates
498
+
499
+ limit_date = DateTime.now + 6
500
+ expect_limit = DateTime.new( limit_date.year, limit_date.mon, limit_date.day, limit_date.hour )
501
+
502
+ # 注文
503
+ result = fx.order( ClickClient::FX::EURJPY, ClickClient::FX::BUY, 1, {
504
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate - 5,
505
+ :execution_expression=>ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
506
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
507
+ :expiration_date=>limit_date,
508
+ :settle=>{
509
+ :unit=>1,
510
+ :sell_or_buy=>ClickClient::FX::SELL,
511
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate + 4,
512
+ :stop_order_rate=>list[ClickClient::FX::EURJPY].ask_rate - 6,
513
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
514
+ :expiration_date=>limit_date,
515
+ }
516
+ })
517
+
518
+ assert_not_nil result.order_no
519
+ assert_not_nil result.kessaiSashineChumonBango
520
+ assert_not_nil result.kessaiGyakusashiChumonBango
521
+ order_no = result.order_no
522
+ settlement_order_no = result.kessaiSashineChumonBango
523
+ reverse_settlement_order_no = result.kessaiGyakusashiChumonBango
524
+ begin
525
+
526
+ # 注文確認
527
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
528
+ order = orders[order_no]
529
+ assert_equals order.order_no, result.order_no
530
+ assert_equals order.enable_change_or_cancel, true
531
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
532
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
533
+ assert_equals order.trade_quantity, 10000
534
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5).to_s
535
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
536
+ assert_not_nil order.date
537
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
538
+ assert_equals order.expiration_date, expect_limit
539
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
540
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
541
+ assert_nil order.settlement_rate
542
+ assert_nil order.settlement_date
543
+
544
+ order = orders[settlement_order_no]
545
+ assert_equals order.order_no, settlement_order_no
546
+ assert_equals order.enable_change_or_cancel, true
547
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
548
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
549
+ assert_equals order.trade_quantity, 10000
550
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 4).to_s
551
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
552
+ assert_not_nil order.date
553
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
554
+ assert_equals order.expiration_date, expect_limit
555
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
556
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
557
+ assert_nil order.settlement_rate
558
+ assert_nil order.settlement_date
559
+
560
+ order = orders[reverse_settlement_order_no]
561
+ assert_equals order.order_no, reverse_settlement_order_no
562
+ assert_equals order.enable_change_or_cancel, true
563
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
564
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
565
+ assert_equals order.trade_quantity, 10000
566
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 6 ).to_s
567
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
568
+ assert_not_nil order.date
569
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
570
+ assert_equals order.expiration_date, expect_limit
571
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
572
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
573
+ assert_nil order.settlement_rate
574
+ assert_nil order.settlement_date
575
+
576
+ #注文変更
577
+ limit_date = DateTime.now + 7
578
+ expect_limit = DateTime.new( limit_date.year, limit_date.mon, limit_date.day, limit_date.hour )
579
+ fx.edit_order( order_no, {
580
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate - 5.01,
581
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
582
+ :expiration_date=>limit_date,
583
+ :settle=>{
584
+ :order_no=>settlement_order_no,
585
+ :stop_order_no=>reverse_settlement_order_no,
586
+ :rate=>list[ClickClient::FX::EURJPY].ask_rate + 4.01,
587
+ :stop_order_rate=>list[ClickClient::FX::EURJPY].ask_rate - 6.01,
588
+ :expiration_type=>ClickClient::FX::EXPIRATION_TYPE_SPECIFIED,
589
+ :expiration_date=>limit_date
590
+ }
591
+ })
592
+ sleep WAIT
593
+
594
+ # 注文確認
595
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
596
+ order = orders[order_no]
597
+ assert_equals order.order_no, order_no
598
+ assert_equals order.enable_change_or_cancel, true
599
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
600
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
601
+ assert_equals order.trade_quantity, 10000
602
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5.01).to_s
603
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
604
+ assert_not_nil order.date
605
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
606
+ assert_equals order.expiration_date, expect_limit
607
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_RECEIVED
608
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
609
+ assert_nil order.settlement_rate
610
+ assert_nil order.settlement_date
611
+
612
+ order = orders[settlement_order_no]
613
+ assert_equals order.order_no, settlement_order_no
614
+ assert_equals order.enable_change_or_cancel, true
615
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
616
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
617
+ assert_equals order.trade_quantity, 10000
618
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 4.01).to_s
619
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
620
+ assert_not_nil order.date
621
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
622
+ assert_equals order.expiration_date, expect_limit
623
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
624
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
625
+ assert_nil order.settlement_rate
626
+ assert_nil order.settlement_date
627
+
628
+ order = orders[reverse_settlement_order_no]
629
+ assert_equals order.order_no, reverse_settlement_order_no
630
+ assert_equals order.enable_change_or_cancel, true
631
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
632
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
633
+ assert_equals order.trade_quantity, 10000
634
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 6.01 ).to_s
635
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
636
+ assert_not_nil order.date
637
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
638
+ assert_equals order.expiration_date, expect_limit
639
+ assert_equals order.order_state, ClickClient::FX::ORDER_STATE_WAITING # 決済注文は待機中。
640
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_NOT_FAILED
641
+ assert_nil order.settlement_rate
642
+ assert_nil order.settlement_date
643
+
644
+ ensure
645
+ # キャンセル
646
+ fx.cancel_order order_no
647
+
648
+ orders = fx.list_orders( ClickClient::FX::ORDER_CONDITION_ALL, ClickClient::FX::EURJPY)
649
+ order = orders[order_no]
650
+ assert_equals order.order_no, result.order_no
651
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
652
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_NEW
653
+ assert_equals order.sell_or_buy, ClickClient::FX::BUY
654
+ assert_equals order.trade_quantity, 10000
655
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 5.01).to_s
656
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
657
+ assert_not_nil order.date
658
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
659
+ assert_equals order.expiration_date, expect_limit
660
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
661
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
662
+ assert_nil order.settlement_rate
663
+ assert_nil order.settlement_date
664
+
665
+ order = orders[settlement_order_no]
666
+ assert_equals order.order_no, settlement_order_no
667
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
668
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
669
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
670
+ assert_equals order.trade_quantity, 10000
671
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate + 4.01).to_s
672
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
673
+ assert_not_nil order.date
674
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
675
+ assert_equals order.expiration_date, expect_limit
676
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
677
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
678
+ assert_nil order.settlement_rate
679
+ assert_nil order.settlement_date
680
+
681
+ order = orders[reverse_settlement_order_no]
682
+ assert_equals order.order_no, reverse_settlement_order_no
683
+ #assert_equals order.enable_change_or_cancel, true #キャンセル後は変更不可だがタイミングによっては変更可となる。
684
+ assert_equals order.trade_type, ClickClient::FX::TRADE_TYPE_SETTLEMENT
685
+ assert_equals order.sell_or_buy, ClickClient::FX::SELL
686
+ assert_equals order.trade_quantity, 10000
687
+ assert_equals order.rate.to_s, (list[ClickClient::FX::EURJPY].ask_rate - 6.01 ).to_s
688
+ assert_equals order.execution_expression, ClickClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
689
+ assert_not_nil order.date
690
+ assert_equals order.expiration_type, ClickClient::FX::EXPIRATION_TYPE_SPECIFIED
691
+ assert_equals order.expiration_date, expect_limit
692
+ assert order.order_state == ClickClient::FX::ORDER_STATE_CANCELING || order.order_state == ClickClient::FX::ORDER_STATE_CANCELED # キャンセルorキャンセル中
693
+ assert_not_nil order.failure_reason, ClickClient::FX::FAILURE_REASON_USER # 不成立になる
694
+ assert_nil order.settlement_rate
695
+ assert_nil order.settlement_date
696
+ end
697
+ }
698
+ end
699
+
700
+ private
701
+ # 通貨ペアコードに値が設定されているか評価する
702
+ def assert_valid_currency_pair( info, code )
703
+ assert_equals code, info.currency_pair_code
704
+ assert_not_nil info.name
705
+ assert_not_nil info.max_trade_quantity.to_i
706
+ assert_not_nil info.min_trade_quantity.to_i
707
+ assert_not_nil info.trade_unit.to_i
708
+ end
709
+
710
+ # レートに値が設定されているか評価する
711
+ def assert_valid_rate( info, code )
712
+ assert_equals code, info.currency_pair_code
713
+ assert_not_nil info.bid.to_f
714
+ assert_not_nil info.ask.to_f
715
+ assert_not_nil info.day_before_to.to_f
716
+ assert_not_nil info.bid_high.to_f
717
+ assert_not_nil info.bid_low.to_f
718
+ assert_not_nil info.sell_swap.to_i
719
+ assert_not_nil info.buy_swap.to_i
720
+ assert_not_nil info.date
721
+ assert_not_nil info.days_of_grant.to_i
722
+ end
723
+
724
+ # 約定に値が設定されているか評価する
725
+ def assert_valid_execution_result( execution_result )
726
+ assert_not_nil execution_result.currency_pair_code
727
+ end
728
+ end