Initial commit
This commit is contained in:
40
app/trading/matching/price_level.rb
Normal file
40
app/trading/matching/price_level.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Matching
|
||||
class PriceLevel
|
||||
|
||||
attr :price, :orders
|
||||
|
||||
def initialize(price)
|
||||
@price = price
|
||||
@orders = []
|
||||
end
|
||||
|
||||
def top
|
||||
@orders.first
|
||||
end
|
||||
|
||||
def empty?
|
||||
@orders.empty?
|
||||
end
|
||||
|
||||
def add(order)
|
||||
unless find(order.id)
|
||||
@orders << order
|
||||
end
|
||||
end
|
||||
|
||||
def total
|
||||
@orders.map(&:volume).sum
|
||||
end
|
||||
|
||||
def remove(order)
|
||||
@orders.delete_if { |o| o.id == order.id }
|
||||
end
|
||||
|
||||
def find(id)
|
||||
@orders.find { |o| o.id == id }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user