unageanu-clickclient 0.0.3

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