bitex_bot 0.1.4 → 0.1.5

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.
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.2"
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 * 2)) / 100.0)
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
@@ -92,7 +92,7 @@ module BitexBot
92
92
  end
93
93
 
94
94
  def self.close_time_to_live
95
- 60
95
+ 30
96
96
  end
97
97
  end
98
98
  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 * 2)) / 100.0)
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]
@@ -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 1500 unless self.class.test_mode
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
- return if store.reload.hold?
116
- return if active_closing_flows?
117
- return if self.class.graceful_shutdown
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
- return if recent_buying && recent_selling
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
- return if store.usd_stop && total_usd <= store.usd_stop
151
- return if store.btc_stop && total_btc <= store.btc_stop
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 }
@@ -1,3 +1,3 @@
1
1
  module BitexBot
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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.0324'.to_d
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.0849000000001'.to_d
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 == '-16.075'.to_d
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.943548".to_d
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.1039519999999'.to_d
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.0156963'.to_d
161
- flow.usd_profit.should == '20.66616775'.to_d
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.1173".to_d
179
- flow.usd_profit.should == "20.10205".to_d
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 == '308.5'.to_d
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
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-08-18 00:00:00.000000000 Z
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.2
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.2
110
+ version: 0.1.3
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: mail
113
113
  requirement: !ruby/object:Gem::Requirement