sbiclient 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "IFD" 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
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
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
33
+ end
34
+
35
+ it "指値-逆指値" do
36
+ @order_id = @s.order( SBIClient::FX::USDJPY, SBIClient::FX::SELL, 1, {
37
+ :rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 0.5,
38
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
39
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END,
40
+ :settle => {
41
+ :rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 1,
42
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
43
+ }
44
+ })
45
+ @order = @s.list_orders[@order_id.order_no]
46
+ @order_id.should_not be_nil
47
+ @order_id.order_no.should_not be_nil
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_LIMIT_ORDER
52
+ @order.sell_or_buy.should == SBIClient::FX::SELL
53
+ @order.pair.should == SBIClient::FX::USDJPY
54
+ @order.count.should == 1
55
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate + 0.5
56
+ @order.trail_range.should be_nil
57
+ @order.order_type= SBIClient::FX::ORDER_TYPE_IFD
58
+ end
59
+
60
+ it "逆指値-逆指値" do
61
+ @order_id = @s.order( SBIClient::FX::EURUSD, SBIClient::FX::BUY, 1, {
62
+ :rate=>@rates[SBIClient::FX::EURUSD].ask_rate + 0.05,
63
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
64
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY,
65
+ :settle => {
66
+ :rate=>@rates[SBIClient::FX::EURUSD].ask_rate,
67
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
68
+ }
69
+ })
70
+ @order_id.should_not be_nil
71
+ @order_id.order_no.should_not be_nil
72
+ @order = @s.list_orders[@order_id.order_no]
73
+ @order.should_not be_nil
74
+ @order.order_no.should == @order_id.order_no
75
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
76
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
77
+ @order.sell_or_buy.should == SBIClient::FX::BUY
78
+ @order.pair.should == SBIClient::FX::EURUSD
79
+ @order.count.should == 1
80
+ @order.rate.to_s.should == (@rates[SBIClient::FX::EURUSD].ask_rate + 0.05).to_s
81
+ @order.trail_range.should be_nil
82
+ @order.order_type= SBIClient::FX::ORDER_TYPE_IFD
83
+ end
84
+
85
+ it "逆指値-指値" do
86
+ @order_id = @s.order( SBIClient::FX::MURJPY, SBIClient::FX::SELL, 2, {
87
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
88
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
89
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED,
90
+ :expiration_date=>Date.today+2,
91
+ :settle => {
92
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 1,
93
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
94
+ }
95
+ })
96
+ @order = @s.list_orders[@order_id.order_no]
97
+ @order_id.should_not be_nil
98
+ @order_id.order_no.should_not be_nil
99
+ @order.should_not be_nil
100
+ @order.order_no.should == @order_id.order_no
101
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
102
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
103
+ @order.sell_or_buy.should == SBIClient::FX::SELL
104
+ @order.pair.should == SBIClient::FX::MURJPY
105
+ @order.count.should == 2
106
+ @order.rate.should == @rates[SBIClient::FX::MURJPY].ask_rate - 0.5
107
+ @order.trail_range.should be_nil
108
+ @order.order_type= SBIClient::FX::ORDER_TYPE_IFD
109
+ end
110
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $: << "../lib"
4
+
5
+ require "rubygems"
6
+ require "logger"
7
+ require 'sbiclient'
8
+ require "common"
9
+ require 'jiji/plugin/plugin_loader'
10
+ require 'jiji/plugin/securities_plugin'
11
+
12
+ # jijiプラグインのテスト
13
+ # ※実際に取引を行うので注意!
14
+ describe "market order" do
15
+ before(:all) {
16
+ # ロード
17
+ JIJI::Plugin::Loader.new.load
18
+ plugins = JIJI::Plugin.get( JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME )
19
+ @plugin = plugins.find {|i| i.plugin_id == :sbi_securities }
20
+ @logger = Logger.new STDOUT
21
+ }
22
+ it "jiji pluginのテスト" do
23
+ @plugin.should_not be_nil
24
+ @plugin.display_name.should == "SBI Securities"
25
+
26
+ begin
27
+ @plugin.init_plugin( {:user=>USER, :password=>PASS, :trade_password=>ORDER_PASS}, @logger )
28
+
29
+ # 利用可能な通貨ペア一覧とレート
30
+ pairs = @plugin.list_pairs
31
+ rates = @plugin.list_rates
32
+ pairs.each {|p|
33
+ # 利用可能とされたペアのレートが取得できていることを確認
34
+ p.name.should_not be_nil
35
+ p.trade_unit.should_not be_nil
36
+ rates[p.name].should_not be_nil
37
+ rates[p.name].bid.should_not be_nil
38
+ rates[p.name].ask.should_not be_nil
39
+ rates[p.name].sell_swap.should_not be_nil
40
+ rates[p.name].buy_swap.should_not be_nil
41
+ }
42
+ sleep 1
43
+
44
+ 3.times {
45
+ rates = @plugin.list_rates
46
+ pairs.each {|p|
47
+ # 利用可能とされたペアのレートが取得できていることを確認
48
+ p.name.should_not be_nil
49
+ p.trade_unit.should_not be_nil
50
+ rates[p.name].should_not be_nil
51
+ rates[p.name].bid.should_not be_nil
52
+ rates[p.name].ask.should_not be_nil
53
+ rates[p.name].sell_swap.should_not be_nil
54
+ rates[p.name].buy_swap.should_not be_nil
55
+ }
56
+ sleep 3
57
+ }
58
+
59
+ # 売り/買い
60
+ sell = @plugin.order( :MSDJPY, :sell, 1 )
61
+ buy = @plugin.order( :MSDJPY, :buy, 1 )
62
+ sell.position_id.should_not be_nil
63
+ buy.position_id.should_not be_nil
64
+
65
+ # 約定
66
+ @plugin.commit sell.position_id, 1
67
+ @plugin.commit buy.position_id, 1
68
+ ensure
69
+ @plugin.destroy_plugin
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,93 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "limit" 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
+ })
15
+ @order = @s.list_orders[@order_id.order_no]
16
+ @order_id.should_not be_nil
17
+ @order_id.order_no.should_not be_nil
18
+ @order.should_not be_nil
19
+ @order.order_no.should == @order_id.order_no
20
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
21
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
22
+ @order.sell_or_buy.should == SBIClient::FX::BUY
23
+ @order.pair.should == SBIClient::FX::EURJPY
24
+ @order.count.should == 1
25
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate - 0.5
26
+ @order.trail_range.should be_nil
27
+ @order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
28
+ end
29
+
30
+ it "指値-売り" do
31
+ @order_id = @s.order( SBIClient::FX::USDJPY, SBIClient::FX::SELL, 1, {
32
+ :rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 0.5,
33
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
34
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
35
+ })
36
+ @order = @s.list_orders[@order_id.order_no]
37
+ @order_id.should_not be_nil
38
+ @order_id.order_no.should_not be_nil
39
+ @order.should_not be_nil
40
+ @order.order_no.should == @order_id.order_no
41
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
42
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
43
+ @order.sell_or_buy.should == SBIClient::FX::SELL
44
+ @order.pair.should == SBIClient::FX::USDJPY
45
+ @order.count.should == 1
46
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate + 0.5
47
+ @order.trail_range.should be_nil
48
+ @order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
49
+ end
50
+
51
+ it "逆指値-買い" do
52
+ @order_id = @s.order( SBIClient::FX::EURUSD, SBIClient::FX::BUY, 1, {
53
+ :rate=>@rates[SBIClient::FX::EURUSD].ask_rate + 0.05,
54
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
55
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
56
+ })
57
+ @order_id.should_not be_nil
58
+ @order_id.order_no.should_not be_nil
59
+ @order = @s.list_orders[@order_id.order_no]
60
+ @order.should_not be_nil
61
+ @order.order_no.should == @order_id.order_no
62
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
63
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
64
+ @order.sell_or_buy.should == SBIClient::FX::BUY
65
+ @order.pair.should == SBIClient::FX::EURUSD
66
+ @order.count.should == 1
67
+ @order.rate.to_s.should == (@rates[SBIClient::FX::EURUSD].ask_rate + 0.05).to_s
68
+ @order.trail_range.should be_nil
69
+ @order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
70
+ end
71
+
72
+ it "逆指値-売り" do
73
+ @order_id = @s.order( SBIClient::FX::MURJPY, SBIClient::FX::SELL, 2, {
74
+ :rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
75
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
76
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
77
+ :expiration_date=>Date.today+2 # 2日後
78
+ })
79
+ @order = @s.list_orders[@order_id.order_no]
80
+ @order_id.should_not be_nil
81
+ @order_id.order_no.should_not be_nil
82
+ @order.should_not be_nil
83
+ @order.order_no.should == @order_id.order_no
84
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
85
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
86
+ @order.sell_or_buy.should == SBIClient::FX::SELL
87
+ @order.pair.should == SBIClient::FX::MURJPY
88
+ @order.count.should == 2
89
+ @order.rate.should == @rates[SBIClient::FX::MURJPY].ask_rate - 0.5
90
+ @order.trail_range.should be_nil
91
+ @order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
92
+ end
93
+ end
@@ -0,0 +1,51 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "list_orders" 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
+ result = @s.list_orders
49
+ result.size.should == 13 #OCOは2つになるので、3*3+2*2=13になる
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ # 成り行きで発注および決済を行うテスト。
7
+ # <b>注意:</b> 決済まで行う為、実行すると資金が減少します。
8
+ describe "market order" do
9
+ it_should_behave_like "login"
10
+
11
+ it "成り行きで発注し決済するテスト" do
12
+ prev = @s.list_positions
13
+
14
+ # 成り行きで注文
15
+ @s.order( SBIClient::FX::MSDJPY, SBIClient::FX::BUY, 1, {
16
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
17
+ })
18
+ @s.order( SBIClient::FX::MSDJPY, SBIClient::FX::SELL, 1, {
19
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
20
+ })
21
+ sleep 1
22
+
23
+ #建玉一覧取得
24
+ after = @s.list_positions
25
+ positions = after.find_all {|i| !prev.include?(i[0]) }.map{|i| i[1] }
26
+ positions.length.should == 2 # 新規の建玉が2つ存在することを確認
27
+ positions.each {|p|
28
+ p.position_id.should_not be_nil
29
+ p.pair.should_not be_nil
30
+ p.sell_or_buy.should_not be_nil
31
+ p.count.should == 1
32
+ p.rate.should_not be_nil
33
+ p.profit_or_loss.should_not be_nil
34
+ p.date.should_not be_nil
35
+ }
36
+
37
+ # 決済注文
38
+ positions = after.map{|i| i[1] }
39
+ positions.each {|p|
40
+ @s.settle( p[0] ) if p[0] =~ /MURJPY/
41
+ }
42
+ sleep 1
43
+ after_settle = @s.list_positions
44
+ assert_false after_settle.key?( positions[0] )
45
+ assert_false after_settle.key?( positions[1] )
46
+ end
47
+ end
@@ -0,0 +1,307 @@
1
+ $: << "../lib"
2
+
3
+ require 'sbiclient'
4
+ require 'common'
5
+
6
+ describe "OCO" do
7
+ it_should_behave_like "login"
8
+
9
+ it "OCO-買x買-指値" do
10
+ # 買いx買い。2つめの取引は逆指値になる
11
+ @order_id = @s.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
12
+ :rate=>@rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
13
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
14
+ :second_order_rate=>@rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
15
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
16
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
17
+ })
18
+ orders = @s.list_orders
19
+ @order = orders[@order_id.order_no]
20
+ @order_id.should_not be_nil
21
+ @order_id.order_no.should_not be_nil
22
+ @order.should_not be_nil
23
+ @order.order_no.should == @order_id.order_no
24
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
25
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
26
+ @order.sell_or_buy.should == SBIClient::FX::BUY
27
+ @order.pair.should == SBIClient::FX::EURJPY
28
+ @order.count.should == 1
29
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate - 0.5
30
+ @order.trail_range.should be_nil
31
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
32
+
33
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
34
+ @order.should_not be_nil
35
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
36
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
37
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
38
+ @order.sell_or_buy.should == SBIClient::FX::BUY
39
+ @order.pair.should == SBIClient::FX::EURJPY
40
+ @order.count.should == 1
41
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate + 0.5
42
+ @order.trail_range.should be_nil
43
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
44
+ end
45
+
46
+ it "OCO-売x売-指値" do
47
+ # 売りx売り。2つめの取引は逆指値になる
48
+ @order_id = @s.order( SBIClient::FX::GBPJPY, SBIClient::FX::SELL, 1, {
49
+ :rate=>@rates[SBIClient::FX::GBPJPY].ask_rate + 0.5,
50
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
51
+ :second_order_rate=>@rates[SBIClient::FX::GBPJPY].ask_rate - 0.5,
52
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
53
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
54
+ })
55
+ orders = @s.list_orders
56
+ @order = orders[@order_id.order_no]
57
+ @order_id.should_not be_nil
58
+ @order_id.order_no.should_not be_nil
59
+ @order.should_not be_nil
60
+ @order.order_no.should == @order_id.order_no
61
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
62
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
63
+ @order.sell_or_buy.should == SBIClient::FX::SELL
64
+ @order.pair.should == SBIClient::FX::GBPJPY
65
+ @order.count.should == 1
66
+ @order.rate.should == @rates[SBIClient::FX::GBPJPY].ask_rate + 0.5
67
+ @order.trail_range.should be_nil
68
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
69
+
70
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
71
+ @order.should_not be_nil
72
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
73
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
74
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
75
+ @order.sell_or_buy.should == SBIClient::FX::SELL
76
+ @order.pair.should == SBIClient::FX::GBPJPY
77
+ @order.count.should == 1
78
+ @order.rate.should == @rates[SBIClient::FX::GBPJPY].ask_rate - 0.5
79
+ @order.trail_range.should be_nil
80
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
81
+ end
82
+
83
+ it "OCO-買x売-指値" do
84
+ # 買いx売り。両方とも指値になる
85
+ @order_id = @s.order( SBIClient::FX::USDJPY, SBIClient::FX::BUY, 1, {
86
+ :rate=>@rates[SBIClient::FX::USDJPY].ask_rate - 1,
87
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
88
+ :second_order_rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 1,
89
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
90
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
91
+ })
92
+ orders = @s.list_orders
93
+ @order = orders[@order_id.order_no]
94
+ @order_id.should_not be_nil
95
+ @order_id.order_no.should_not be_nil
96
+ @order.should_not be_nil
97
+ @order.order_no.should == @order_id.order_no
98
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
99
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
100
+ @order.sell_or_buy.should == SBIClient::FX::BUY
101
+ @order.pair.should == SBIClient::FX::USDJPY
102
+ @order.count.should == 1
103
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate - 1
104
+ @order.trail_range.should be_nil
105
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
106
+
107
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
108
+ @order.should_not be_nil
109
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
110
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
111
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
112
+ @order.sell_or_buy.should == SBIClient::FX::SELL
113
+ @order.pair.should == SBIClient::FX::USDJPY
114
+ @order.count.should == 1
115
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate + 1
116
+ @order.trail_range.should be_nil
117
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
118
+ end
119
+
120
+ it "OCO-売x買-指値" do
121
+ # 買いx売り。両方とも指値になる
122
+ @order_id = @s.order( SBIClient::FX::MZDJPY, SBIClient::FX::SELL, 2, {
123
+ :rate=>@rates[SBIClient::FX::MZDJPY].ask_rate + 1,
124
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
125
+ :second_order_rate=>@rates[SBIClient::FX::MZDJPY].ask_rate - 1,
126
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
127
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
128
+ :expiration_date=>Date.today+1
129
+ })
130
+ orders = @s.list_orders
131
+ @order = orders[@order_id.order_no]
132
+ @order_id.should_not be_nil
133
+ @order_id.order_no.should_not be_nil
134
+ @order.should_not be_nil
135
+ @order.order_no.should == @order_id.order_no
136
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
137
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
138
+ @order.sell_or_buy.should == SBIClient::FX::SELL
139
+ @order.pair.should == SBIClient::FX::MZDJPY
140
+ @order.count.should == 2
141
+ @order.rate.should == @rates[SBIClient::FX::MZDJPY].ask_rate + 1
142
+ @order.trail_range.should be_nil
143
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
144
+
145
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
146
+ @order.should_not be_nil
147
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
148
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
149
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
150
+ @order.sell_or_buy.should == SBIClient::FX::BUY
151
+ @order.pair.should == SBIClient::FX::MZDJPY
152
+ @order.count.should == 2
153
+ @order.rate.should == @rates[SBIClient::FX::MZDJPY].ask_rate - 1
154
+ @order.trail_range.should be_nil
155
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
156
+ end
157
+
158
+ it "OCO-買x買-逆指値" do
159
+ # 買いx買い。2つめの取引は指値になる
160
+ @order_id = @s.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
161
+ :rate=>@rates[SBIClient::FX::EURJPY].ask_rate + 0.5,
162
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
163
+ :second_order_rate=>@rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
164
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
165
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
166
+ })
167
+ orders = @s.list_orders
168
+ @order = orders[@order_id.order_no]
169
+ @order_id.should_not be_nil
170
+ @order_id.order_no.should_not be_nil
171
+ @order.should_not be_nil
172
+ @order.order_no.should == @order_id.order_no
173
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
174
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
175
+ @order.sell_or_buy.should == SBIClient::FX::BUY
176
+ @order.pair.should == SBIClient::FX::EURJPY
177
+ @order.count.should == 1
178
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate + 0.5
179
+ @order.trail_range.should be_nil
180
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
181
+
182
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
183
+ @order.should_not be_nil
184
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
185
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
186
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
187
+ @order.sell_or_buy.should == SBIClient::FX::BUY
188
+ @order.pair.should == SBIClient::FX::EURJPY
189
+ @order.count.should == 1
190
+ @order.rate.should == @rates[SBIClient::FX::EURJPY].ask_rate - 0.5
191
+ @order.trail_range.should be_nil
192
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
193
+ end
194
+
195
+ it "OCO-売x売-逆指値" do
196
+ # 売りx売り。2つめの取引は指値になる
197
+ @order_id = @s.order( SBIClient::FX::GBPJPY, SBIClient::FX::SELL, 1, {
198
+ :rate=>@rates[SBIClient::FX::GBPJPY].ask_rate - 0.5,
199
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
200
+ :second_order_rate=>@rates[SBIClient::FX::GBPJPY].ask_rate + 0.5,
201
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
202
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
203
+ })
204
+ orders = @s.list_orders
205
+ @order = orders[@order_id.order_no]
206
+ @order_id.should_not be_nil
207
+ @order_id.order_no.should_not be_nil
208
+ @order.should_not be_nil
209
+ @order.order_no.should == @order_id.order_no
210
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
211
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
212
+ @order.sell_or_buy.should == SBIClient::FX::SELL
213
+ @order.pair.should == SBIClient::FX::GBPJPY
214
+ @order.count.should == 1
215
+ @order.rate.should == @rates[SBIClient::FX::GBPJPY].ask_rate - 0.5
216
+ @order.trail_range.should be_nil
217
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
218
+
219
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
220
+ @order.should_not be_nil
221
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
222
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
223
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
224
+ @order.sell_or_buy.should == SBIClient::FX::SELL
225
+ @order.pair.should == SBIClient::FX::GBPJPY
226
+ @order.count.should == 1
227
+ @order.rate.should == @rates[SBIClient::FX::GBPJPY].ask_rate + 0.5
228
+ @order.trail_range.should be_nil
229
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
230
+ end
231
+
232
+ it "OCO-買x売-逆指値" do
233
+ # 買いx売り。両方とも逆指値になる
234
+ @order_id = @s.order( SBIClient::FX::USDJPY, SBIClient::FX::BUY, 1, {
235
+ :rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 1,
236
+ :second_order_sell_or_buy=>SBIClient::FX::SELL,
237
+ :second_order_rate=>@rates[SBIClient::FX::USDJPY].ask_rate - 1,
238
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
239
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
240
+ })
241
+ orders = @s.list_orders
242
+ @order = orders[@order_id.order_no]
243
+ @order_id.should_not be_nil
244
+ @order_id.order_no.should_not be_nil
245
+ @order.should_not be_nil
246
+ @order.order_no.should == @order_id.order_no
247
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
248
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
249
+ @order.sell_or_buy.should == SBIClient::FX::BUY
250
+ @order.pair.should == SBIClient::FX::USDJPY
251
+ @order.count.should == 1
252
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate + 1
253
+ @order.trail_range.should be_nil
254
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
255
+
256
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
257
+ @order.should_not be_nil
258
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
259
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
260
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
261
+ @order.sell_or_buy.should == SBIClient::FX::SELL
262
+ @order.pair.should == SBIClient::FX::USDJPY
263
+ @order.count.should == 1
264
+ @order.rate.should == @rates[SBIClient::FX::USDJPY].ask_rate - 1
265
+ @order.trail_range.should be_nil
266
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
267
+ end
268
+
269
+ it "OCO-売りx買い" do
270
+ # 買いx売り。両方とも指値になる
271
+ @order_id = @s.order( SBIClient::FX::MZDJPY, SBIClient::FX::SELL, 2, {
272
+ :rate=>@rates[SBIClient::FX::MZDJPY].ask_rate - 1,
273
+ :second_order_sell_or_buy=>SBIClient::FX::BUY,
274
+ :second_order_rate=>@rates[SBIClient::FX::MZDJPY].ask_rate + 1,
275
+ :execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
276
+ :expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED,
277
+ :expiration_date=>Date.today+5
278
+ })
279
+ orders = @s.list_orders
280
+ @order = orders[@order_id.order_no]
281
+ @order_id.should_not be_nil
282
+ @order_id.order_no.should_not be_nil
283
+ @order.should_not be_nil
284
+ @order.order_no.should == @order_id.order_no
285
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
286
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
287
+ @order.sell_or_buy.should == SBIClient::FX::SELL
288
+ @order.pair.should == SBIClient::FX::MZDJPY
289
+ @order.count.should == 2
290
+ @order.rate.should == @rates[SBIClient::FX::MZDJPY].ask_rate - 1
291
+ @order.trail_range.should be_nil
292
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
293
+
294
+ @order = orders[(@order_id.order_no.to_i+1).to_s]
295
+ @order.should_not be_nil
296
+ @order.order_no.should == (@order_id.order_no.to_i+1).to_s
297
+ @order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
298
+ @order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
299
+ @order.sell_or_buy.should == SBIClient::FX::BUY
300
+ @order.pair.should == SBIClient::FX::MZDJPY
301
+ @order.count.should == 2
302
+ @order.rate.should == @rates[SBIClient::FX::MZDJPY].ask_rate + 1
303
+ @order.trail_range.should be_nil
304
+ @order.order_type= SBIClient::FX::ORDER_TYPE_OCO
305
+ end
306
+
307
+ end