Class: ApiWrapper
- Inherits:
-
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
-
#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.
-
#balance ⇒ BalanceSummary
-
#base ⇒ Object
-
#base_quote ⇒ Object
-
#cancel ⇒ nil
-
#enough_order_size?(quantity, price) ⇒ Boolean
-
#find_lost(_type, _price, _quantity) ⇒ Object
Hook Method - arguments could not be used in their entirety by the subclasses.
-
#name ⇒ Object
-
#order_book(_retries = 20) ⇒ OrderBook
-
#orders ⇒ Array<Order>
-
#place_order(type, price, quantity) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#quote ⇒ Object
-
#send_order(_type, _price, _quantity) ⇒ Object
Hook Method - arguments could not be used in their entirety by the subclasses.
-
#transactions ⇒ Array<Transaction>
-
#user_transactions ⇒ UserTransaction
Instance Attribute Details
#currency_pair ⇒ Object
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.
143
144
145
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 143
def amount_and_quantity(_order_id)
raise 'self subclass responsibility'
end
|
80
81
82
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 80
def balance
raise 'self subclass responsibility'
end
|
#base ⇒ Object
155
156
157
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 155
def base
currency_pair[:base]
end
|
#base_quote ⇒ Object
151
152
153
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 151
def base_quote
"#{base}_#{quote}"
end
|
#cancel ⇒ nil
85
86
87
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 85
def cancel
raise 'self subclass responsibility'
end
|
#enough_order_size?(quantity, price) ⇒ Boolean
147
148
149
|
# 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) ⇒ Object
Hook Method - arguments could not be used in their entirety by the subclasses
134
135
136
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 134
def find_lost(_type, _price, _quantity)
raise 'self subclass responsibility'
end
|
#name ⇒ Object
65
66
67
|
# 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) ⇒ OrderBook
75
76
77
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 75
def order_book(_retries = 20)
raise 'self subclass responsibility'
end
|
#orders ⇒ Array<Order>
90
91
92
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 90
def orders
raise 'self subclass responsibility'
end
|
#place_order(type, price, quantity) ⇒ Object
rubocop:disable Metrics/AbcSize
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# 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}")
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 ⇒ Object
159
160
161
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 159
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
125
126
127
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 125
def send_order(_type, _price, _quantity)
raise 'self subclass responsibility'
end
|
#transactions ⇒ Array<Transaction>
70
71
72
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 70
def transactions
raise 'self subclass responsibility'
end
|
95
96
97
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 95
def user_transactions
raise 'self subclass responsibility'
end
|