Class: ApiWrapper

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

Overview

This class represents the general behaviour for trading platform wrappers.

Defined Under Namespace

Classes: Balance, BalanceSummary, Order, OrderBook, OrderSummary, Transaction, UserTransaction

Constant Summary collapse

MIN_AMOUNT =
5

Class Method Summary collapse

Class Method Details

.amount_and_quantity(_order_id, _transactions) ⇒ Array<Decimal, Decimal>

Parameters:

  • order_id
  • transactions

Returns:

  • (Array<Decimal, Decimal>)


132
133
134
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 132

def self.amount_and_quantity(_order_id, _transactions)
  raise 'self subclass responsibility'
end

.balanceBalanceSummary

Returns:



78
79
80
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 78

def self.balance
  raise 'self subclass responsibility'
end

.cancelnil

Returns:

  • (nil)


83
84
85
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 83

def self.cancel
  raise 'self subclass responsibility'
end

.enough_order_size?(quantity, price) ⇒ Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 136

def self.enough_order_size?(quantity, price)
  (quantity * price) > MIN_AMOUNT
end

.find_lost(_type, _price, _quantity) ⇒ Object

Hook Method - arguments could not be used in their entirety by the subclasses

Parameters:

  • order_method (String)

    buy|sell

  • price (Decimal)


124
125
126
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 124

def self.find_lost(_type, _price, _quantity)
  raise 'self subclass responsibility'
end

.order_book(_retries = 20) ⇒ OrderBook

Returns:



73
74
75
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 73

def self.order_book(_retries = 20)
  raise 'self subclass responsibility'
end

.ordersArray<Order>

Returns:



88
89
90
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 88

def self.orders
  raise 'self subclass responsibility'
end

.place_order(type, price, quantity) ⇒ Object

Parameters:

  • type
  • price
  • quantity

Raises:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 100

def self.place_order(type, price, quantity)
  order = send_order(type, price, quantity)
  return order unless order.nil? || order.id.nil?

  BitexBot::Robot.log(:debug, "Captured error when placing order on #{self.class.name}")
  # Order may have gone through and be stuck somewhere in Wrapper's pipeline.
  # We just sleep for a bit and then look for the order.
  20.times do
    BitexBot::Robot.sleep_for(10)
    order = find_lost(type, price, quantity)
    return order if order.present?
  end
  raise OrderNotFound, "Closing: #{type} order not found for #{quantity} BTC @ $#{price}. #{order}"
end

.send_order(_type, _price, _quantity) ⇒ Object

Hook Method - arguments could not be used in their entirety by the subclasses



116
117
118
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 116

def self.send_order(_type, _price, _quantity)
  raise 'self subclass responsibility'
end

.setup(_settings) ⇒ Void

Returns:

  • (Void)


63
64
65
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 63

def self.setup(_settings)
  raise 'self subclass responsibility'
end

.transactionsArray<Transaction>

Returns:



68
69
70
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 68

def self.transactions
  raise 'self subclass responsibility'
end

.user_transacitionsUserTransaction

Returns:



93
94
95
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 93

def self.user_transacitions
  raise 'self subclass responsibility'
end