sbiclient 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +13 -0
- data/README +0 -0
- data/lib/jiji_plugin.rb +2 -5
- data/lib/sbiclient.rb +5 -2
- data/sample/common.rb +14 -5
- data/sample/sample_ifd_oco_order.rb +2 -0
- data/sample/sample_ifd_order.rb +2 -0
- data/sample/sample_list_positions.rb +2 -0
- data/sample/sample_list_rates.rb +2 -0
- data/sample/sample_oco_order.rb +2 -0
- data/sample/sample_order.rb +2 -0
- data/sample/sample_settle.rb +2 -0
- data/sample/sample_trail_order.rb +2 -0
- data/spec/cancel_order_spec.rb +56 -53
- data/spec/common.rb +18 -5
- data/spec/ifd_oco_order_spec.rb +54 -50
- data/spec/ifd_order_spec.rb +105 -101
- data/spec/jiji_plugin_daily_spec.rb +63 -0
- data/spec/jiji_plugin_spec!.rb +2 -32
- data/spec/limit_order_spec.rb +88 -84
- data/spec/list_orders_spec.rb +47 -42
- data/spec/market_order_spec!.rb +39 -35
- data/spec/oco_order_spec.rb +294 -290
- data/spec/order_error_spec.rb +344 -339
- data/spec/trail_order_spec.rb +46 -42
- metadata +31 -10
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
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
|
+
# ※dailyでのテスト用。レート情報の参照のみをテストする。
|
14
|
+
describe "jiji plugin daily" 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 test" 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
|
+
ensure
|
60
|
+
@plugin.destroy_plugin
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/jiji_plugin_spec!.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
$: << "../lib"
|
4
4
|
|
@@ -11,7 +11,7 @@ require 'jiji/plugin/securities_plugin'
|
|
11
11
|
|
12
12
|
# jijiプラグインのテスト
|
13
13
|
# ※実際に取引を行うので注意!
|
14
|
-
describe "
|
14
|
+
describe "jiji plugin" do
|
15
15
|
before(:all) {
|
16
16
|
# ロード
|
17
17
|
JIJI::Plugin::Loader.new.load
|
@@ -26,36 +26,6 @@ describe "market order" do
|
|
26
26
|
begin
|
27
27
|
@plugin.init_plugin( {:user=>USER, :password=>PASS, :trade_password=>ORDER_PASS}, @logger )
|
28
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
29
|
# 売り/買い
|
60
30
|
sell = @plugin.order( :MSDJPY, :sell, 1 )
|
61
31
|
buy = @plugin.order( :MSDJPY, :buy, 1 )
|
data/spec/limit_order_spec.rb
CHANGED
@@ -1,93 +1,97 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
$: << "../lib"
|
2
4
|
|
3
5
|
require 'sbiclient'
|
4
6
|
require 'common'
|
5
7
|
|
6
8
|
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
|
9
|
+
it_should_behave_like "login" do
|
71
10
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
11
|
+
it "指値-買い" do
|
12
|
+
@order_id = @s.order( SBIClient::FX::EURJPY, SBIClient::FX::BUY, 1, {
|
13
|
+
:rate=>@rates[SBIClient::FX::EURJPY].ask_rate - 0.5,
|
14
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
15
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
16
|
+
})
|
17
|
+
@order = @s.list_orders[@order_id.order_no]
|
18
|
+
@order_id.should_not be_nil
|
19
|
+
@order_id.order_no.should_not be_nil
|
20
|
+
@order.should_not be_nil
|
21
|
+
@order.order_no.should == @order_id.order_no
|
22
|
+
@order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
|
23
|
+
@order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
|
24
|
+
@order.sell_or_buy.should == SBIClient::FX::BUY
|
25
|
+
@order.pair.should == SBIClient::FX::EURJPY
|
26
|
+
@order.count.should == 1
|
27
|
+
normalize_rate(@order.rate).should == normalize_rate(@rates[SBIClient::FX::EURJPY].ask_rate - 0.5)
|
28
|
+
@order.trail_range.should be_nil
|
29
|
+
@order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
|
30
|
+
end
|
31
|
+
|
32
|
+
it "指値-売り" do
|
33
|
+
@order_id = @s.order( SBIClient::FX::USDJPY, SBIClient::FX::SELL, 1, {
|
34
|
+
:rate=>@rates[SBIClient::FX::USDJPY].ask_rate + 0.5,
|
35
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
36
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
|
37
|
+
})
|
38
|
+
@order = @s.list_orders[@order_id.order_no]
|
39
|
+
@order_id.should_not be_nil
|
40
|
+
@order_id.order_no.should_not be_nil
|
41
|
+
@order.should_not be_nil
|
42
|
+
@order.order_no.should == @order_id.order_no
|
43
|
+
@order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
|
44
|
+
@order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
|
45
|
+
@order.sell_or_buy.should == SBIClient::FX::SELL
|
46
|
+
@order.pair.should == SBIClient::FX::USDJPY
|
47
|
+
@order.count.should == 1
|
48
|
+
normalize_rate(@order.rate).should == normalize_rate(@rates[SBIClient::FX::USDJPY].ask_rate + 0.5)
|
49
|
+
@order.trail_range.should be_nil
|
50
|
+
@order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
|
51
|
+
end
|
52
|
+
|
53
|
+
it "逆指値-買い" do
|
54
|
+
@order_id = @s.order( SBIClient::FX::EURUSD, SBIClient::FX::BUY, 1, {
|
55
|
+
:rate=>@rates[SBIClient::FX::EURUSD].ask_rate + 0.05,
|
56
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
|
57
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
58
|
+
})
|
59
|
+
@order_id.should_not be_nil
|
60
|
+
@order_id.order_no.should_not be_nil
|
61
|
+
@order = @s.list_orders[@order_id.order_no]
|
62
|
+
@order.should_not be_nil
|
63
|
+
@order.order_no.should == @order_id.order_no
|
64
|
+
@order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
|
65
|
+
@order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
|
66
|
+
@order.sell_or_buy.should == SBIClient::FX::BUY
|
67
|
+
@order.pair.should == SBIClient::FX::EURUSD
|
68
|
+
@order.count.should == 1
|
69
|
+
normalize_rate(@order.rate).should == normalize_rate(@rates[SBIClient::FX::EURUSD].ask_rate + 0.05)
|
70
|
+
@order.trail_range.should be_nil
|
71
|
+
@order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
|
72
|
+
end
|
73
|
+
|
74
|
+
it "逆指値-売り" do
|
75
|
+
@order_id = @s.order( SBIClient::FX::MURJPY, SBIClient::FX::SELL, 2, {
|
76
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
|
77
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER,
|
78
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
|
79
|
+
:expiration_date=>Date.today+2 # 2日後
|
80
|
+
})
|
81
|
+
@order = @s.list_orders[@order_id.order_no]
|
82
|
+
@order_id.should_not be_nil
|
83
|
+
@order_id.order_no.should_not be_nil
|
84
|
+
@order.should_not be_nil
|
85
|
+
@order.order_no.should == @order_id.order_no
|
86
|
+
@order.trade_type.should == SBIClient::FX::TRADE_TYPE_NEW
|
87
|
+
@order.execution_expression.should == SBIClient::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER
|
88
|
+
@order.sell_or_buy.should == SBIClient::FX::SELL
|
89
|
+
@order.pair.should == SBIClient::FX::MURJPY
|
90
|
+
@order.count.should == 2
|
91
|
+
normalize_rate(@order.rate).should == normalize_rate(@rates[SBIClient::FX::MURJPY].ask_rate - 0.5)
|
92
|
+
@order.trail_range.should be_nil
|
93
|
+
@order.order_type= SBIClient::FX::ORDER_TYPE_NORMAL
|
94
|
+
end
|
95
|
+
|
92
96
|
end
|
93
97
|
end
|
data/spec/list_orders_spec.rb
CHANGED
@@ -1,51 +1,56 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
$: << "../lib"
|
2
4
|
|
3
5
|
require 'sbiclient'
|
4
6
|
require 'common'
|
5
7
|
|
6
8
|
describe "list_orders" do
|
7
|
-
it_should_behave_like "login"
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
})
|
9
|
+
it_should_behave_like "login" do
|
10
|
+
|
11
|
+
before { @order_ids = [] }
|
12
|
+
after {
|
13
|
+
@order_ids.each {|id| @s.cancel_order(id.order_no) }
|
47
14
|
}
|
48
|
-
|
49
|
-
|
15
|
+
|
16
|
+
it "複数のページがあってもすべてのデータが取得できる" do
|
17
|
+
3.times{|i|
|
18
|
+
@order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
|
19
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
|
20
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
21
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
22
|
+
})
|
23
|
+
}
|
24
|
+
3.times{|i|
|
25
|
+
@order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
|
26
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
|
27
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
28
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY,
|
29
|
+
:settle => {
|
30
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
|
31
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER
|
32
|
+
}
|
33
|
+
})
|
34
|
+
}
|
35
|
+
2.times{|i|
|
36
|
+
@order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
|
37
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate - 0.5,
|
38
|
+
:second_order_sell_or_buy=>SBIClient::FX::BUY,
|
39
|
+
:second_order_rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
|
40
|
+
:execution_expression=>SBIClient::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
41
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
42
|
+
})
|
43
|
+
}
|
44
|
+
3.times{|i|
|
45
|
+
@order_ids << @s.order( SBIClient::FX::MURJPY, SBIClient::FX::BUY, 1, {
|
46
|
+
:rate=>@rates[SBIClient::FX::MURJPY].ask_rate + 0.5,
|
47
|
+
:trail_range=>0.5,
|
48
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
49
|
+
})
|
50
|
+
}
|
51
|
+
result = @s.list_orders
|
52
|
+
result.size.should == 13 #OCOは2つになるので、3*3+2*2=13になる
|
53
|
+
end
|
54
|
+
|
50
55
|
end
|
51
56
|
end
|
data/spec/market_order_spec!.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
$: << "../lib"
|
2
4
|
|
3
5
|
require 'sbiclient'
|
@@ -6,42 +8,44 @@ require 'common'
|
|
6
8
|
# 成り行きで発注および決済を行うテスト。
|
7
9
|
# <b>注意:</b> 決済まで行う為、実行すると資金が減少します。
|
8
10
|
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
|
11
|
+
it_should_behave_like "login" do
|
22
12
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
13
|
+
it "成り行きで発注し決済するテスト" do
|
14
|
+
prev = @s.list_positions
|
15
|
+
|
16
|
+
# 成り行きで注文
|
17
|
+
@s.order( SBIClient::FX::MSDJPY, SBIClient::FX::BUY, 1, {
|
18
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_TODAY
|
19
|
+
})
|
20
|
+
@s.order( SBIClient::FX::MSDJPY, SBIClient::FX::SELL, 1, {
|
21
|
+
:expiration_type=>SBIClient::FX::EXPIRATION_TYPE_WEEK_END
|
22
|
+
})
|
23
|
+
sleep 1
|
24
|
+
|
25
|
+
#建玉一覧取得
|
26
|
+
after = @s.list_positions
|
27
|
+
positions = after.find_all {|i| !prev.include?(i[0]) }.map{|i| i[1] }
|
28
|
+
positions.length.should == 2 # 新規の建玉が2つ存在することを確認
|
29
|
+
positions.each {|p|
|
30
|
+
p.position_id.should_not be_nil
|
31
|
+
p.pair.should_not be_nil
|
32
|
+
p.sell_or_buy.should_not be_nil
|
33
|
+
p.count.should == 1
|
34
|
+
p.rate.should_not be_nil
|
35
|
+
p.profit_or_loss.should_not be_nil
|
36
|
+
p.date.should_not be_nil
|
37
|
+
}
|
38
|
+
|
39
|
+
# 決済注文
|
40
|
+
positions = after.map{|i| i[1] }
|
41
|
+
positions.each {|p|
|
42
|
+
@s.settle( p[0] ) if p[0] =~ /MURJPY/
|
43
|
+
}
|
44
|
+
sleep 1
|
45
|
+
after_settle = @s.list_positions
|
46
|
+
assert_false after_settle.key?( positions[0] )
|
47
|
+
assert_false after_settle.key?( positions[1] )
|
48
|
+
end
|
36
49
|
|
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
50
|
end
|
47
51
|
end
|