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,37 @@
# frozen_string_literal: true
module Bench
module Injectors
class Bitfinex < Base
def initialize(config)
super
if config[:data_load_path].present?
@data = YAML.load_file(Rails.root.join(config[:data_load_path]))
@index = 0
end
end
private
def construct_order
@index = 0 if @data[@index].blank?
order_data = @data[@index]
price = order_data[1]
amount = order_data[2]
market = @markets.sample
type = amount > 0 ? 'OrderBid' : 'OrderAsk'
@index += 1
{ type: type,
state: Order::WAIT,
member: @members.sample,
market: market,
ask: market.base_unit,
bid: market.quote_unit,
ord_type: :limit,
price: price,
volume: amount.abs }
end
end
end
end

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
module Bench
module Injectors
class Dummy < Base
extend Memoist
def initialize(config)
super
config.reverse_merge!(default_config)
%i[min_volume max_volume min_price max_price].each do |var|
instance_variable_set(:"@#{var}", config[var])
end
end
def construct_order(memberes = nil, order_type = nil)
market = @markets.sample
@members = memberes if memberes.present?
type = order_type || config.fetch(:side) { %w[OrderBid OrderAsk].sample }
{ type: type,
state: Order::PENDING,
member: @members.sample,
market: market,
ask: market.base_unit,
bid: market.quote_unit,
ord_type: :limit,
price: config.fetch(:price) { rand(@min_price..@max_price) },
volume: rand(@min_volume..@max_volume) }
end
private
def default_config
{ min_volume: 0.1,
max_volume: 1,
min_price: 0.5,
max_price: 2 }
end
memoize :default_config
end
end
end