4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/trade-o-matic/adapters/game_backend/execute_order.rb', line 4
def perform
@market = state.market_for pair
@base_balance = state.balance_for account, @market['base']
@quote_balance = state.balance_for account, @market['quote']
if bid?
raise 'Not enough funds' if limit_order? and !enough_funds_for_bid?
load_bid_candidates
match_candidates
raise 'Not enough funds' if market_order? and !can_execute_market_bid?
execute_bid_txs
update_balance_on_bid unless order_fully_consumed?
store_order 'bid'
else
raise 'Not enough funds' unless enough_funds_for_ask?
load_ask_candidates
match_candidates
execute_ask_txs
update_balance_on_ask unless order_fully_consumed?
store_order 'ask'
end
end
|