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.
-
#order_book(_retries = 20) ⇒ OrderBook
-
#orders ⇒ Array<Order>
-
#place_order(type, price, quantity) ⇒ Object
-
#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.
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
|
76
77
78
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 76
def balance
raise 'self subclass responsibility'
end
|
#base ⇒ Object
144
145
146
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 144
def base
currency_pair[:base]
end
|
#base_quote ⇒ Object
140
141
142
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 140
def base_quote
"#{base}_#{quote}"
end
|
#cancel ⇒ 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
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
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
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
|
#orders ⇒ Array<Order>
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
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}")
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
|
#quote ⇒ Object
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
|
#transactions ⇒ Array<Transaction>
66
67
68
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 66
def transactions
raise 'self subclass responsibility'
end
|
91
92
93
|
# File 'lib/bitex_bot/models/api_wrappers/api_wrapper.rb', line 91
def user_transactions
raise 'self subclass responsibility'
end
|