bitex_bot 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bitex_bot.gemspec +1 -1
- data/lib/bitex_bot/models/buy_closing_flow.rb +1 -1
- data/lib/bitex_bot/models/closing_flow.rb +1 -1
- data/lib/bitex_bot/models/sell_closing_flow.rb +1 -1
- data/lib/bitex_bot/robot.rb +29 -7
- data/lib/bitex_bot/version.rb +1 -1
- data/spec/models/buy_closing_flow_spec.rb +3 -3
- data/spec/models/sell_closing_flow_spec.rb +7 -7
- metadata +4 -4
data/bitex_bot.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "activesupport"
|
27
27
|
spec.add_dependency "sqlite3"
|
28
28
|
spec.add_dependency "bitstamp"
|
29
|
-
spec.add_dependency "bitex", "0.1.
|
29
|
+
spec.add_dependency "bitex", "0.1.3"
|
30
30
|
spec.add_dependency "mail"
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -26,7 +26,7 @@ module BitexBot
|
|
26
26
|
|
27
27
|
def get_next_price_and_quantity
|
28
28
|
closes = close_positions
|
29
|
-
next_price = desired_price - ((closes.count * (closes.count *
|
29
|
+
next_price = desired_price - ((closes.count * (closes.count * 3)) / 100.0)
|
30
30
|
next_quantity = quantity - closes.sum(:quantity)
|
31
31
|
[next_price, next_quantity]
|
32
32
|
end
|
@@ -27,7 +27,7 @@ module BitexBot
|
|
27
27
|
def get_next_price_and_quantity
|
28
28
|
closes = close_positions
|
29
29
|
next_price =
|
30
|
-
desired_price + ((closes.count * (closes.count *
|
30
|
+
desired_price + ((closes.count * (closes.count * 3)) / 100.0)
|
31
31
|
next_quantity =
|
32
32
|
((quantity * desired_price) - closes.sum(:amount)) / next_price
|
33
33
|
[next_price, next_quantity]
|
data/lib/bitex_bot/robot.rb
CHANGED
@@ -37,6 +37,8 @@ module BitexBot
|
|
37
37
|
next if start_time < cooldown_until
|
38
38
|
self.current_cooldowns = 0
|
39
39
|
bot.trade!
|
40
|
+
# This global sleep is so that we don't stress bitex too much.
|
41
|
+
sleep 0.1 unless test_mode
|
40
42
|
self.cooldown_until = start_time + current_cooldowns.seconds
|
41
43
|
end
|
42
44
|
end
|
@@ -75,7 +77,7 @@ module BitexBot
|
|
75
77
|
start_opening_flows_if_needed
|
76
78
|
rescue CannotCreateFlow => e
|
77
79
|
self.notify("#{e.message}:\n\n#{e.backtrace.join("\n")}")
|
78
|
-
sleep
|
80
|
+
sleep (60 * 3) unless self.class.test_mode
|
79
81
|
rescue StandardError => e
|
80
82
|
self.notify("#{e.message}:\n\n#{e.backtrace.join("\n")}")
|
81
83
|
sleep 60 unless self.class.test_mode
|
@@ -112,9 +114,20 @@ module BitexBot
|
|
112
114
|
end
|
113
115
|
|
114
116
|
def start_opening_flows_if_needed
|
115
|
-
|
116
|
-
|
117
|
-
|
117
|
+
if store.reload.hold?
|
118
|
+
BitexBot::Robot.logger.debug("Not placing new orders because of hold")
|
119
|
+
return
|
120
|
+
end
|
121
|
+
|
122
|
+
if active_closing_flows?
|
123
|
+
BitexBot::Robot.logger.debug("Not placing new orders, closing flows.")
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
if self.class.graceful_shutdown
|
128
|
+
BitexBot::Robot.logger.debug("Not placing new orders, shutting down.")
|
129
|
+
return
|
130
|
+
end
|
118
131
|
|
119
132
|
recent_buying, recent_selling =
|
120
133
|
[BuyOpeningFlow, SellOpeningFlow].collect do |kind|
|
@@ -122,7 +135,10 @@ module BitexBot
|
|
122
135
|
kind.active.where('created_at > ?', threshold).first
|
123
136
|
end
|
124
137
|
|
125
|
-
|
138
|
+
if recent_buying && recent_selling
|
139
|
+
BitexBot::Robot.logger.debug("Not placing new orders, recent ones exist.")
|
140
|
+
return
|
141
|
+
end
|
126
142
|
|
127
143
|
balances = with_cooldown{ Bitstamp.balance }
|
128
144
|
profile = Bitex::Profile.get
|
@@ -147,8 +163,14 @@ module BitexBot
|
|
147
163
|
end
|
148
164
|
end
|
149
165
|
|
150
|
-
|
151
|
-
|
166
|
+
if store.usd_stop && total_usd <= store.usd_stop
|
167
|
+
BitexBot::Robot.logger.debug("Not placing new orders, USD target not met")
|
168
|
+
return
|
169
|
+
end
|
170
|
+
if store.btc_stop && total_btc <= store.btc_stop
|
171
|
+
BitexBot::Robot.logger.debug("Not placing new orders, BTC target not met")
|
172
|
+
return
|
173
|
+
end
|
152
174
|
|
153
175
|
order_book = with_cooldown{ Bitstamp.order_book }
|
154
176
|
transactions = with_cooldown{ Bitstamp.transactions }
|
data/lib/bitex_bot/version.rb
CHANGED
@@ -130,12 +130,12 @@ describe BitexBot::BuyClosingFlow do
|
|
130
130
|
stub_bitstamp_orders_into_transactions
|
131
131
|
flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
|
132
132
|
flow.close_positions.last.tap do |close|
|
133
|
-
close.amount.should == '312.
|
133
|
+
close.amount.should == '312.02235'.to_d
|
134
134
|
close.quantity.should == 1.005
|
135
135
|
end
|
136
136
|
flow.should be_done
|
137
137
|
flow.btc_profit.should == 0
|
138
|
-
flow.usd_profit.should == '20.
|
138
|
+
flow.usd_profit.should == '20.07485'.to_d
|
139
139
|
end
|
140
140
|
|
141
141
|
it "does not retry for an amount less than minimum_for_closing" do
|
@@ -168,7 +168,7 @@ describe BitexBot::BuyClosingFlow do
|
|
168
168
|
|
169
169
|
flow.reload.should be_done
|
170
170
|
flow.btc_profit.should == 0
|
171
|
-
flow.usd_profit.should == '-
|
171
|
+
flow.usd_profit.should == '-34.165'.to_d
|
172
172
|
end
|
173
173
|
end
|
174
174
|
end
|
@@ -132,12 +132,12 @@ describe BitexBot::SellClosingFlow do
|
|
132
132
|
stub_bitstamp_orders_into_transactions
|
133
133
|
flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
|
134
134
|
flow.close_positions.last.tap do |close|
|
135
|
-
close.amount.should == "291.
|
135
|
+
close.amount.should == "291.953597".to_d
|
136
136
|
close.quantity.should == '1.0049'.to_d
|
137
137
|
end
|
138
138
|
flow.should be_done
|
139
139
|
flow.btc_profit.should == '-0.0001'.to_d
|
140
|
-
flow.usd_profit.should == '20.
|
140
|
+
flow.usd_profit.should == '20.093903'.to_d
|
141
141
|
|
142
142
|
end
|
143
143
|
|
@@ -157,8 +157,8 @@ describe BitexBot::SellClosingFlow do
|
|
157
157
|
end.not_to change{ BitexBot::CloseSell.count }
|
158
158
|
|
159
159
|
flow.should be_done
|
160
|
-
flow.btc_profit.should == '-0.
|
161
|
-
flow.usd_profit.should == '20.
|
160
|
+
flow.btc_profit.should == '-0.0224895'.to_d
|
161
|
+
flow.usd_profit.should == '20.66566825'.to_d
|
162
162
|
end
|
163
163
|
|
164
164
|
it "can lose BTC if price had to be raised dramatically" do
|
@@ -175,11 +175,11 @@ describe BitexBot::SellClosingFlow do
|
|
175
175
|
flow.sync_closed_positions(Bitstamp.orders.all, Bitstamp.user_transactions.all)
|
176
176
|
|
177
177
|
flow.reload.should be_done
|
178
|
-
flow.btc_profit.should == "-0.
|
179
|
-
flow.usd_profit.should == "20.
|
178
|
+
flow.btc_profit.should == "-0.1709".to_d
|
179
|
+
flow.usd_profit.should == "20.08575".to_d
|
180
180
|
close = flow.close_positions.last
|
181
181
|
(close.amount / close.quantity)
|
182
|
-
.should == '
|
182
|
+
.should == '317.5'.to_d
|
183
183
|
end
|
184
184
|
end
|
185
185
|
end
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: settingslogic
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
requirements:
|
100
100
|
- - '='
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 0.1.
|
102
|
+
version: 0.1.3
|
103
103
|
type: :runtime
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.1.
|
110
|
+
version: 0.1.3
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: mail
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|