Class: ClickSecuritiesPlugin
- Inherits:
-
Object
- Object
- ClickSecuritiesPlugin
- Includes:
- JIJI::Plugin::SecuritiesPlugin
- Defined in:
- lib/jiji_plugin.rb
Overview
クリック証券アクセスプラグイン
Instance Method Summary collapse
-
#commit(position_id, count) ⇒ Object
建玉を決済します。.
-
#destroy_plugin ⇒ Object
プラグインを破棄します。.
-
#display_name ⇒ Object
プラグインの表示名を返します。.
-
#init_plugin(props, logger) ⇒ Object
プラグインを初期化します。.
-
#initialize(demo = false) ⇒ ClickSecuritiesPlugin
constructor
A new instance of ClickSecuritiesPlugin.
-
#input_infos ⇒ Object
「jiji setting」でユーザーに入力を要求するデータの情報を返します。.
-
#list_pairs ⇒ Object
利用可能な通貨ペア一覧を取得します。.
-
#list_rates ⇒ Object
現在のレートを取得します。.
-
#order(pair, sell_or_buy, count) ⇒ Object
成り行きで発注を行います。.
-
#plugin_id ⇒ Object
プラグインの識別子を返します。.
Constructor Details
#initialize(demo = false) ⇒ ClickSecuritiesPlugin
Returns a new instance of ClickSecuritiesPlugin.
12 13 14 |
# File 'lib/jiji_plugin.rb', line 12 def initialize( demo=false ) @demo = demo end |
Instance Method Details
#commit(position_id, count) ⇒ Object
建玉を決済します。
76 77 78 |
# File 'lib/jiji_plugin.rb', line 76 def commit( position_id, count ) @session.settle( position_id, count ) end |
#destroy_plugin ⇒ Object
プラグインを破棄します。
37 38 39 |
# File 'lib/jiji_plugin.rb', line 37 def destroy_plugin @session.close end |
#display_name ⇒ Object
プラグインの表示名を返します。
22 23 24 |
# File 'lib/jiji_plugin.rb', line 22 def display_name @demo ? "CLICK Securities DEMO" : "CLICK Securities" end |
#init_plugin(props, logger) ⇒ Object
プラグインを初期化します。
33 34 35 |
# File 'lib/jiji_plugin.rb', line 33 def init_plugin( props, logger ) @session = ClickSecuritiesPluginSession.new( props, logger, @demo ) end |
#input_infos ⇒ Object
「jiji setting」でユーザーに入力を要求するデータの情報を返します。
26 27 28 29 30 |
# File 'lib/jiji_plugin.rb', line 26 def input_infos [ Input.new( :user, "Please input a user name of CLICK Securities#{ @demo ? " DEMO" : "" }.", false, nil ), Input.new( :password, "Please input a password of CLICK Securities#{ @demo ? " DEMO" : "" }.", true, nil ), Input.new( :proxy, "Please input a proxy. example: http://example.com:80 (default: nil )", false, nil ) ] end |
#list_pairs ⇒ Object
利用可能な通貨ペア一覧を取得します。
42 43 44 45 46 |
# File 'lib/jiji_plugin.rb', line 42 def list_pairs return ALL_PAIRS.map {|pair| Pair.new( pair, pair == ClickClientScrap::FX::ZARJPY ? 100000 : 10000 ) } end |
#list_rates ⇒ Object
現在のレートを取得します。
49 50 51 52 53 54 |
# File 'lib/jiji_plugin.rb', line 49 def list_rates @session.list_rates.inject({}) {|r,p| r[p[0]] = Rate.new( p[1].bid_rate, p[1].ask_rate, p[1].sell_swap, p[1].buy_swap ) r } end |
#order(pair, sell_or_buy, count) ⇒ Object
成り行きで発注を行います。
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jiji_plugin.rb', line 57 def order( pair, sell_or_buy, count ) # 建玉一覧を取得 before = @session.list_open_interests.inject( Set.new ) {|s,i| s << i[0]; s } # 発注 @session.order( pair, sell_or_buy == :buy ? ClickClientScrap::FX::BUY : ClickClientScrap::FX::SELL, count ) # 建玉を特定 position = nil # 10s待っても取得できなければあきらめる 20.times {|i| sleep 0.5 position = @session.list_open_interests.find {|inte| !before.include?(inte[0]) } break if position } raise "order fialed." unless position return JIJI::Plugin::SecuritiesPlugin::Position.new( position[1].open_interest_id ) end |
#plugin_id ⇒ Object
プラグインの識別子を返します。
17 18 19 |
# File 'lib/jiji_plugin.rb', line 17 def plugin_id @demo ? :click_securities_demo : :click_securities end |