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 +4 -4
- data/lib/bitex_bot/database.rb +6 -8
- data/lib/bitex_bot/models/api_wrappers/bitstamp/bitstamp_api_wrapper.rb +0 -2
- data/lib/bitex_bot/models/api_wrappers/itbit/itbit_api_wrapper.rb +0 -2
- data/lib/bitex_bot/models/api_wrappers/kraken/kraken_api_wrapper.rb +0 -2
- data/lib/bitex_bot/robot.rb +12 -15
- data/lib/bitex_bot/version.rb +1 -1
- data/spec/models/robot_spec.rb +10 -34
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042de027f9e4945015bb3dadb4eb0791ae088d1c
|
4
|
+
data.tar.gz: 5ac5f3a68839f43827023b79c979204856946838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f9192ae1bc2469b425a71b0f497cde7500fd980e6ff1744932921bec1c40094bfaea1e6a0d5f371439f9a95bab4082877b79b234c3da5ae7c42dec8bd4f9b3
|
7
|
+
data.tar.gz: f8904fb9df76e8eed734a11423afc1c15bc509bf2e49abe0230b2d6b9de325c037e334d1704fc3e97ce8bc7d6226cb974df55558eeec9425a9739b72d8fe8898
|
data/lib/bitex_bot/database.rb
CHANGED
@@ -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
|
-
|
106
|
-
t.decimal :
|
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',
|
data/lib/bitex_bot/robot.rb
CHANGED
@@ -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?(:
|
187
|
-
return log(:debug, "Not placing new orders, #{Settings.base} target not met") if alert?(:
|
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,
|
224
|
-
notify_balance_warning(Settings.quote,
|
225
|
-
|
226
|
-
|
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
|
231
|
-
|
232
|
-
store.send("#{
|
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)
|
data/lib/bitex_bot/version.rb
CHANGED
data/spec/models/robot_spec.rb
CHANGED
@@ -132,24 +132,12 @@ describe BitexBot::Robot do
|
|
132
132
|
other_bot.store.update(hold: true)
|
133
133
|
end
|
134
134
|
|
135
|
-
|
136
|
-
|
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
|
-
|
146
|
-
|
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(
|
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
|
-
|
192
|
-
|
193
|
-
end
|
174
|
+
it 'crypto warning is reached' do
|
175
|
+
other_bot.store.update(crypto_warning: 1_000)
|
194
176
|
end
|
195
177
|
|
196
|
-
|
197
|
-
|
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.
|
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-
|
12
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|