class Jiji::Model::Trading::ClosingPolicy

決済条件

Public Class Methods

create(options) click to toggle source

for internal use.

# File src/jiji/model/trading/closing_policy.rb, line 35
def self.create(options)
  ClosingPolicy.new do |c|
    c.take_profit     = options[:take_profit]     || 0
    c.stop_loss       = options[:stop_loss]       || 0
    c.trailing_stop   = options[:trailing_stop]   || 0
    c.trailing_amount = options[:trailing_amount] || 0
  end
end
extract_stop_loss_from_order(stop_loss_on_fill, price) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 53
def self.extract_stop_loss_from_order(stop_loss_on_fill, price)
  if stop_loss_on_fill
    if stop_loss_on_fill[:price]
      BigDecimal(stop_loss_on_fill[:price], 10)
    elsif stop_loss_on_fill[:distance]
      BigDecimal(price, 10) + stop_loss_on_fill[:distance]
    end
  else
    0
  end
end
extract_stop_loss_from_trade(trade) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 89
def self.extract_stop_loss_from_trade(trade)
  price = trade['stopLossOrder'] && trade['stopLossOrder']['price']
  price ? BigDecimal(price, 10) : 0
end
extract_take_profit_from_order(take_profit_on_fill) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 65
def self.extract_take_profit_from_order(take_profit_on_fill)
  price = take_profit_on_fill && take_profit_on_fill[:price]
  price ? BigDecimal(price, 10) : 0
end
extract_take_profit_from_trade(trade) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 94
def self.extract_take_profit_from_trade(trade)
  price = trade['takeProfitOrder'] && trade['takeProfitOrder']['price']
  price ? BigDecimal(price, 10) : 0
end
extract_trailing_amount_from_order(trailing_stop_loss_on_fill) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 75
def self.extract_trailing_amount_from_order(trailing_stop_loss_on_fill)
  price = trailing_stop_loss_on_fill && trailing_stop_loss_on_fill[:trailing_stop_value]
  price ? BigDecimal(price, 10) : 0
end
extract_trailing_amount_from_trade(trade) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 104
def self.extract_trailing_amount_from_trade(trade)
  price = trade['trailingStopLossOrder'] && trade['trailingStopLossOrder']['trailingStopValue']
  price ? BigDecimal(price, 10) : 0
end
extract_trailing_stop_from_order(trailing_stop_loss_on_fill) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 70
def self.extract_trailing_stop_from_order(trailing_stop_loss_on_fill)
  price = trailing_stop_loss_on_fill && trailing_stop_loss_on_fill[:distance]
  price ? BigDecimal(price, 10) : 0
end
extract_trailing_stop_from_trade(trade) click to toggle source
# File src/jiji/model/trading/closing_policy.rb, line 99
def self.extract_trailing_stop_from_trade(trade)
  price = trade['trailingStopLossOrder'] && trade['trailingStopLossOrder']['distance']
  price ? BigDecimal(price, 10) : 0
end