coss_bot 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9ef19ac8c7758772a524ab6ba485b4781dcfa747e1f2c0258f31161d4e82a86
4
- data.tar.gz: 24e8458f0b3aaef39acbb713ce0d39ae700a7b100921fd8082b91c5e7d7f906e
3
+ metadata.gz: 633ffb47e93673f3a89ed285b392f115dbfbe82669bdc6d6b427f33261264840
4
+ data.tar.gz: a880886a0b86a88274800ce7e7d6d52b1c76a1dc5f06ee4ee4a694cde9fa1ff3
5
5
  SHA512:
6
- metadata.gz: 18cbac675cc8db28442f7cffd9e9a1520878d1eb5465a40457a0edb59d7fdf8aff07ebd8c4e2ce1bf19f21f8297520314fdc156601feef36db32dcee32bb0ee7
7
- data.tar.gz: bdf5bfc7a759babcb4f1513c1b93d011b832ad2b5470280831e8b8555ed13203f49421c0197f44118c011dcf31a1364688a0184bf938caeb926c65c70b8e4c3f
6
+ metadata.gz: b1b854059729b64a63cad0345c6551bda074f2022d1e48d96a43f0992ef226ca1e8f7e0e3aa7565275503e2220a92d07c6a525c60a091b89dedbd66d8d2d79f4
7
+ data.tar.gz: 443b13f271c6ee55256cf302d31fcbd04745fb623c04bc68c9358e34fb6ca6e59e54bc91902a5f69d911d7f6696a918dcad665b461ef7c856affa10f88761de5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coss_bot (0.1.2)
4
+ coss_bot (0.1.3)
5
5
  coss_api_ruby_wrapper (= 0.1.1)
6
6
 
7
7
  GEM
data/lib/coss_bot.rb CHANGED
@@ -4,6 +4,7 @@ require 'coss_bot/version'
4
4
  require 'coss_bot/basic'
5
5
  require 'coss_bot/buy_low_sell_high'
6
6
  require 'benchmark'
7
+ require 'logger'
7
8
  require 'coss_api_ruby_wrapper'
8
9
 
9
10
  module CossBot
@@ -3,10 +3,11 @@
3
3
  module CossBot
4
4
  class Basic
5
5
  attr_reader :exchange
6
- attr_accessor :interval, :lot_size, :profit, :pair, :trade_limit
6
+ attr_accessor :interval, :lot_size, :profit, :pair, :trade_limit, :logger
7
7
 
8
- def initialize(public_key:, private_key:)
8
+ def initialize(public_key:, private_key:, logger: Logger.new(STDOUT))
9
9
  @exchange = CossApiRubyWrapper::Exchange.new(public_key: public_key, private_key: private_key)
10
+ @logger = logger
10
11
  end
11
12
 
12
13
  def call(&block)
@@ -5,22 +5,31 @@ module CossBot
5
5
  private
6
6
 
7
7
  def tick
8
- puts '=== Start of trading cycle ==='
8
+ logger.info('=== Start of trading cycle ===')
9
9
  balances = exchange.account_balances
10
10
  currency_to_sell = pair.split('_').last
11
11
  current_balance = balances.detect { |c| c['currency_code'] == currency_to_sell }['available'].to_f
12
12
  pair_depth = exchange.pair_depth(pair)
13
13
  current_price = pair_depth['asks'].first.first.to_f
14
- return if current_balance <= trade_limit.to_f
15
- return if current_balance <= current_price * lot_size
16
14
 
17
- price_with_profit = (current_price + (current_price / 100 * profit.to_f)).round(6)
18
- puts "Placing BUY order for #{current_price}. Lot size: #{lot_size}"
19
- buy_response = exchange.place_limit_order(pair, current_price, 'BUY', lot_size)
20
- puts "Placing SELL order for #{price_with_profit}. Lot size: #{lot_size}"
21
- sell_response = exchange.place_limit_order(pair, price_with_profit, 'SELL', lot_size)
22
- yield(buy_response, sell_response)
23
- puts '=== End of trading cycle ==='
15
+ if current_balance <= trade_limit.to_f
16
+ yield(nil, nil, { status: 0, message: 'Current balance <= trade limit' })
17
+ elsif current_balance <= current_price * lot_size
18
+ yield(nil, nil, { status: 0, message: 'Current balance <= current_price * lot_size' })
19
+ else
20
+ price_with_profit = (current_price + (current_price / 100 * profit.to_f)).round(6)
21
+ logger.info("Placing BUY order for #{current_price}. Lot size: #{lot_size}")
22
+ buy_response = exchange.place_limit_order(pair, current_price, 'BUY', lot_size)
23
+ logger.info("Placing SELL order for #{price_with_profit}. Lot size: #{lot_size}")
24
+ sell_response = exchange.place_limit_order(pair, price_with_profit, 'SELL', lot_size)
25
+ logger.info('=== End of trading cycle ===')
26
+
27
+ error = {}
28
+ error[:buy] = buy_response if buy_response[:status].present?
29
+ error[:sell] = sell_response if sell_response[:status].present?
30
+
31
+ yield(buy_response, sell_response, error)
32
+ end
24
33
  end
25
34
  end
26
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CossBot
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coss_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Vsk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-21 00:00:00.000000000 Z
11
+ date: 2018-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coss_api_ruby_wrapper