Sha256: 7ac6249fa71f84cc14a7b65ac385f744f97ac471cc6cc88cdfafb9fbc428a594
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
module Deamons # Simple process to add wash trades to a market in order to simulate trade matching for QA and dev class WashTrade require 'utils' def initialize(api, market, freq) @api = api @market = market @freq = freq Process.fork do Process.daemon(true) pid = Process.pid redirect("#{pid}.outfile","#{pid}.errfile") write_pid_file(pid, "#{pid}.pid") start end puts "SimBot started on #{market} @ freq #{freq}" end def start count = 0 loop do vol = rand(1...10) price = Utils.get_bchbtc_price @api.post_order(@market, price, vol, 'sell') delay = (1.00 / @freq) sleep(delay) @api.post_order(@market, price, vol, 'buy') puts "order ##{count} placed" count += 1 end end # Attempts to write the pid of the forked process to the pid file. def write_pid_file(pid, pidfile) File.open pidfile, "w" do |f| f.write pid end rescue ::Exception => e $stderr.puts "While writing the PID to file, unexpected #{e.class}: #{e}" Process.kill "HUP", pid end # Send stdout and stderr to log files for the child process def redirect(outfile, errfile) $stdin.reopen '/dev/null' out = File.new outfile, "a" err = File.new errfile, "a" $stdout.reopen out $stderr.reopen err $stdout.sync = $stderr.sync = true end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
SimBot-0.1.6 | lib/wash_trade.rb |
SimBot-0.1.5 | lib/Deamons/wash_trade.rb |