Class: Deamons::WashTrade
- Inherits:
-
Object
- Object
- Deamons::WashTrade
- Defined in:
- lib/Deamons/wash_trade.rb
Overview
Simple process to add wash trades to a market in order to simulate trade matching for QA and dev
Instance Method Summary collapse
-
#initialize(api, market, freq) ⇒ WashTrade
constructor
A new instance of WashTrade.
-
#redirect(outfile, errfile) ⇒ Object
Send stdout and stderr to log files for the child process.
- #start ⇒ Object
-
#write_pid_file(pid, pidfile) ⇒ Object
Attempts to write the pid of the forked process to the pid file.
Constructor Details
#initialize(api, market, freq) ⇒ WashTrade
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/Deamons/wash_trade.rb', line 6 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 |
Instance Method Details
#redirect(outfile, errfile) ⇒ Object
Send stdout and stderr to log files for the child process
45 46 47 48 49 50 51 52 |
# File 'lib/Deamons/wash_trade.rb', line 45 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 |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/Deamons/wash_trade.rb', line 20 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 |
#write_pid_file(pid, pidfile) ⇒ Object
Attempts to write the pid of the forked process to the pid file.
35 36 37 38 39 40 41 42 |
# File 'lib/Deamons/wash_trade.rb', line 35 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 |