Class: JIJI::AgentOperator
- Inherits:
-
Object
- Object
- JIJI::AgentOperator
- Defined in:
- lib/jiji/operator.rb
Overview
各エージェントに設定されるオペレータ。取引者としてエージェント名を指定して売り買いを行なう。また、建玉を独自に保持する。(エージェント間で共有されない) 売/買ロジック自体ははオペレータに委譲する。
Instance Attribute Summary collapse
-
#positions ⇒ Object
readonly
建て玉.
Instance Method Summary collapse
-
#buy(count, pair = :EURJPY) ⇒ Object
購入する count:: 購入する数量 pair:: 通貨ペア return:: ポジション.
-
#commit(position) ⇒ Object
取引を確定する.
-
#initialize(operator, agent_name) ⇒ AgentOperator
constructor
A new instance of AgentOperator.
-
#sell(count, pair = :EURJPY) ⇒ Object
売却する count:: 売却する数量 pair:: 通貨ペア return:: ポジション.
Constructor Details
#initialize(operator, agent_name) ⇒ AgentOperator
Returns a new instance of AgentOperator.
354 355 356 357 358 |
# File 'lib/jiji/operator.rb', line 354 def initialize( operator, agent_name ) @operator = operator @name = agent_name @positions = {}.taint end |
Instance Attribute Details
#positions ⇒ Object (readonly)
建て玉
387 388 389 |
# File 'lib/jiji/operator.rb', line 387 def positions @positions end |
Instance Method Details
#buy(count, pair = :EURJPY) ⇒ Object
購入する
- count
-
購入する数量
- pair
-
通貨ペア
- return
-
ポジション
364 365 366 367 368 |
# File 'lib/jiji/operator.rb', line 364 def buy(count, pair=:EURJPY) p = @operator.buy( count, pair, @name ) @positions[p.position_id] = p return p end |
#commit(position) ⇒ Object
取引を確定する
381 382 383 384 |
# File 'lib/jiji/operator.rb', line 381 def commit(position) @operator.commit(position) @positions.delete position.position_id end |
#sell(count, pair = :EURJPY) ⇒ Object
売却する
- count
-
売却する数量
- pair
-
通貨ペア
- return
-
ポジション
374 375 376 377 378 |
# File 'lib/jiji/operator.rb', line 374 def sell(count, pair=:EURJPY) p = @operator.sell( count, pair, @name ) @positions[p.position_id] = p return p end |