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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currency_pairObject

Returns the value of attribute currency_pair.



3
4
5
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 3

def currency_pair
  @currency_pair
end

Instance Method Details

#amount_and_quantity(_order_id) ⇒ Array<Decimal, Decimal>

From an order when you buy or sell, when you place an order and it matches, you can match more than one order.

Parameters:

  • order_id
  • transactions:

    all matches for a purchase or sale order.

Returns:

  • (Array<Decimal, Decimal>)


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

def amount_and_quantity(_order_id)
  raise 'self subclass responsibility'
end

#balanceBalanceSummary

Returns:



76
77
78
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 76

def balance
  raise 'self subclass responsibility'
end

#baseObject



144
145
146
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 144

def base
  currency_pair[:base]
end

#base_quoteObject



140
141
142
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 140

def base_quote
  "#{base}_#{quote}"
end

#cancelnil

Returns:

  • (nil)


81
82
83
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 81

def 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 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_type (String)

    buy|sell

  • price (Decimal)
  • quantity (Decimal)


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

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

#order_book(_retries = 20) ⇒ OrderBook

Returns:



71
72
73
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 71

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

#ordersArray<Order>

Returns:



86
87
88
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 86

def orders
  raise 'self subclass responsibility'
end

#place_order(type, price, quantity) ⇒ Object

Parameters:

  • type
  • price
  • quantity

Raises:



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

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 #{self.class}")
  # 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} #{base} @ #{quote} #{price}. #{order}"
end

#quoteObject



148
149
150
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 148

def quote
  currency_pair[:quote]
end

#send_order(_type, _price, _quantity) ⇒ Object

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



114
115
116
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 114

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

#transactionsArray<Transaction>

Returns:



66
67
68
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 66

def transactions
  raise 'self subclass responsibility'
end

#user_transactionsUserTransaction

Returns:



91
92
93
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 91

def user_transactions
  raise 'self subclass responsibility'
end