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
プラグインを初期化します。.
-
#input_infos ⇒ Object
「jiji setting」でユーザーに入力を要求するデータの情報を返します。.
-
#list_pairs ⇒ Object
利用可能な通貨ペア一覧を取得します。.
-
#list_rates ⇒ Object
現在のレートを取得します。.
-
#order(pair, sell_or_buy, count) ⇒ Object
成り行きで発注を行います。.
-
#plugin_id ⇒ Object
プラグインの識別子を返します。.
Instance Method Details
#commit(position_id, count) ⇒ Object
建玉を決済します。
70 71 72 |
# File 'lib/jiji_plugin.rb', line 70 def commit( position_id, count ) @session.settle( position_id, count ) end |
#destroy_plugin ⇒ Object
プラグインを破棄します。
31 32 33 |
# File 'lib/jiji_plugin.rb', line 31 def destroy_plugin @session.close end |
#display_name ⇒ Object
プラグインの表示名を返します。
16 17 18 |
# File 'lib/jiji_plugin.rb', line 16 def display_name "CLICK Securities" end |
#init_plugin(props, logger) ⇒ Object
プラグインを初期化します。
27 28 29 |
# File 'lib/jiji_plugin.rb', line 27 def init_plugin( props, logger ) @session = ClickSecuritiesPluginSession.new( props, logger ) end |
#input_infos ⇒ Object
「jiji setting」でユーザーに入力を要求するデータの情報を返します。
20 21 22 23 24 |
# File 'lib/jiji_plugin.rb', line 20 def input_infos [ Input.new( :user, "Please input a user name of CLICK Securities.", false, nil ), Input.new( :password, "Please input a password of CLICK Securities.", true, nil ), Input.new( :proxy, "Please input a proxy. example: https://example.com:80 (default: nil )", false, nil ) ] end |
#list_pairs ⇒ Object
利用可能な通貨ペア一覧を取得します。
36 37 38 39 40 |
# File 'lib/jiji_plugin.rb', line 36 def list_pairs return ALL_PAIRS.map {|pair| Pair.new( pair, pair == ClickClientScrap::FX::ZARJPY ? 100000 : 10000 ) } end |
#list_rates ⇒ Object
現在のレートを取得します。
43 44 45 46 47 48 |
# File 'lib/jiji_plugin.rb', line 43 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
成り行きで発注を行います。
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jiji_plugin.rb', line 51 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 {|i| !before.include?(i[0]) } break if position } raise "order fialed." unless position return JIJI::Plugin::SecuritiesPlugin::Position.new( position[1].open_interest_id ) end |
#plugin_id ⇒ Object
プラグインの識別子を返します。
12 13 14 |
# File 'lib/jiji_plugin.rb', line 12 def plugin_id :click_securities end |