Class: JIJI::RmtOperator

Inherits:
Operator show all
Defined in:
lib/jiji/operator.rb

Overview

リアル取引用オペレーター

Instance Attribute Summary

Attributes inherited from Operator

#conf, #draw, #fixed_profit_or_loss, #lose, #positions, #profit_or_loss, #win

Instance Method Summary collapse

Methods inherited from Operator

#flush, #next_rates, #stop, #win_rate

Constructor Details

#initialize(client, logger, trade_result_dao, trade_enable = true, money = nil) ⇒ RmtOperator

コンストラクタ

client

クライアント

logger

ロガー

money

保証金



289
290
291
292
293
294
# File 'lib/jiji/operator.rb', line 289

def initialize( client, logger, trade_result_dao, trade_enable=true, money=nil )
  super(trade_result_dao,money)
  @client = client
  @logger = logger
  @trade_enable = trade_enable
end

Instance Method Details

#buy(count, pair = :EURJPY, trader = "") ⇒ Object

購入する

count

購入する数量

return

Position



299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/jiji/operator.rb', line 299

def buy(count, pair=:EURJPY, trader="")
  id = nil
  if @trade_enable
    JIJI::Util.log_if_error_and_throw( @logger ) {
      rate = @rate[pair]
      # 成り行きで買い
      id = @client.order( pair, :buy, count ).position_id
    }
  end
  p = super(count, pair, trader)
  p.raw_position_id = id if id
  p
end

#commit(position) ⇒ Object

取引を確定する



331
332
333
334
335
336
337
338
# File 'lib/jiji/operator.rb', line 331

def commit(position)
  if @trade_enable && position.raw_position_id
    JIJI::Util.log_if_error_and_throw( @logger ) {
      @client.commit( position.raw_position_id, position.count )
    }
  end
  super(position)
end

#sell(count, pair = :EURJPY, trader = "") ⇒ Object

売却する

count

売却する数量

return

Position



316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/jiji/operator.rb', line 316

def sell(count, pair=:EURJPY, trader="")
  id = nil
  if @trade_enable
    JIJI::Util.log_if_error_and_throw( @logger ) {
      rate = @rate[pair]
      # 成り行きで売り
      id = @client.order( pair, :sell, count ).position_id
    }
  end
  p = super(count, pair, trader)
  p.raw_position_id = id if id
  p
end

#trade_enableObject



343
344
345
# File 'lib/jiji/operator.rb', line 343

def trade_enable
  return @trade_enable
end

#trade_enable=(value) ⇒ Object



340
341
342
# File 'lib/jiji/operator.rb', line 340

def trade_enable=(value)
  @trade_enable = value && conf.get([:system,:trade_enable], true)
end