lib/wash_trade.rb in SimBot-0.1.8 vs lib/wash_trade.rb in SimBot-0.1.10
- old
+ new
@@ -2,10 +2,11 @@
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)
+ @g_count = 1
@api = api
@market = market
@freq = freq
Process.fork do
Process.daemon(true)
@@ -19,19 +20,29 @@
def start
count = 0
loop do
vol = rand(0.2...3)
- price = Utils.quote(@market)
+ price = move_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
rescue ::StandardError => e
puts e
+ end
+
+ def move_price
+ range = 1.015
+ if @g_count > 100
+ range = rand(1.005...1.010)
+ @g_count = 0
+ end
+ @g_count += 1
+ Utils.quote(@market) * rand(1.003...range)
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|
\ No newline at end of file