lib/coss_bot/basic.rb in coss_bot-0.1.0 vs lib/coss_bot/basic.rb in coss_bot-0.1.1
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module CossBot
class Basic
attr_reader :exchange
attr_accessor :interval, :lot_size, :profit, :pair, :trade_limit
@@ -8,12 +10,13 @@
end
def call(&block)
validate_params!
loop do
- tick(&block)
- sleep(interval)
+ time = Benchmark.measure { tick(&block) }.real
+ wait_time = time > interval ? 0 : interval - time
+ sleep(wait_time)
end
end
private
@@ -24,8 +27,7 @@
lot_size.to_f.positive? &&
interval.to_i > 1
raise ArgumentError, 'Some params are invalid'
end
-
end
end