class ApiWrapper

This class represents the general behaviour for trading platform wrappers.

Constants

Balance
BalanceSummary
MIN_AMOUNT
Order
OrderBook
OrderSummary
Transaction
UserTransaction

Attributes

currency_pair[RW]

Public Instance Methods

amount_and_quantity(_order_id) click to toggle source

From an order when you buy or sell, when you place an order and it matches, you can match more than one order. @param order_id @param transactions: all matches for a purchase or sale order.

@return [Array<Decimal, Decimal>]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 143
def amount_and_quantity(_order_id)
  raise 'self subclass responsibility'
end
balance() click to toggle source

@return [BalanceSummary]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 80
def balance
  raise 'self subclass responsibility'
end
base() click to toggle source
# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 155
def base
  currency_pair[:base]
end
base_quote() click to toggle source
# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 151
def base_quote
  "#{base}_#{quote}"
end
cancel() click to toggle source

@return [nil]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 85
def cancel
  raise 'self subclass responsibility'
end
enough_order_size?(quantity, price) click to toggle source
# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 147
def enough_order_size?(quantity, price)
  quantity * price > MIN_AMOUNT
end
find_lost(_type, _price, _quantity) click to toggle source

@param order_type [String] buy|sell @param price [Decimal] @param quantity [Decimal]

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

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 134
def find_lost(_type, _price, _quantity)
  raise 'self subclass responsibility'
end
name() click to toggle source
# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 65
def name
  self.class.name.underscore.split('_').first.capitalize
end
order_book(_retries = 20) click to toggle source

@return [OrderBook]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 75
def order_book(_retries = 20)
  raise 'self subclass responsibility'
end
orders() click to toggle source

@return [Array<Order>]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 90
def orders
  raise 'self subclass responsibility'
end
place_order(type, price, quantity) click to toggle source

@param type @param price @param quantity rubocop:disable Metrics/AbcSize

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 103
def 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 #{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.
  5.times do |i|
    BitexBot::Robot.log(
      :info,
      "#{name} cauldn't place #{type} order #{i} times for #{base.upcase} #{quantity} @ #{quote.upcase} #{price}.\n"\
      "Going to sleep 10 seconds.\n"
    )
    BitexBot::Robot.sleep_for(15)
    order = find_lost(type, price, quantity)
    return order if order.present?
  end
  raise OrderNotFound, "Closing: #{type} order not found for #{base.upcase} #{quantity} @ #{quote.upcase} #{price}."
end
quote() click to toggle source
# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 159
def quote
  currency_pair[:quote]
end
send_order(_type, _price, _quantity) click to toggle source

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

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 125
def send_order(_type, _price, _quantity)
  raise 'self subclass responsibility'
end
transactions() click to toggle source

@return [Array<Transaction>]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 70
def transactions
  raise 'self subclass responsibility'
end
user_transactions() click to toggle source

@return [UserTransaction]

# File lib/bitex_bot/models/api_wrappers/api_wrapper.rb, line 95
def user_transactions
  raise 'self subclass responsibility'
end