Allow iteration of limit volume tracker entries
This commit is contained in:
parent
4b48904f1e
commit
16028989e4
@ -1,6 +1,7 @@
|
||||
module Rex
|
||||
module Book
|
||||
class LimitVolumeTracker
|
||||
include Enumerable
|
||||
LimitVolumeChange = Struct.new(:side, :price, :quantity)
|
||||
|
||||
attr_reader :volumes
|
||||
@ -24,6 +25,18 @@ module Rex
|
||||
]
|
||||
end
|
||||
|
||||
def each
|
||||
volumes.each do |side, limits|
|
||||
limits.each do |limit, volume|
|
||||
yield LimitVolumeChange.new(
|
||||
side ? :buy : :sell,
|
||||
limit,
|
||||
volume
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def remove_order(order)
|
||||
volumes[order.is_buy][order.price] -= order.remaining_quantity
|
||||
|
||||
|
@ -37,6 +37,22 @@ RSpec.describe Rex::Book::LimitVolumeTracker do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#each" do
|
||||
before do
|
||||
instance.add_order(sell_order)
|
||||
end
|
||||
|
||||
it "retuns all limit volumes" do
|
||||
expect(instance.to_a).to eq([
|
||||
Rex::Book::LimitVolumeTracker::LimitVolumeChange.new(
|
||||
:sell,
|
||||
100,
|
||||
250
|
||||
)
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#process_trade" do
|
||||
let(:trade) do
|
||||
Rex::Book::Trade.new(
|
||||
|
Loading…
Reference in New Issue
Block a user