bitex_bot 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ec3db346eb39cba7b7760969b32205f778bdf89
4
- data.tar.gz: 4117298e216bc463273d303ea82b0d4f549958af
3
+ metadata.gz: 0341a8eb9da405634fc53dd2165a30c31f46674d
4
+ data.tar.gz: 6a468573664f6efc3a00e7811b31ce658e9dc11c
5
5
  SHA512:
6
- metadata.gz: b73d5b0ea727152b76ab15052ca7501fa5beae556d6946ddb5d2e0f26e1d76a93d86210283488a57e44c04c2b4ed36fe993a297debc39bb3234e657a90a570dd
7
- data.tar.gz: 2958fc14136fb77f4b578bda495d27050a6bc14886f78fc784fda7dc2ab00703bbbe5fb55860214a5c0ec21374335163da2aa760c0dfbe9f755d10c30ce4aca1
6
+ metadata.gz: 4529d05e2353bcbf5a91d7ad05bfa261a83cb97bcf4df9d36d235508d31b64cf5ffa66953984095ba72a206c183dd6bec25955f9a648190535f6c967a4d4255f
7
+ data.tar.gz: 280af9b62f157ffaa0932b8781fcfcb06bfdb8dd322b41e5a6014f362ef37d991b0a1e2358ad8b51163090c3db287b9aeacfc2da1cba8cc31d495f3731d6dca7
@@ -49,8 +49,8 @@ module BitexBot
49
49
  # end: sought_transaction helpers
50
50
 
51
51
  # create_for_market helpers
52
- def self.maker_price(bitcoin_to_resell)
53
- value_to_use / bitcoin_to_resell * (1 - profit / 100)
52
+ def self.maker_price(crypto_to_resell)
53
+ value_to_use / crypto_to_resell * (1 - profit / 100)
54
54
  end
55
55
 
56
56
  def self.order_class
@@ -62,11 +62,11 @@ module BitexBot
62
62
  end
63
63
 
64
64
  def self.remote_value_to_use(value_to_use_needed, safest_price)
65
- value_to_use_needed / safest_price
65
+ (value_to_use_needed / fx_rate) / safest_price
66
66
  end
67
67
 
68
- def self.safest_price(transactions, order_book, dollars_to_use)
69
- OrderBookSimulator.run(Settings.time_to_live, transactions, order_book, dollars_to_use, nil)
68
+ def self.safest_price(transactions, order_book, amount_to_use)
69
+ OrderBookSimulator.run(Settings.time_to_live, transactions, order_book, amount_to_use / fx_rate, nil)
70
70
  end
71
71
 
72
72
  def self.value_to_use
@@ -36,7 +36,7 @@ module BitexBot
36
36
  raise CannotCreateFlow, "Needed #{remote_value} but you only have #{remote_balance}" unless
37
37
  enough_remote_funds?(remote_balance, remote_value)
38
38
 
39
- bitex_price = maker_price(remote_value) * fx_rate
39
+ bitex_price = maker_price(remote_value)
40
40
  order = create_order!(bitex_price)
41
41
  raise CannotCreateFlow, "You need to have #{value_to_use} on bitex to place this #{order_class.name}." unless
42
42
  enough_funds?(order)
@@ -28,10 +28,11 @@ module BitexBot
28
28
 
29
29
  # An order may be partially or completely skipped due to volatility.
30
30
  if to_skip.positive?
31
- dropped = [quantity, to_skip].min
32
- to_skip -= dropped
33
- quantity -= dropped
34
- Robot.log(:debug, "Skipped #{dropped} BTC @ $#{price}")
31
+ [quantity, to_skip].min.tap do |dropped|
32
+ to_skip -= dropped
33
+ quantity -= dropped
34
+ Robot.log(:debug, "Skipped #{dropped} BTC @ $#{price}")
35
+ end
35
36
  next if quantity.zero?
36
37
  end
37
38
 
@@ -54,7 +55,7 @@ module BitexBot
54
55
  threshold = transactions.first.timestamp - volatility
55
56
  transactions
56
57
  .select { |t| t.timestamp > threshold }
57
- .map { |t| t.amount.to_d }
58
+ .map(&:amount)
58
59
  .sum
59
60
  end
60
61
 
@@ -63,8 +64,7 @@ module BitexBot
63
64
  end
64
65
 
65
66
  def self.best_price(currency, target, price)
66
- Robot.log(:debug, "Best price to get #{currency} #{target} is $#{price}")
67
- price
67
+ price.tap { Robot.log(:debug, "Best price to get #{currency} #{target} is $#{price}") }
68
68
  end
69
69
 
70
70
  # end: private class methods
@@ -14,6 +14,7 @@ module BitexBot
14
14
  # Start a workflow for selling bitcoin on bitex and buying on the other exchange. The quantity to be sold on bitex is
15
15
  # retrieved from Settings, if there is not enough BTC on bitex or USD on the other exchange then no order will be placed and
16
16
  # an exception will be raised instead.
17
+ #
17
18
  # The amount a SellOpeningFlow will try to sell and the price it will try to charge are derived from these parameters:
18
19
  #
19
20
  # @param usd_balance [BigDecimal] amount of usd available in the other exchange that can be spent to balance this sale.
@@ -48,8 +49,8 @@ module BitexBot
48
49
  # end: sought_transaction helpers
