Class: JIJI::Position
- Inherits:
-
Object
- Object
- JIJI::Position
- Defined in:
- lib/jiji/operator.rb
Overview
ポジション
Constant Summary collapse
- SELL =
売り/買い区分
0- BUY =
1- STATE_WAITING =
状態:注文中
0- STATE_START =
状態:新規
1- STATE_FIX_WAITING =
状態:決済注文中
2- STATE_FIXED =
状態:決済済み
3- STATE_LOST =
状態:約定前にシステムが再起動された
4
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
取引数量.
-
#current_price ⇒ Object
readonly
現在価値.
-
#date ⇒ Object
readonly
購入日時.
-
#fix_date ⇒ Object
readonly
決済日時.
-
#fix_rate ⇒ Object
readonly
決済時のレート.
-
#open_interest_no ⇒ Object
建玉番号.
-
#operator ⇒ Object
readonly
クライアント.
-
#order_no ⇒ Object
注文番号.
-
#pair ⇒ Object
readonly
通貨ペア.
-
#position_id ⇒ Object
readonly
一意な識別子.
-
#price ⇒ Object
readonly
取得金額.
-
#profit_or_loss ⇒ Object
readonly
現在の損益.
-
#rate ⇒ Object
readonly
購入時のレート.
-
#sell_or_buy ⇒ Object
readonly
売りか買いか?.
-
#state ⇒ Object
readonly
状態.
-
#swap ⇒ Object
readonly
決済時のレート.
-
#trader ⇒ Object
readonly
取引実行者.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #_commit ⇒ Object
-
#initialize(position_id, sell_or_buy, count, unit, date, rate, pair, trader, operator, open_interest_no = "", order_no = "") ⇒ Position
constructor
コンストラクタ.
- #lost ⇒ Object
-
#next(rates) ⇒ Object
現在価格を更新.
- #values ⇒ Object
Constructor Details
#initialize(position_id, sell_or_buy, count, unit, date, rate, pair, trader, operator, open_interest_no = "", order_no = "") ⇒ Position
コンストラクタ
- sell_or_buy
-
売りor買い
- count
-
数量
- unit
-
取引単位
- date
-
取引日時
- rate
-
レート
- pair
-
通貨ペア
- trader
-
取引実行者
- operator
-
operator
- open_interest_no
-
建玉番号
- order_no
-
注文番号
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/jiji/operator.rb', line 165 def initialize( position_id, sell_or_buy, count, unit, date, rate, pair, trader, operator, open_interest_no="", order_no="" ) @position_id = position_id @sell_or_buy = sell_or_buy @count = count @unit = unit @price = (count*unit*rate).to_i @date = date @profit_or_loss = 0 @state =STATE_START @rate = rate @pair = pair @trader = trader @open_interest_no = open_interest_no @order_no = order_no @operator = operator @info = {} @swap = 0 @swap_time = Time.local( date.year, \ date.month, date.day, operator.conf.get([:swap_time], 5 )) @swap_time += 60*60*24 if date > @swap_time end |
Instance Attribute Details
#count ⇒ Object (readonly)
取引数量
266 267 268 |
# File 'lib/jiji/operator.rb', line 266 def count @count end |
#current_price ⇒ Object (readonly)
現在価値
270 271 272 |
# File 'lib/jiji/operator.rb', line 270 def current_price @current_price end |
#date ⇒ Object (readonly)
購入日時
262 263 264 |
# File 'lib/jiji/operator.rb', line 262 def date @date end |
#fix_date ⇒ Object (readonly)
決済日時
264 265 266 |
# File 'lib/jiji/operator.rb', line 264 def fix_date @fix_date end |
#fix_rate ⇒ Object (readonly)
決済時のレート
276 277 278 |
# File 'lib/jiji/operator.rb', line 276 def fix_rate @fix_rate end |
#open_interest_no ⇒ Object
建玉番号
250 251 252 |
# File 'lib/jiji/operator.rb', line 250 def open_interest_no @open_interest_no end |
#operator ⇒ Object (readonly)
クライアント
248 249 250 |
# File 'lib/jiji/operator.rb', line 248 def operator @operator end |
#order_no ⇒ Object
注文番号
252 253 254 |
# File 'lib/jiji/operator.rb', line 252 def order_no @order_no end |
#pair ⇒ Object (readonly)
通貨ペア
280 281 282 |
# File 'lib/jiji/operator.rb', line 280 def pair @pair end |
#position_id ⇒ Object (readonly)
一意な識別子
255 256 257 |
# File 'lib/jiji/operator.rb', line 255 def position_id @position_id end |
#price ⇒ Object (readonly)
取得金額
268 269 270 |
# File 'lib/jiji/operator.rb', line 268 def price @price end |
#profit_or_loss ⇒ Object (readonly)
現在の損益
272 273 274 |
# File 'lib/jiji/operator.rb', line 272 def profit_or_loss @profit_or_loss end |
#rate ⇒ Object (readonly)
購入時のレート
274 275 276 |
# File 'lib/jiji/operator.rb', line 274 def rate @rate end |
#sell_or_buy ⇒ Object (readonly)
売りか買いか?
257 258 259 |
# File 'lib/jiji/operator.rb', line 257 def sell_or_buy @sell_or_buy end |
#state ⇒ Object (readonly)
状態
259 260 261 |
# File 'lib/jiji/operator.rb', line 259 def state @state end |
#swap ⇒ Object (readonly)
決済時のレート
278 279 280 |
# File 'lib/jiji/operator.rb', line 278 def swap @swap end |
#trader ⇒ Object (readonly)
取引実行者
282 283 284 |
# File 'lib/jiji/operator.rb', line 282 def trader @trader end |
Instance Method Details
#[](key) ⇒ Object
221 222 223 |
# File 'lib/jiji/operator.rb', line 221 def [](key) @info[key] end |
#[]=(key, value) ⇒ Object
224 225 226 |
# File 'lib/jiji/operator.rb', line 224 def []=(key, value) @info[key] = value end |
#_commit ⇒ Object
190 191 192 193 194 195 |
# File 'lib/jiji/operator.rb', line 190 def _commit raise "illegal state" if @state != STATE_START @state = STATE_FIXED @fix_date = @current_date @fix_rate = @current_rate end |
#lost ⇒ Object
197 198 199 |
# File 'lib/jiji/operator.rb', line 197 def lost @state = STATE_LOST end |
#next(rates) ⇒ Object
現在価格を更新
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/jiji/operator.rb', line 202 def next(rates) return if @state == STATE_FIXED rate = rates[@pair] @current_rate = @sell_or_buy == BUY ? rate.bid : rate.ask @current_price = (@count * @unit * @current_rate).to_i # swap if @swap_time <= rates.time @swap += @sell_or_buy == BUY ? rate.buy_swap : rate.sell_swap @swap_time += 60*60*24 end @profit_or_loss = @sell_or_buy == BUY \ ? @current_price - @price + @swap\ : @price - @current_price + @swap @current_date = rates.time end |
#values ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/jiji/operator.rb', line 228 def values { :position_id => position_id, :open_interest_no=> open_interest_no, :sell_or_buy => sell_or_buy == JIJI::Position::SELL ? :sell : :buy, :state => state, :date => date.to_i, :fix_date => fix_date.to_i, :count => count , :price => price, :profit_or_loss => profit_or_loss.to_i, :rate => rate, :fix_rate => fix_rate, :swap=> swap, :pair => pair, :trader => trader } end |