bitex_bot 0.5.1 → 0.6.0

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
  SHA1:
3
- metadata.gz: 0341a8eb9da405634fc53dd2165a30c31f46674d
4
- data.tar.gz: 6a468573664f6efc3a00e7811b31ce658e9dc11c
3
+ metadata.gz: 042de027f9e4945015bb3dadb4eb0791ae088d1c
4
+ data.tar.gz: 5ac5f3a68839f43827023b79c979204856946838
5
5
  SHA512:
6
- metadata.gz: 4529d05e2353bcbf5a91d7ad05bfa261a83cb97bcf4df9d36d235508d31b64cf5ffa66953984095ba72a206c183dd6bec25955f9a648190535f6c967a4d4255f
7
- data.tar.gz: 280af9b62f157ffaa0932b8781fcfcb06bfdb8dd322b41e5a6014f362ef37d991b0a1e2358ad8b51163090c3db287b9aeacfc2da1cba8cc31d495f3731d6dca7
6
+ metadata.gz: d0f9192ae1bc2469b425a71b0f497cde7500fd980e6ff1744932921bec1c40094bfaea1e6a0d5f371439f9a95bab4082877b79b234c3da5ae7c42dec8bd4f9b3
7
+ data.tar.gz: f8904fb9df76e8eed734a11423afc1c15bc509bf2e49abe0230b2d6b9de325c037e334d1704fc3e97ce8bc7d6226cb974df55558eeec9425a9739b72d8fe8898
@@ -92,18 +92,16 @@ module BitexBot
92
92
  unless ActiveRecord::Base.connection.table_exists?('stores')
93
93
  create_table :stores, force: true do |t|
94
94
  t.decimal :maker_crypto, precision: 20, scale: 8
95
- t.decimal :maker_crypto_stop, precision: 20, scale: 8
96
- t.decimal :maker_crypto_warning, precision: 20, scale: 8
97
95
  t.decimal :maker_fiat, precision: 20, scale: 8
98
- t.decimal :maker_fiat_stop, precision: 20, scale: 8
99
- t.decimal :maker_fiat_warning, precision: 20, scale: 8
100
96
 
101
97
  t.decimal :taker_crypto, precision: 20, scale: 8
102
- t.decimal :taker_crypto_stop, precision: 20, scale: 8
103
- t.decimal :taker_crypto_warning, precision: 20, scale: 8
104
98
  t.decimal :taker_fiat, precision: 20, scale: 8
105
- t.decimal :taker_fiat_stop, precision: 20, scale: 8
106
- t.decimal :taker_fiat_warning, precision: 20, scale: 8
99
+
100
+ t.decimal :crypto_stop, precision: 20, scale: 8
101
+ t.decimal :crypto_warning, precision: 20, scale: 8
102
+
103
+ t.decimal :fiat_stop, precision: 20, scale: 8
104
+ t.decimal :fiat_warning, precision: 20, scale: 8
107
105
 
108
106
  t.decimal :buying_amount_to_spend_per_order, precision: 20, scale: 8
109
107
  t.decimal :buying_fx_rate, precision: 20, scale: 8
@@ -72,8 +72,6 @@ class BitstampApiWrapper < ApiWrapper
72
72
  raise ApiWrapperError, "Bitstamp user_transactions failed: #{e.message}"
73
73
  end
74
74
 
75
- private_class_method
76
-
77
75
  # {
78
76
  # btc_reserved: '0', btc_available: '0', btc_balance: '0',
79
77
  # usd_reserved: '1.02, usd_available: '6952.05', usd_balance: '6953.07',
@@ -58,8 +58,6 @@ class ItbitApiWrapper < ApiWrapper
58
58
  []
59
59
  end
60
60
 
61
- private_class_method
62
-
63
61
  # [
64
62
  # { total_balance: 0.2e2, currency: :usd, available_balance: 0.1e2 },
65
63
  # { total_balance: 0.0, currency: :xbt, available_balance: 0.0 },
@@ -55,8 +55,6 @@ class KrakenApiWrapper < ApiWrapper
55
55
  []
56
56
  end
57
57
 
58
- private_class_method
59
-
60
58
  # { ZEUR: '1433.0939', XXBT: '0.0000000000', 'XETH': '99.7497224800' }
61
59
  def self.balance_summary_parser(balances)
62
60
  open_orders = KrakenOrder.open
@@ -69,8 +69,6 @@ module BitexBot
69
69
  end
70
70
  end
71
71
 
72
- private_class_method
73
-
74
72
  def self.start_robot
75
73
  setup
76
74
  log(:info, 'Loading trading robot, ctrl+c *once* to exit gracefully.')
@@ -183,10 +181,8 @@ module BitexBot
183
181
 
184
182
  check_balance_warning if expired_last_warning?
185
183
 
186
- return log(:debug, "Not placing new orders, #{Settings.quote} target not met") if alert?(:maker, :fiat, :stop)
187
- return log(:debug, "Not placing new orders, #{Settings.base} target not met") if alert?(:maker, :crypto, :stop)
188
- return log(:debug, 'Not placing new orders, USD target not met') if alert?(:taker, :fiat, :stop)
189
- return log(:debug, "Not placing new orders, #{Settings.quote} target not met") if alert?(:taker, :crypto, :stop)
184
+ return log(:debug, "Not placing new orders, #{Settings.quote} target not met") if alert?(:fiat, :stop)
185
+ return log(:debug, "Not placing new orders, #{Settings.base} target not met") if alert?(:crypto, :stop)
190
186
 