49
50
 
50
51
  # create_for_market helpers
51
- def self.maker_price(usd_to_spend_re_buying)
52
- usd_to_spend_re_buying / value_to_use * (1 + profit / 100)
52
+ def self.maker_price(fiat_to_spend_re_buying)
53
+ fiat_to_spend_re_buying * fx_rate / value_to_use * (1 + profit / 100)
53
54
  end
54
55
 
55
56
  def self.order_class
@@ -1,3 +1,3 @@
1
1
  module BitexBot
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
@@ -72,7 +72,7 @@ describe BitexBot::BuyClosingFlow do
72
72
  end.not_to change { BitexBot::BuyClosingFlow.count }
73
73
  end
74
74
 
75
- describe 'when syncinc executed orders' do
75
+ describe 'when sync executed orders' do
76
76
  before(:each) do
77
77
  stub_bitstamp_sell
78
78
  stub_bitstamp_empty_user_transactions
@@ -29,8 +29,6 @@ describe BitexBot::BuyOpeningFlow do
29
29
  end
30
30
 
31
31
  let(:order_id) { 12_345 }
32
- let(:usd_price) { '14.888_059_701_492'.to_d }
33
- let(:suggested_closing_price) { 15.to_d }
34
32
  let(:amount_to_spend) { 100.to_d }
35
33
  let(:btc_balance) { 100_000.to_d }
36
34
  let(:maker_fee) { 0.5.to_d }
@@ -39,6 +37,8 @@ describe BitexBot::BuyOpeningFlow do
39
37
  let(:transactions) { bitstamp_api_wrapper_transactions_stub }
40
38
 
41
39
  it 'spends 100 usd' do
40
+ suggested_closing_price = 15.to_d
41
+
42
42
  BitexBot::Settings.stub(
43
43
  time_to_live: 3,
44
44
  buying: double(amount_to_spend_per_order: amount_to_spend, profit: 0)
@@ -57,14 +57,15 @@ describe BitexBot::BuyOpeningFlow do
57
57
 
58
58
  flow.order_id.should eq order_id
59
59
  flow.value_to_use.should eq amount_to_spend
60
- flow.price.should.should <= flow.suggested_closing_price
61
- flow.price.truncate(12).should eq usd_price
60
+ flow.price.should <= suggested_closing_price
62
61
  flow.suggested_closing_price.should eq suggested_closing_price
63
62
  end
64
63
 
65
64
  let(:other_fx_rate) { 10.to_d }
66
65
 
67
66
  it 'spends 100 usd with other fx_rate' do
67
+ suggested_closing_price = 25.to_d
68
+
68
69
  BitexBot::Settings.stub(
69
70
  buying_foreign_exchange_rate: other_fx_rate,
70
71
  time_to_live: 3,
@@ -84,8 +85,7 @@ describe BitexBot::BuyOpeningFlow do
84
85
 
85
86
  flow.order_id.should eq order_id
86
87
  flow.value_to_use.should eq amount_to_spend
87
- flow.price.should <= flow.suggested_closing_price * other_fx_rate
88
- flow.price.truncate(11).should eq usd_price * other_fx_rate
88
+ flow.price.should <= suggested_closing_price * other_fx_rate
89
89
  flow.suggested_closing_price.should eq suggested_closing_price
90
90
  end
91
91
 
@@ -113,7 +113,7 @@ describe BitexBot::SellClosingFlow do
113
113
  end.not_to change{ BitexBot::SellClosingFlow.count }
114
114
  end
115
115
 
116
- describe 'when syncinc executed orders' do
116
+ describe 'when sync executed orders' do
117
117
  before(:each) do
118
118
  stub_bitstamp_buy
119
119
  stub_bitstamp_empty_user_transactions
@@ -29,8 +29,6 @@ describe BitexBot::SellOpeningFlow do
29
29
  end
30
30
 
31
31
  let(:order_id) { 12_345 }
32
- let(:usd_price) { '25.18_796_992_481_203'.to_d }
33
- let(:suggested_closing_price) { 25.to_d }
34
32
  let(:amount_to_sell) { 4.to_d }
35
33
  let(:btc_balance) { 100_000.to_d }
36
34
  let(:maker_fee) { 0.5.to_d }
@@ -58,8 +56,6 @@ describe BitexBot::SellOpeningFlow do
58
56
  flow.order_id.should eq order_id
59
57
  flow.value_to_use.should eq amount_to_sell
60
58
  flow.price.should >= flow.suggested_closing_price
61
- flow.price.should eq usd_price
62
- flow.suggested_closing_price.should eq suggested_closing_price
63
59
  end
64
60
 
65
61
  let(:other_fx_rate) { 10.to_d }
@@ -85,8 +81,6 @@ describe BitexBot::SellOpeningFlow do
85
81
  flow.order_id.should eq order_id
86
82
  flow.value_to_use.should eq amount_to_sell
87
83
  flow.price.should >= flow.suggested_closing_price * other_fx_rate
88
- flow.price.truncate(13).should eq usd_price * other_fx_rate
89
- flow.suggested_closing_price.should eq suggested_closing_price
90
84
  end
91
85
 
92
86
  it 'raises the price to charge on bitex to take a profit' do
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.0
4
+ version: 0.5.1
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-02 00:00:00.000000000 Z
12
+ date: 2018-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord