Class: JIJI::Plugin::ClickSecuritiesDemoPlugin

Inherits:
Object
  • Object
show all
Includes:
SecuritiesPlugin
Defined in:
lib/jiji/plugin/embedded/click_securities_demo_plugin.rb

Overview

クリック証券デモトレードアクセスプラグイン

Constant Summary

Constants included from SecuritiesPlugin

SecuritiesPlugin::FUTURE_NAME

Instance Method Summary collapse

Instance Method Details

#commit(position_id, count) ⇒ Object

建玉を決済します。



66
67
68
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 66

def commit( position_id, count )
  @client.request {|fx| fx.settle( position_id, count ) }
end

#convert_currency_pair_code(code) ⇒ Object

通貨ペアコードをシンボルに変換する



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 71

def convert_currency_pair_code(code)
  case code
    when ClickClient::FX::USDJPY
      return :USDJPY
    when ClickClient::FX::EURJPY
      return :EURJPY
    when ClickClient::FX::GBPJPY
      return :GBPJPY
    when ClickClient::FX::AUDJPY
      return :AUDJPY
    when ClickClient::FX::NZDJPY
      return :NZDJPY
    when ClickClient::FX::CADJPY
      return :CADJPY
    when ClickClient::FX::CHFJPY
      return :CHFJPY
    when ClickClient::FX::ZARJPY
      return :ZARJPY
    when ClickClient::FX::EURUSD
      return :EURUSD
    when ClickClient::FX::GBPUSD
      return :GBPUSD
    when ClickClient::FX::AUDUSD
      return :AUDUSD
    when ClickClient::FX::EURCHF
      return :EURCHF
    when ClickClient::FX::GBPCHF
      return :GBPCHF
    when ClickClient::FX::USDCHF
      return :USDCHF
  end
end

#convert_currency_pair_code_r(code) ⇒ Object

シンボルを通貨ペアコードに変換する



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 105

def convert_currency_pair_code_r(code)
  case code
    when :USDJPY
      return ClickClient::FX::USDJPY
    when :EURJPY
      return ClickClient::FX::EURJPY
    when :GBPJPY
      return ClickClient::FX::GBPJPY
    when :AUDJPY
      return ClickClient::FX::AUDJPY
    when :NZDJPY
      return ClickClient::FX::NZDJPY
    when :CADJPY
      return ClickClient::FX::CADJPY
    when :CHFJPY
      return ClickClient::FX::CHFJPY
    when :ZARJPY
      return ClickClient::FX::ZARJPY
    when :EURUSD
      return ClickClient::FX::EURUSD
    when :GBPUSD
      return ClickClient::FX::GBPUSD
    when :AUDUSD
      return ClickClient::FX::AUDUSD
    when :EURCHF
      return ClickClient::FX::EURCHF
    when :GBPCHF
      return ClickClient::FX::GBPCHF
    when :USDCHF
      return ClickClient::FX::USDCHF
  end
end

#destroy_pluginObject

プラグインを破棄します。



32
33
34
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 32

def destroy_plugin
  @client.close if @client
end

#display_nameObject

プラグインの表示名を返します。



17
18
19
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 17

def display_name
  "CLICK Securities DEMO Trade"
end

#init_plugin(props, logger) ⇒ Object

プラグインを初期化します。



28
29
30
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 28

def init_plugin( props, logger ) 
  @client = JIJI::Plugin::SingleClickClient.new( props, logger )
end

#input_infosObject

「jiji setting」でユーザーに入力を要求するデータの情報を返します。



21
22
23
24
25
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 21

def input_infos
  [ Input.new( :user, "Please input a user name of CLICK Securities DEMO Trade.", false, nil ),
    Input.new( :password, "Please input a password of CLICK Securities DEMO Trade.", true, nil ),
    Input.new( :proxy, "Please input a proxy. example: http://example.com:80 (default: nil )", false, nil )]
end

#list_pairsObject

利用可能な通貨ペア一覧を取得します。



37
38
39
40
41
42
43
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 37

def list_pairs
  pairs = @client.request {|fx| fx.list_currency_pairs }
  return pairs.map {|i| 
    name = convert_currency_pair_code(i[0])
    Pair.new( name, i[1].trade_unit )
  }
end

#list_ratesObject

現在のレートを取得します。



46
47
48
49
50
51
52
53
54
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 46

def list_rates
  @client.request {|fx|               
    fx.list_rates.inject({}) {|r,p|
      code = convert_currency_pair_code(p[0])
      r[code] = Rate.new( p[1].bid, p[1].ask, p[1].sell_swap, p[1].buy_swap )
      r
    }
  }
end

#order(pair, sell_or_buy, count) ⇒ Object

成り行きで発注を行います。



57
58
59
60
61
62
63
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 57

def order( pair, sell_or_buy, count )
  result = @client.request{ |fx|
      fx.order( convert_currency_pair_code_r(pair),
        sell_or_buy == :buy ? ClickClient::FX::BUY : ClickClient::FX::SELL,  count )
  }
  return JIJI::Plugin::SecuritiesPlugin::Position.new( result.open_interest_no )
end

#plugin_idObject

プラグインの識別子を返します。



13
14
15
# File 'lib/jiji/plugin/embedded/click_securities_demo_plugin.rb', line 13

def plugin_id
  :click_securities_demo
end