Sha256: f5f788900219425c738566db8bc9d9df82e30deef36c3dc99653ade3ed7b4c07

Contents?: true

Size: 898 Bytes

Versions: 7

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

module CossBot
  class Basic
    attr_reader :exchange
    attr_accessor :interval, :lot_size, :profit, :pair, :trade_limit, :logger

    def initialize(public_key:, private_key:, logger: Logger.new(STDOUT))
      @exchange = CossApiRubyWrapper::Exchange.new(public_key: public_key, private_key: private_key)
      @logger = logger
    end

    def call(&block)
      validate_params!
      loop do
        time = Benchmark.measure { tick(&block) }.real
        wait_time = time > interval ? 0 : interval - time
        sleep(wait_time)
      end
    end

    private

    def validate_params!
      return if !trade_limit.nil? &&
                pair.to_s =~ /\A\w+_\w+\Z/ &&
                profit.to_f.positive? &&
                lot_size.to_f.positive? &&
                interval.to_i > 1

      raise ArgumentError, 'Some params are invalid'
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coss_bot-0.1.9 lib/coss_bot/basic.rb
coss_bot-0.1.8 lib/coss_bot/basic.rb
coss_bot-0.1.7 lib/coss_bot/basic.rb
coss_bot-0.1.6 lib/coss_bot/basic.rb
coss_bot-0.1.5 lib/coss_bot/basic.rb
coss_bot-0.1.4 lib/coss_bot/basic.rb
coss_bot-0.1.3 lib/coss_bot/basic.rb