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,67 @@
require 'faraday'
require 'thread/pool'
require 'progress_bar'
require "#{Rails.root}/lib/api_bench.rb"
yml_data = YAML.load_file("#{Rails.root}/config/bench/api_bench.yml")
namespace :api_benchmark do
desc 'create random request for order creation and do trading'
task :random_fire do
bar = ProgressBar.new(yml_data.dig('order_count'), :percentage, :bar, :elapsed, :eta, :rate)
pool = Thread.pool(5)
creator = ApiBench.new
start_time = Time.now
yml_data.dig('order_count').times do |_i|
pool.process do
price = rand(1000..1500)
side = price.odd? ? 'sell' : 'buy'
creator.create_order(yml_data.dig('base_url'),
'btcusd',
side,
rand.round(2),
yml_data.dig('server_token'),
'limit',
price)
bar.increment!
end
end
pool.shutdown
puts 'elapsed_time:'
puts Time.now - start_time
end
desc 'create one big sell request for support a lot of small buy order for trading'
task :direct_fire do
bar = ProgressBar.new(yml_data.dig('order_count'), :percentage, :bar, :elapsed, :eta, :rate)
pool = Thread.pool(5)
creator = ApiBench.new
creator.create_order(yml_data.dig('base_url'),
'btcusd',
'sell',
yml_data.dig('order_count'),
yml_data.dig('server_token'),
'limit',
1000)
# sleep(1)
start_time = Time.now
yml_data.dig('order_count').times do |_i|
pool.process do
price = rand(1001..1500)
creator.create_order(yml_data.dig('base_url'),
'btcusd',
'buy',
1,
yml_data.dig('server_token'),
'limit',
price)
bar.increment!
end
end
pool.shutdown
puts 'elapsed_time:'
puts Time.now - start_time
end
end