sbiclient 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/sample/common.rb ADDED
@@ -0,0 +1,28 @@
1
+
2
+ # ※「../etc」ディレクトリにuser,passファイルを作成し、
3
+ # ユーザー名,パスワードを設定しておくこと。
4
+ USER=IO.read("../etc/user")
5
+ PASS=IO.read("../etc/pass")
6
+ ORDER_PASS=IO.read("../etc/order_pass") # 取引パスワード
7
+
8
+ #注文一覧を出力する。
9
+ #session:: Session
10
+ def print_order( session )
11
+ # 注文一覧を取得
12
+ orders = session.list_orders
13
+ orders.each_pair {|k,v|
14
+ puts <<-STR
15
+ ---
16
+ order_no : #{v.order_no}
17
+ trade_type : #{v.trade_type}
18
+ order_type : #{v.order_type}
19
+ execution_expression : #{v.execution_expression}
20
+ sell_or_buy : #{v.sell_or_buy}
21
+ pair : #{v.pair}
22
+ count : #{v.count}
23
+ rate : #{v.rate}
24
+ order_state : #{v.order_state}
25
+
26
+ STR
27
+ }
28
+ end
@@ -0,0 +1,80 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レートを取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+
17
+ ## IFD-OCO注文
18
+ # 指値
19
+ begin
20
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
21
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
22
+ :settle=> {
23
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
24
+ :stop_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate - 1
25
+ },
26
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
27
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
28
+ })
29
+ print_order( session )
30
+ ensure
31
+ session.cancel_order(order_id.order_no) if order_id
32
+ end
33
+
34
+ begin
35
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
36
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
37
+ :settle=> {
38
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
39
+ :stop_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate + 1
40
+ },
41
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
42
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
43
+ })
44
+ print_order( session )
45
+ ensure
46
+ session.cancel_order(order_id.order_no) if order_id
47
+ end
48
+
49
+
50
+ # 逆指値
51
+ begin
52
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
53
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
54
+ :settle=> {
55
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 1,
56
+ :stop_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate
57
+ },
58
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
59
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
60
+ })
61
+ print_order( session )
62
+ ensure
63
+ session.cancel_order(order_id.order_no) if order_id
64
+ end
65
+
66
+ begin
67
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
68
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
69
+ :settle=> {
70
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 1,
71
+ :stop_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate
72
+ },
73
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
74
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
75
+ })
76
+ print_order( session )
77
+ ensure
78
+ session.cancel_order(order_id.order_no) if order_id
79
+ end
80
+ }
@@ -0,0 +1,80 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レートを取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+
17
+ ## IFD注文
18
+ # 指値
19
+ begin
20
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
21
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
22
+ :settle=> {
23
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
24
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
25
+ },
26
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
27
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
28
+ })
29
+ print_order( session )
30
+ ensure
31
+ session.cancel_order(order_id.order_no) if order_id
32
+ end
33
+
34
+ begin
35
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
36
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
37
+ :settle=> {
38
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
39
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
40
+ },
41
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
42
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
43
+ })
44
+ print_order( session )
45
+ ensure
46
+ session.cancel_order(order_id.order_no) if order_id
47
+ end
48
+
49
+
50
+ # 逆指値
51
+ begin
52
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
53
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
54
+ :settle=> {
55
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
56
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
57
+ },
58
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
59
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
60
+ })
61
+ print_order( session )
62
+ ensure
63
+ session.cancel_order(order_id.order_no) if order_id
64
+ end
65
+
66
+ begin
67
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
68
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
69
+ :settle=> {
70
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
71
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
72
+ },
73
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
74
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
75
+ })
76
+ print_order( session )
77
+ ensure
78
+ session.cancel_order(order_id.order_no) if order_id
79
+ end
80
+ }
@@ -0,0 +1,17 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # 建玉一覧を取得
12
+ rates = session.list_positions
13
+ rates.each_pair {|k,v|
14
+ puts "#{v.pair} : #{v.sell_or_buy} : #{v.count} : #{v.rate} : #{v.profit_or_loss} : #{v.date}"
15
+ }
16
+
17
+ }
@@ -0,0 +1,16 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レート一覧を取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+ }
@@ -0,0 +1,126 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レートを取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+
17
+ ## OCO注文
18
+ # BUY-BUY,SELL-SELLの組み合わせ。
19
+ # BUY指値-BUY逆指値
20
+ begin
21
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
22
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
23
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
24
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
25
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
26
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
27
+ })
28
+ print_order( session )
29
+ ensure
30
+ session.cancel_order(order_id.order_no) if order_id
31
+ end
32
+
33
+ # SELL指値-SELL逆指値
34
+ begin
35
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
36
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
37
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
38
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
39
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
40
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
41
+ })
42
+ print_order( session )
43
+ ensure
44
+ session.cancel_order(order_id.order_no) if order_id
45
+ end
46
+
47
+ # BUY逆指値-BUY指値
48
+ begin
49
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
50
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
51
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
52
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
53
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
54
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
55
+ })
56
+ print_order( session )
57
+ ensure
58
+ session.cancel_order(order_id.order_no) if order_id
59
+ end
60
+
61
+ # SELL逆指値-SELL指値
62
+ begin
63
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
64
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
65
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
66
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
67
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
68
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
69
+ })
70
+ print_order( session )
71
+ ensure
72
+ session.cancel_order(order_id.order_no) if order_id
73
+ end
74
+
75
+
76
+ # BUY-SELLの組み合わせ。
77
+ # BUY指値-SELL指値
78
+ begin
79
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
80
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
81
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
82
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
83
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
84
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
85
+ })
86
+ print_order( session )
87
+ ensure
88
+ session.cancel_order(order_id.order_no) if order_id
89
+ end
90
+
91
+ # BUY指値-SELL指値
92
+ begin
93
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
94
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
95
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
96
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
97
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
98
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
99
+ })
100
+ print_order( session )
101
+ ensure
102
+ session.cancel_order(order_id.order_no) if order_id
103
+ end
104
+
105
+ # BUY逆指値-SELL指値
106
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
107
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
108
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
109
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
110
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
111
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
112
+ })
113
+ print_order( session )
114
+ session.cancel_order(order_id.order_no) if order_id
115
+
116
+ # SELL逆指値-BUY指値
117
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
118
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
119
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
120
+ :second_order_rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
121
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
122
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
123
+ })
124
+ print_order( session )
125
+ session.cancel_order(order_id.order_no) if order_id
126
+ }
@@ -0,0 +1,64 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レートを取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+
17
+ ## 指値注文
18
+ begin
19
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
20
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5, # 指値レート
21
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
22
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY # 有効期限: 当日限り
23
+ })
24
+ print_order( session )
25
+ ensure
26
+ session.cancel_order(order_id.order_no) if order_id
27
+ end
28
+
29
+ begin
30
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
31
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5, # 指値レート
32
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
33
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END # 有効期限: 週末まで
34
+ })
35
+ print_order( session )
36
+ ensure
37
+ session.cancel_order(order_id.order_no) if order_id
38
+ end
39
+
40
+
41
+ # 逆指値注文
42
+ begin
43
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
44
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5, # 逆指値レート
45
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER, # 執行条件: 逆指値
46
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY # 有効期限: 無限
47
+ })
48
+ print_order( session )
49
+ ensure
50
+ session.cancel_order(order_id.order_no) if order_id
51
+ end
52
+
53
+ begin
54
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
55
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5, # 逆指値レート
56
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER, # 執行条件: 逆指値
57
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
58
+ :expiration_date=>Date.today+2 # 2日後
59
+ })
60
+ print_order( session )
61
+ ensure
62
+ session.cancel_order(order_id.order_no) if order_id
63
+ end
64
+ }
@@ -0,0 +1,18 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # 建玉一覧を取得してすべてを約定
12
+ rates = session.list_positions
13
+ rates.each_pair {|k,v|
14
+ puts "#{v.pair} : #{v.sell_or_buy} : #{v.count} : #{v.rate} : #{v.profit_or_loss} : #{v.date}"
15
+ session.settle( v.position_id, v.count ) if v.position_id =~ /MURJPY/
16
+ }
17
+
18
+ }
@@ -0,0 +1,42 @@
1
+
2
+ $: << "../lib"
3
+
4
+ require 'sbiclient'
5
+ require 'common'
6
+
7
+ # ログイン
8
+ c = SBIClient::Client.new
9
+ c.fx_session( USER, PASS, ORDER_PASS ) {|session|
10
+
11
+ # レートを取得
12
+ rates = session.list_rates
13
+ rates.each_pair {|k,v|
14
+ puts "#{k} : #{v.bid_rate} : #{v.ask_rate} : #{v.sell_swap} : #{v.buy_swap}"
15
+ }
16
+
17
+ # トレール注文
18
+ # trail_rangeを指定するととレール注文になる。
19
+ # 執行条件は逆指値限定なので、指定不要。
20
+ begin
21
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
22
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
23
+ :trail_range=>0.5,
24
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
25
+ })
26
+ print_order( session )
27
+ ensure
28
+ session.cancel_order(order_id.order_no) if order_id
29
+ end
30
+
31
+ begin
32
+ order_id = session.order( SBIClient::FX::EURJPY, SBIClient::FX::SELL, 1, {
33
+ :rate=>rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
34
+ :trail_range=>1.5,
35
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED,
36
+ :expiration_date=>Date.today+2
37
+ })
38
+ print_order( session )
39
+ ensure
40
+ session.cancel_order(order_id.order_no) if order_id
41
+ end
42
+ }
@@ -0,0 +1,62 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "cancel_order" do
7
+ it_should_behave_like "login"
8
+ before { @order_ids = [] }
9
+ after {
10
+ @order_ids.each {|id| @s.cancel_order(id.order_no) }
11
+ }
12
+
13
+ it "複数のページがあってもキャンセルできる" do
14
+ 3.times{|i|
15
+ @order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
16
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
17
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
18
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
19
+ })
20
+ }
21
+ 3.times{|i|
22
+ @order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
23
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
24
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
25
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY,
26
+ :settle => {
27
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
28
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
29
+ }
30
+ })
31
+ }
32
+ 2.times{|i|
33
+ @order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
34
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
35
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
36
+ :second_order_rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
37
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
38
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
39
+ })
40
+ }
41
+ 3.times{|i|
42
+ @order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
43
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
44
+ :trail_range=>0.5,
45
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
46
+ })
47
+ }
48
+ # 末尾から消していき、すべて削除できればOK。
49
+ @order_ids.reverse.each {|id|
50
+ @s.cancel_order(id.order_no)
51
+ @order_ids.pop
52
+ }
53
+ @s.list_orders.size.should == 0
54
+ end
55
+
56
+ it "削除対象が存在しない" do
57
+ proc {
58
+ @s.cancel_order("not found")
59
+ }.should raise_error( RuntimeError, "illegal order_no. order_no=not found" )
60
+ end
61
+
62
+ end
data/spec/common.rb ADDED
@@ -0,0 +1,20 @@
1
+
2
+ # ※「../etc」ディレクトリにuser,passファイルを作成し、
3
+ # ユーザー名,パスワードを設定しておくこと。
4
+ USER=IO.read("../etc/user")
5
+ PASS=IO.read("../etc/pass")
6
+ ORDER_PASS=IO.read("../etc/order_pass") # 取引パスワード
7
+
8
+ # ログインする
9
+ shared_examples_for "login" do
10
+ before(:all) {
11
+ c = SBIClient::Client.new
12
+ @s = c.fx_session( USER, PASS, ORDER_PASS )
13
+ @rates = @s.list_rates
14
+ }
15
+ after(:all) {
16
+ @s.logout if @s
17
+ }
18
+ before { @order_id = nil }
19
+ after { @s.cancel_order(@order_id.order_no) if @order_id }
20
+ end
@@ -0,0 +1,59 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "IFDOCO" do
7
+ it_should_behave_like "login"
8
+
9
+ it "指値" do
10
+ @order_id = @s.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
11
+ :rate=>@rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
12
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
13
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY,
14
+ :settle => {
15
+ :rate=>@rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
16
+ :stop_order_rate=>@rates[SBIClient::FX::EURJPY].ask_rate - 1
17
+ }
18
+ })
19
+ orders = @s.list_orders
20
+ @order = orders[@order_id.order_no]
21
+ @order_id.should_not be_nil
22
+ @order_id.order_no.should_not be_nil
23
+ @order.should_not be_nil
24
+ @order.order_no.should == @order_id.order_no
25
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
26
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
27
+ @order.sell_or_buy.should == SBIClient::FX::BUY
28
+ @order.pair.should == SBIClient::FX::EURJPY
29
+ @order.count.should == 1
30
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate - 0.5
31
+ @order.trail_range.should be_nil
32
+ @order.order_type= SBIClient::FX::ORDER_TYPE_IFD_OCO
33
+ end
34
+
35
+ it "逆指値" do
36
+ @order_id = @s.order( SBIClient::FX::EURUSD, SBIClient::FX::BUY, 1, {
37
+ :rate=>@rates[SBIClient::FX::EURUSD].ask_rate + 0.05,
38
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
39
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY,
40
+ :settle => {
41
+ :rate=>@rates[SBIClient::FX::EURUSD].ask_rate + 0.1,
42
+ :stop_order_rate=>@rates[SBIClient::FX::EURUSD].ask_rate-0.05
43
+ }
44
+ })
45
+ @order_id.should_not be_nil
46
+ @order_id.order_no.should_not be_nil
47
+ @order = @s.list_orders[@order_id.order_no]
48
+ @order.should_not be_nil
49
+ @order.order_no.should == @order_id.order_no
50
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
51
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
52
+ @order.sell_or_buy.should == SBIClient::FX::BUY
53
+ @order.pair.should == SBIClient::FX::EURUSD
54
+ @order.count.should == 1
55
+ @order.rate.to_s.should == (@rates[SBIClient::FX::EURUSD].ask_rate + 0.05).to_s
56
+ @order.trail_range.should be_nil
57
+ @order.order_type= SBIClient::FX::ORDER_TYPE_IFD_OCO
58
+ end
59
+ end