Sha256: a82d9498117d245511e387ca31a2969e5b24ea1756ffbc6fb6b0b3cbf826aaab

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module CossBot
  class BuyLowSellHigh < Basic

    private

    def tick
      puts '=== Start of trading cycle ==='
      balances = exchange.account_balances
      currency_to_sell = pair.split('_').last
      current_balance = balances.detect { |c| c['currency_code'] == currency_to_sell }['available'].to_f
      pair_depth = exchange.pair_depth(pair)
      current_price = pair_depth['asks'].first.first.to_f
      return if current_balance <= trade_limit.to_f
      return if current_balance <= current_price * lot_size

      price_with_profit = (current_price + (current_price / 100 * profit)).round(6)
      puts "Placing BUY order for #{current_price}. Lot size: #{lot_size}"
      exchange.place_limit_order(pair, current_price, 'BUY', lot_size)
      puts "Placing SELL order for #{price_with_profit}. Lot size: #{lot_size}"
      exchange.place_limit_order(pair, price_with_profit, 'SELL', lot_size)
      yield(current_price, price_with_profit)
      puts '=== End of trading cycle ==='
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coss_bot-0.1.0 lib/coss_bot/buy_low_sell_high.rb