191
187
  order_book = with_cooldown { Robot.taker.order_book }
192
188
  transactions = with_cooldown { Robot.taker.transactions }
@@ -218,18 +214,19 @@ module BitexBot
218
214
  store.last_warning.nil? || store.last_warning < 30.minutes.ago
219
215
  end
220
216
 
221
- # rubocop:disable Metrics/AbcSize
222
217
  def check_balance_warning
223
- notify_balance_warning(Settings.base, store.maker_crypto, store.maker_crypto_warning) if alert?(:maker, :crypto, :warning)
224
- notify_balance_warning(Settings.quote, store.maker_fiat, store.maker_fiat_warning) if alert?(:maker, :fiat, :warning)
225
- notify_balance_warning(Settings.base, store.taker_crypto, store.taker_crypto_warning) if alert?(:taker, :crypto, :warning)
226
- notify_balance_warning(:usd, store.taker_fiat, store.taker_fiat_warning) if alert?(:taker, :fiat, :warning)
218
+ notify_balance_warning(Settings.base, balance(:crypto), store.crypto_warning) if alert?(:crypto, :warning)
219
+ notify_balance_warning(Settings.quote, balance(:fiat), store.fiat_warning) if alert?(:fiat, :warning)
220
+ end
221
+
222
+ def alert?(currency, flag)
223
+ return unless store.send("#{currency}_#{flag}").present?
224
+ balance(currency) <= store.send("#{currency}_#{flag}")
227
225
  end
228
- # rubocop:enable Metrics/AbcSize
229
226
 
230
- def alert?(market, currency, flag)
231
- return unless store.send("#{market}_#{currency}_#{flag}").present?
232
- store.send("#{market}_#{currency}") <= store.send("#{market}_#{currency}_#{flag}")
227
+ def balance(currency)
228
+ fx_rate = currency == :fiat ? Settings.buying_fx_rate : 1
229
+ store.send("maker_#{currency}") / fx_rate + store.send("taker_#{currency}")
233
230
  end
234
231
 
235
232
  def notify_balance_warning(currency, amount, warning_amount)
@@ -1,3 +1,3 @@
1
1
  module BitexBot
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -132,24 +132,12 @@ describe BitexBot::Robot do
132
132
  other_bot.store.update(hold: true)
133
133
  end
134
134
 
135
- context 'maker' do
136
- it 'crypto stop is reached' do
137
- other_bot.store.update(maker_crypto_stop: 30)
138
- end
139
-
140
- it 'fiat stop is reached' do
141
- other_bot.store.update(maker_fiat_stop: 30)
142
- end
135
+ it 'crypto stop is reached' do
136
+ other_bot.store.update(crypto_stop: 30)
143
137
  end
144
138
 
145
- context 'taker' do
146
- it 'crypto stop is reached' do
147
- other_bot.store.update(taker_crypto_stop: 30)
148
- end
149
-
150
- it 'fiat stop is reached' do
151
- other_bot.store.update(taker_fiat_stop: 30)
152
- end
139
+ it 'fiat stop is reached' do
140
+ other_bot.store.update(fiat_stop: 30)
153
141
  end
154
142
  end
155
143
 
@@ -166,7 +154,7 @@ describe BitexBot::Robot do
166
154
  })
167
155
  Bitex::Trade.stub(all: [])
168
156
  stub_bitstamp_api_wrapper_balance(100, 100)
169
- other_bot.store.update(maker_crypto_warning: 0, taker_crypto_warning: 0, maker_fiat_warning: 0, taker_fiat_warning: 0)
157
+ other_bot.store.update(crypto_warning: 0, fiat_warning: 0)
170
158
  end
171
159
 
172
160
  after(:each) do
@@ -181,26 +169,14 @@ describe BitexBot::Robot do
181
169
  expect { bot.trade! }.to change { Mail::TestMailer.deliveries.count }.by(1)
182
170
  end
183
171
 
184
- let(:other_bot) { described_class.new }
185
-
186
- context 'maker' do
187
- it 'crypto warning is reached' do
188
- other_bot.store.update(maker_crypto_warning: 100)
189
- end
172
+ let(:other_bot) { described_class.new }
190
173
 
191
- it 'fiat warning is reached' do
192
- other_bot.store.update(maker_fiat_warning: 100)
193
- end
174
+ it 'crypto warning is reached' do
175
+ other_bot.store.update(crypto_warning: 1_000)
194
176
  end
195
177
 
196
- context 'taker' do
197
- it 'crypto warning is reached' do
198
- other_bot.store.update(taker_crypto_warning: 100)
199
- end
200
-
201
- it 'fiat warning is reached' do
202
- other_bot.store.update(taker_fiat_warning: 100)
203
- end
178
+ it 'fiat warning is reached' do
179
+ other_bot.store.update(fiat_warning: 1_000)
204
180
  end
205
181
  end
206
182
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitex_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nubis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-07-06 00:00:00.000000000 Z
12
+ date: 2018-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord