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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/coss_bot.rb +1 -0
- data/lib/coss_bot/basic.rb +3 -2
- data/lib/coss_bot/buy_low_sell_high.rb +19 -10
- data/lib/coss_bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 633ffb47e93673f3a89ed285b392f115dbfbe82669bdc6d6b427f33261264840
|
4
|
+
data.tar.gz: a880886a0b86a88274800ce7e7d6d52b1c76a1dc5f06ee4ee4a694cde9fa1ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1b854059729b64a63cad0345c6551bda074f2022d1e48d96a43f0992ef226ca1e8f7e0e3aa7565275503e2220a92d07c6a525c60a091b89dedbd66d8d2d79f4
|
7
|
+
data.tar.gz: 443b13f271c6ee55256cf302d31fcbd04745fb623c04bc68c9358e34fb6ca6e59e54bc91902a5f69d911d7f6696a918dcad665b461ef7c856affa10f88761de5
|
data/Gemfile.lock
CHANGED
data/lib/coss_bot.rb
CHANGED
data/lib/coss_bot/basic.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
data/lib/coss_bot/version.rb
CHANGED
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.
|
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-
|
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
|