clickclient_scrap 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/lib/clickclient_scrap.rb +726 -688
- data/lib/jiji_plugin.rb +17 -8
- data/sample/constants.rb +5 -0
- data/sample/sample_get_margin.rb +24 -0
- data/sample/sample_list_open_interests.rb +25 -0
- data/sample/sample_list_orders.rb +28 -0
- data/sample/sample_list_rates.rb +16 -0
- data/sample/sample_market_order.rb +21 -0
- data/sample/sample_oco_order.rb +36 -0
- data/sample/sample_order.rb +64 -0
- data/sample/sample_settle.rb +18 -0
- data/specs/cancel_order_spec.rb +43 -0
- data/specs/common.rb +30 -0
- data/specs/jiji_plugin_spec!.rb +127 -0
- data/specs/limit_order_spec.rb +98 -0
- data/specs/list_orders_spec.rb +28 -0
- data/specs/market_order_spec!.rb +131 -0
- data/specs/oco_order_spec.rb +60 -0
- data/specs/order_error_spec.rb +139 -0
- metadata +27 -6
- data/test/test_FxSession.rb +0 -38
- data/test/test_jiji_plugin.rb +0 -77
data/lib/jiji_plugin.rb
CHANGED
@@ -8,24 +8,29 @@ require 'thread'
|
|
8
8
|
class ClickSecuritiesPlugin
|
9
9
|
include JIJI::Plugin::SecuritiesPlugin
|
10
10
|
|
11
|
+
def initialize( demo=false )
|
12
|
+
@demo = demo
|
13
|
+
end
|
14
|
+
|
11
15
|
#プラグインの識別子を返します。
|
12
16
|
def plugin_id
|
13
|
-
:click_securities
|
17
|
+
@demo ? :click_securities_demo : :click_securities
|
14
18
|
end
|
19
|
+
|
15
20
|
#プラグインの表示名を返します。
|
16
21
|
def display_name
|
17
|
-
"CLICK Securities"
|
22
|
+
@demo ? "CLICK Securities DEMO" : "CLICK Securities"
|
18
23
|
end
|
19
24
|
#「jiji setting」でユーザーに入力を要求するデータの情報を返します。
|
20
25
|
def input_infos
|
21
|
-
[ Input.new( :user, "Please input a user name of CLICK Securities.", false, nil ),
|
22
|
-
Input.new( :password, "Please input a password of CLICK Securities.", true, nil ),
|
26
|
+
[ Input.new( :user, "Please input a user name of CLICK Securities#{ @demo ? " DEMO" : "" }.", false, nil ),
|
27
|
+
Input.new( :password, "Please input a password of CLICK Securities#{ @demo ? " DEMO" : "" }.", true, nil ),
|
23
28
|
Input.new( :proxy, "Please input a proxy. example: http://example.com:80 (default: nil )", false, nil ) ]
|
24
29
|
end
|
25
30
|
|
26
31
|
#プラグインを初期化します。
|
27
32
|
def init_plugin( props, logger )
|
28
|
-
@session = ClickSecuritiesPluginSession.new( props, logger )
|
33
|
+
@session = ClickSecuritiesPluginSession.new( props, logger, @demo )
|
29
34
|
end
|
30
35
|
#プラグインを破棄します。
|
31
36
|
def destroy_plugin
|
@@ -85,10 +90,11 @@ private
|
|
85
90
|
end
|
86
91
|
|
87
92
|
class ClickSecuritiesPluginSession
|
88
|
-
def initialize( props, logger )
|
93
|
+
def initialize( props, logger, demo=false )
|
89
94
|
@props = props
|
90
95
|
@logger = logger
|
91
96
|
@m = Mutex.new
|
97
|
+
@demo = demo
|
92
98
|
end
|
93
99
|
def method_missing( name, *args )
|
94
100
|
@m.synchronize {
|
@@ -117,7 +123,7 @@ class ClickSecuritiesPluginSession
|
|
117
123
|
if @props.key?(:proxy) && @props[:proxy] != nil && @props[:proxy].length > 0
|
118
124
|
proxy = @props[:proxy]
|
119
125
|
end
|
120
|
-
@client ||= ClickClientScrap::Client.new( proxy )
|
126
|
+
@client ||= ClickClientScrap::Client.new( proxy, @demo )
|
121
127
|
@session ||= @client.fx_session( @props[:user], @props[:password] )
|
122
128
|
rescue
|
123
129
|
@logger.error $!
|
@@ -130,4 +136,7 @@ end
|
|
130
136
|
JIJI::Plugin.register(
|
131
137
|
JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME,
|
132
138
|
ClickSecuritiesPlugin.new )
|
133
|
-
|
139
|
+
|
140
|
+
JIJI::Plugin.register(
|
141
|
+
JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME,
|
142
|
+
ClickSecuritiesPlugin.new( true ) )
|
data/sample/constants.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, PASS ) {|session|
|
10
|
+
|
11
|
+
# 与力を取得
|
12
|
+
margin = session.get_margin
|
13
|
+
puts <<-STR
|
14
|
+
時価評価の総額 : #{margin.market_value}
|
15
|
+
建玉の評価損益 : #{margin.appraisal_profit_or_loss_of_open_interest}
|
16
|
+
口座残高 : #{margin.balance_in_account}
|
17
|
+
証拠金の維持率 : #{margin.guarantee_money_maintenance_ratio}
|
18
|
+
余力 : #{margin.margin}
|
19
|
+
拘束されている証拠金 : #{margin.freezed_guarantee_money}
|
20
|
+
必要な証拠金 : #{margin.required_guarantee_money}
|
21
|
+
注文中の証拠金 : #{margin.ordered_guarantee_money}
|
22
|
+
振替可能額 : #{margin.transferable_money_amount}
|
23
|
+
STR
|
24
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, PASS ) {|session|
|
10
|
+
|
11
|
+
# 建玉一覧を取得
|
12
|
+
list = session.list_open_interests
|
13
|
+
list.each_pair {|k,v|
|
14
|
+
puts <<-STR
|
15
|
+
---
|
16
|
+
open_interest_id : #{v.open_interest_id}
|
17
|
+
sell_or_buy : #{v.sell_or_buy}
|
18
|
+
pair : #{v.pair}
|
19
|
+
count : #{v.count}
|
20
|
+
rate : #{v.rate}
|
21
|
+
profit or loss : #{v.profit_or_loss}
|
22
|
+
|
23
|
+
STR
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, PASS ) {|session|
|
10
|
+
|
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
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, 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,21 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, PASS ) {|session|
|
10
|
+
|
11
|
+
#成り行き注文
|
12
|
+
session.order( ClickClientScrap::FX::USDJPY, ClickClientScrap::FX::BUY, 1)
|
13
|
+
session.order( ClickClientScrap::FX::USDJPY, ClickClientScrap::FX::SELL, 1)
|
14
|
+
|
15
|
+
# 建玉一覧を取得
|
16
|
+
list = session.list_open_interests
|
17
|
+
list.each_pair {|k,v|
|
18
|
+
# すべて決済
|
19
|
+
session.settle( v.open_interest_id, v.count )
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, 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
|
+
order_ids = []
|
18
|
+
|
19
|
+
##OCO注文
|
20
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::BUY, 1, {
|
21
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate - 0.5, # 指値レート
|
22
|
+
:stop_order_rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate + 0.5, # 逆指値レート
|
23
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
|
24
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_TODAY # 有効期限: 当日限り
|
25
|
+
})
|
26
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::SELL, 1, {
|
27
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate + 0.5, # 指値レート
|
28
|
+
:stop_order_rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate - 0.5, # 逆指値レート
|
29
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
|
30
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
|
31
|
+
:expiration_date=>Date.today+2 # 2日後
|
32
|
+
})
|
33
|
+
|
34
|
+
# すべての注文をキャンセル
|
35
|
+
order_ids.each{|id| session.cancel_order(id.order_no) }
|
36
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, 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
|
+
order_ids = []
|
18
|
+
|
19
|
+
## 指値注文
|
20
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::BUY, 1, {
|
21
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate - 0.5, # 指値レート
|
22
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
|
23
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_TODAY # 有効期限: 当日限り
|
24
|
+
})
|
25
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::SELL, 1, {
|
26
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate + 0.5, # 指値レート
|
27
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_LIMIT_ORDER, # 執行条件: 指値
|
28
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_WEEK_END # 有効期限: 週末まで
|
29
|
+
})
|
30
|
+
|
31
|
+
# 逆指値注文
|
32
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::BUY, 1, {
|
33
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate + 0.5, # 逆指値レート
|
34
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER, # 執行条件: 逆指値
|
35
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_INFINITY # 有効期限: 無限
|
36
|
+
})
|
37
|
+
order_ids << session.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::SELL, 1, {
|
38
|
+
:rate=>rates[ClickClientScrap::FX::EURJPY].ask_rate - 0.5, # 逆指値レート
|
39
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_REVERSE_LIMIT_ORDER, # 執行条件: 逆指値
|
40
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_SPECIFIED, # 有効期限: 指定
|
41
|
+
:expiration_date=>Date.today+2 # 2日後
|
42
|
+
})
|
43
|
+
|
44
|
+
# 注文一覧を取得
|
45
|
+
orders = session.list_orders
|
46
|
+
orders.each_pair {|k,v|
|
47
|
+
puts <<-STR
|
48
|
+
---
|
49
|
+
order_no : #{v.order_no}
|
50
|
+
trade_type : #{v.trade_type}
|
51
|
+
order_type : #{v.order_type}
|
52
|
+
execution_expression : #{v.execution_expression}
|
53
|
+
sell_or_buy : #{v.sell_or_buy}
|
54
|
+
pair : #{v.pair}
|
55
|
+
count : #{v.count}
|
56
|
+
rate : #{v.rate}
|
57
|
+
order_state : #{v.order_state}
|
58
|
+
|
59
|
+
STR
|
60
|
+
}
|
61
|
+
|
62
|
+
# すべての注文をキャンセル
|
63
|
+
order_ids.each{|id| session.cancel_order(id.order_no) }
|
64
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
$: << "../lib"
|
3
|
+
|
4
|
+
require 'clickclient_scrap'
|
5
|
+
require 'constants'
|
6
|
+
|
7
|
+
# ログイン
|
8
|
+
c = ClickClientScrap::Client.new
|
9
|
+
c.fx_session( USER, PASS ) {|session|
|
10
|
+
|
11
|
+
# 建玉一覧を取得
|
12
|
+
list = session.list_open_interests
|
13
|
+
list.each_pair {|k,v|
|
14
|
+
# すべて決済
|
15
|
+
session.settle( v.open_interest_id, v.count )
|
16
|
+
}
|
17
|
+
|
18
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
$: << "../lib"
|
2
|
+
|
3
|
+
require 'clickclient_scrap'
|
4
|
+
require 'common'
|
5
|
+
|
6
|
+
describe "cancel_order" do
|
7
|
+
include TestBase
|
8
|
+
|
9
|
+
it "複数のページがあってもキャンセルできる" do
|
10
|
+
do_test {|s|
|
11
|
+
10.times{|i|
|
12
|
+
@order_ids << @s.order( ClickClientScrap::FX::USDJPY, ClickClientScrap::FX::BUY, 1, {
|
13
|
+
:rate=>@rates[ClickClientScrap::FX::USDJPY].ask_rate - 0.5,
|
14
|
+
:execution_expression=>ClickClientScrap::FX::EXECUTION_EXPRESSION_LIMIT_ORDER,
|
15
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_TODAY
|
16
|
+
})
|
17
|
+
}
|
18
|
+
10.times{|i|
|
19
|
+
@order_ids << @s.order( ClickClientScrap::FX::EURJPY, ClickClientScrap::FX::BUY, 1, {
|
20
|
+
:rate=>@rates[ClickClientScrap::FX::EURJPY].ask_rate - 0.5,
|
21
|
+
:stop_order_rate=>@rates[ClickClientScrap::FX::EURJPY].ask_rate + 0.5,
|
22
|
+
:expiration_type=>ClickClientScrap::FX::EXPIRATION_TYPE_TODAY
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
# 末尾から消していき、すべて削除できればOK。
|
27
|
+
@order_ids.reverse.each {|id|
|
28
|
+
@s.cancel_order(id.order_no)
|
29
|
+
@order_ids.pop
|
30
|
+
}
|
31
|
+
@s.list_orders(ClickClientScrap::FX::ORDER_CONDITION_ON_ORDER).size.should == 0
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "削除対象が存在しない" do
|
36
|
+
do_test {|s|
|
37
|
+
proc {
|
38
|
+
@s.cancel_order("not found")
|
39
|
+
}.should raise_error( RuntimeError, "illegal order_no. order_no=not found" )
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/specs/common.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
# ※「../etc」ディレクトリにuser,passファイルを作成し、
|
3
|
+
# ユーザー名,パスワードを設定しておくこと。
|
4
|
+
USER=IO.read("../etc/user")
|
5
|
+
PASS=IO.read("../etc/pass")
|
6
|
+
DEMO_USER=IO.read("../etc/demo_user")
|
7
|
+
DEMO_PASS=IO.read("../etc/demo_pass")
|
8
|
+
|
9
|
+
|
10
|
+
# ベース
|
11
|
+
module TestBase
|
12
|
+
# 通常/デモのそれぞれのセッションでブロックを実行する。
|
13
|
+
def do_test
|
14
|
+
[{:c=>ClickClientScrap::Client.new, :p=>PASS, :u=>USER },
|
15
|
+
{:c=>ClickClientScrap::Client.new(nil, true), :p=>DEMO_PASS, :u=>DEMO_USER }].each {|i|
|
16
|
+
@s = i[:c].fx_session( i[:u], i[:p] )
|
17
|
+
@rates = @s.list_rates
|
18
|
+
@order_ids = []
|
19
|
+
begin
|
20
|
+
yield @s
|
21
|
+
ensure
|
22
|
+
begin
|
23
|
+
@order_ids.each {|order| @s.cancel_order(order.order_no) } if @s
|
24
|
+
ensure
|
25
|
+
@s.logout if @s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "logger"
|
7
|
+
require 'clickclient_scrap'
|
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
|
+
@logger = Logger.new STDOUT
|
19
|
+
}
|
20
|
+
it "jiji pluginのテスト(DEMO)" do
|
21
|
+
plugins = JIJI::Plugin.get( JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME )
|
22
|
+
plugin = plugins.find {|i| i.plugin_id == :click_securities_demo }
|
23
|
+
|
24
|
+
plugin.should_not be_nil
|
25
|
+
plugin.display_name.should == "CLICK Securities DEMO"
|
26
|
+
|
27
|
+
begin
|
28
|
+
plugin.init_plugin( {:user=>DEMO_USER, :password=>DEMO_PASS}, @logger )
|
29
|
+
|
30
|
+
# 利用可能な通貨ペア一覧とレート
|
31
|
+
pairs = plugin.list_pairs
|
32
|
+
rates = plugin.list_rates
|
33
|
+
pairs.each {|p|
|
34
|
+
# 利用可能とされたペアのレートが取得できていることを確認
|
35
|
+
p.name.should_not be_nil
|
36
|
+
p.trade_unit.should_not be_nil
|
37
|
+
rates[p.name].should_not be_nil
|
38
|
+
rates[p.name].bid.should_not be_nil
|
39
|
+
rates[p.name].ask.should_not be_nil
|
40
|
+
rates[p.name].sell_swap.should_not be_nil
|
41
|
+
rates[p.name].buy_swap.should_not be_nil
|
42
|
+
}
|
43
|
+
sleep 1
|
44
|
+
|
45
|
+
3.times {
|
46
|
+
rates = plugin.list_rates
|
47
|
+
pairs.each {|p|
|
48
|
+
# 利用可能とされたペアのレートが取得できていることを確認
|
49
|
+
p.name.should_not be_nil
|
50
|
+
p.trade_unit.should_not be_nil
|
51
|
+
rates[p.name].should_not be_nil
|
52
|
+
rates[p.name].bid.should_not be_nil
|
53
|
+
rates[p.name].ask.should_not be_nil
|
54
|
+
rates[p.name].sell_swap.should_not be_nil
|
55
|
+
rates[p.name].buy_swap.should_not be_nil
|
56
|
+
}
|
57
|
+
sleep 3
|
58
|
+
}
|
59
|
+
|
60
|
+
# 売り/買い
|
61
|
+
sell = plugin.order( :EURJPY, :sell, 1 )
|
62
|
+
buy = plugin.order( :EURJPY, :buy, 1 )
|
63
|
+
sell.position_id.should_not be_nil
|
64
|
+
buy.position_id.should_not be_nil
|
65
|
+
|
66
|
+
# 約定
|
67
|
+
plugin.commit sell.position_id, 1
|
68
|
+
plugin.commit buy.position_id, 1
|
69
|
+
ensure
|
70
|
+
plugin.destroy_plugin
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "jiji pluginのテスト" do
|
75
|
+
plugins = JIJI::Plugin.get( JIJI::Plugin::SecuritiesPlugin::FUTURE_NAME )
|
76
|
+
plugin = plugins.find {|i| i.plugin_id == :click_securities }
|
77
|
+
|
78
|
+
plugin.should_not be_nil
|
79
|
+
plugin.display_name.should == "CLICK Securities"
|
80
|
+
|
81
|
+
begin
|
82
|
+
plugin.init_plugin( {:user=>USER, :password=>PASS}, @logger )
|
83
|
+
|
84
|
+
# 利用可能な通貨ペア一覧とレート
|
85
|
+
pairs = plugin.list_pairs
|
86
|
+
rates = plugin.list_rates
|
87
|
+
pairs.each {|p|
|
88
|
+
# 利用可能とされたペアのレートが取得できていることを確認
|
89
|
+
p.name.should_not be_nil
|
90
|
+
p.trade_unit.should_not be_nil
|
91
|
+
rates[p.name].should_not be_nil
|
92
|
+
rates[p.name].bid.should_not be_nil
|
93
|
+
rates[p.name].ask.should_not be_nil
|
94
|
+
rates[p.name].sell_swap.should_not be_nil
|
95
|
+
rates[p.name].buy_swap.should_not be_nil
|
96
|
+
}
|
97
|
+
sleep 1
|
98
|
+
|
99
|
+
3.times {
|
100
|
+
rates = plugin.list_rates
|
101
|
+
pairs.each {|p|
|
102
|
+
# 利用可能とされたペアのレートが取得できていることを確認
|
103
|
+
p.name.should_not be_nil
|
104
|
+
p.trade_unit.should_not be_nil
|
105
|
+
rates[p.name].should_not be_nil
|
106
|
+
rates[p.name].bid.should_not be_nil
|
107
|
+
rates[p.name].ask.should_not be_nil
|
108
|
+
rates[p.name].sell_swap.should_not be_nil
|
109
|
+
rates[p.name].buy_swap.should_not be_nil
|
110
|
+
}
|
111
|
+
sleep 3
|
112
|
+
}
|
113
|
+
|
114
|
+
# 売り/買い
|
115
|
+
sell = plugin.order( :EURJPY, :sell, 1 )
|
116
|
+
buy = plugin.order( :EURJPY, :buy, 1 )
|
117
|
+
sell.position_id.should_not be_nil
|
118
|
+
buy.position_id.should_not be_nil
|
119
|
+
|
120
|
+
# 約定
|
121
|
+
plugin.commit sell.position_id, 1
|
122
|
+
plugin.commit buy.position_id, 1
|
123
|
+
ensure
|
124
|
+
plugin.destroy_plugin
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|