Class: BitstampApiWrapper
- Inherits:
-
Object
- Object
- BitstampApiWrapper
- Defined in:
- lib/bitex_bot/models/bitstamp_api_wrapper.rb
Class Method Summary collapse
- .amount_and_quantity(order_id, transactions) ⇒ Object
-
.balance ⇒ Object
“10.0”, “btc_reserved”=> “0”, “btc_available”=> “10.0”, “usd_balance”=> “100.0”, “usd_reserved”=>“0”, “usd_available”=> “100.0”, “fee”=> “0.5000”.
-
.order_book(retries = 20) ⇒ Object
{ ‘timestamp’ => DateTime.now.to_i.to_s, ‘bids’ => [[‘30’, ‘3’], [‘25’, ‘2’], [‘20’, ‘1.5’], [‘15’, ‘4’], [‘10’, ‘5’]], ‘asks’ => [[‘10’, ‘2’], [‘15’, ‘3’], [‘20’, ‘1.5’], [‘25’, ‘3’], [‘30’, ‘3’]] }.
- .order_is_done?(order) ⇒ Boolean
- .orders ⇒ Object
- .place_order(type, price, quantity) ⇒ Object
- .setup(settings) ⇒ Object
-
.transactions ⇒ Object
{ tid:i, date: (i+1).seconds.ago.to_i.to_s, price: price.to_s, amount: amount.to_s }.
-
.user_transactions ⇒ Object
double(usd: (usd * ratio).to_s, btc: (btc * ratio).to_s, btc_usd: o.price.to_s, order_id: o.id, fee: “0.5”, type: 2, datetime: DateTime.now.to_s).
Class Method Details
.amount_and_quantity(order_id, transactions) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 72 def self.amount_and_quantity(order_id, transactions) closes = transactions.select{|t| t.order_id.to_s == order_id} amount = closes.collect{|x| x.usd.to_d }.sum.abs quantity = closes.collect{|x| x.btc.to_d }.sum.abs [amount, quantity] end |
.balance ⇒ Object
“10.0”, “btc_reserved”=> “0”, “btc_available”=> “10.0”, “usd_balance”=> “100.0”, “usd_reserved”=>“0”, “usd_available”=> “100.0”, “fee”=> “0.5000”
50 51 52 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 50 def self.balance Bitstamp.balance end |
.order_book(retries = 20) ⇒ Object
{ ‘timestamp’ => DateTime.now.to_i.to_s,
'bids' =>
[['30', '3'], ['25', '2'], ['20', '1.5'], ['15', '4'], ['10', '5']],
'asks' =>
[['10', '2'], ['15', '3'], ['20', '1.5'], ['25', '3'], ['30', '3']]
}
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 26 def self.order_book(retries = 20) begin book = Bitstamp.order_book age = Time.now.to_i - book["timestamp"].to_i if age > 300 BitexBot::Robot.logger.info("Refusing to continue as orderbook is #{age} seconds old") self.order_book(retries) else book end rescue StandardError => e if retries == 0 raise else BitexBot::Robot.logger.info("Bitstamp order_book failed, retrying #{retries} more times") sleep 1 self.order_book(retries - 1) end end end |
.order_is_done?(order) ⇒ Boolean
68 69 70 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 68 def self.order_is_done?(order) order.nil? end |
.orders ⇒ Object
57 58 59 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 57 def self.orders Bitstamp.orders.all end |
.place_order(type, price, quantity) ⇒ Object
79 80 81 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 79 def self.place_order(type, price, quantity) Bitstamp.orders.send(type, amount: quantity, price: price) end |
.setup(settings) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 2 def self.setup(settings) Bitstamp.setup do |config| config.key = settings.bitstamp.key config.secret = settings.bitstamp.secret config.client_id = settings.bitstamp.client_id.to_s end end |
.transactions ⇒ Object
tid:i,
date: (i+1).seconds.ago.to_i.to_s,
price: price.to_s,
amount: amount.to_s
16 17 18 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 16 def self.transactions Bitstamp.transactions end |
.user_transactions ⇒ Object
double(usd: (usd * ratio).to_s, btc: (btc * ratio).to_s,
btc_usd: o.price.to_s, order_id: o.id, fee: "0.5", type: 2,
datetime: DateTime.now.to_s)
64 65 66 |
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 64 def self.user_transactions Bitstamp.user_transactions.all end |