Initial commit

This commit is contained in:
Yaser
2026-08-13 19:50:53 +03:30
commit 38084458fe
879 changed files with 95198 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
# frozen_string_literal: true
module Bench
module Injectors
class << self
def initialize_injector(config)
"#{self.name}/#{config[:injector]}"
.camelize
.constantize
.new(config)
end
end
class Base
attr_reader :config
def initialize(config)
@config = config
@number = config[:number].to_i
@step = config.fetch(:step, 1000).to_i
@markets = ::Market.where(id: config[:markets].split(',').map(&:squish).reject(&:blank?))
end
def generate!(members = nil)
@members = members || Member.all
@queue = Queue.new
Array.new(@number / @step) do
::Rails.logger.info { "Created orders: #{@queue.size}" }
ActiveRecord::Base.transaction do
Array.new(@step) do
create_order.tap { |o| @queue << o }
end
end
end
end
def pop
# Use non_blocking pop.
@queue.pop(true)
rescue ThreadError
# Return nil in case of empty queue.
nil
end
def size
@queue.size
end
def create_order
Order.new(construct_order)
.tap(&:round_amount_and_price)
.tap { |o| o.locked = o.origin_locked = o.compute_locked }
.tap { |o| o.hold_account!.lock_funds(o.locked) }
.tap(&:save)
end
end
end
end