Class: BitstampApiWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/bitex_bot/models/bitstamp_api_wrapper.rb

Class Method Summary collapse

Class Method Details

.amount_and_quantity(order_id, transactions) ⇒ Object



55
56
57
58
59
60
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 55

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

.balanceObject

“10.0”, “btc_reserved”=> “0”, “btc_available”=> “10.0”, “usd_balance”=> “100.0”, “usd_reserved”=>“0”, “usd_available”=> “100.0”, “fee”=> “0.5000”



33
34
35
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 33

def self.balance
  Bitstamp.balance
end

.order_bookObject

{ ‘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
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 26

def self.order_book
  Bitstamp.order_book
end

.order_is_done?(order) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 51

def self.order_is_done?(order)
  order.nil?
end

.ordersObject

ask = double(amount: args, price: args,

type: 1, id: remote_id, datetime: DateTime.now.to_s)

ask.stub(:cancel!) do



40
41
42
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 40

def self.orders
  Bitstamp.orders.all
end

.place_order(type, price, quantity) ⇒ Object



62
63
64
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 62

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

.transactionsObject

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_transactionsObject

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)


47
48
49
# File 'lib/bitex_bot/models/bitstamp_api_wrapper.rb', line 47

def self.user_transactions
  Bitstamp.user_transactions.all
end