class ApplyMatch
Public Instance Methods
perform()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 2 def perform cache_balances :before execute_exchange execute_fees unless same_user? cache_balances :after event end
Private Instance Methods
ask()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 55 def ask match.ask end
ask_base_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 78 def ask_base_account market.base_account_for match.ask end
ask_fee()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 98 def ask_fee @ask_fee ||= CalculateFee.new(order: ask, collected_amount: quote).perform end
ask_quote_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 86 def ask_quote_account market.quote_account_for match.ask end
bid()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 51 def bid match.bid end
bid_base_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 74 def bid_base_account market.base_account_for match.bid end
bid_fee()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 94 def bid_fee @bid_fee ||= CalculateFee.new(order: bid, collected_amount: volume).perform end
bid_quote_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 82 def bid_quote_account market.quote_account_for match.bid end
cache_balances(_which)
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 33 def cache_balances(_which) event.public_send("bid_base_account_#{_which}=", bid_base_account.clone) event.public_send("bid_quote_account_#{_which}=", bid_quote_account.clone) event.public_send("ask_base_account_#{_which}=", ask_base_account.clone) event.public_send("ask_quote_account_#{_which}=", ask_quote_account.clone) event.public_send("ex_base_account_#{_which}=", exchange_base_account.clone) event.public_send("ex_quote_account_#{_which}=", exchange_quote_account.clone) end
event()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 42 def event @event ||= Events::TransactionExecuted.new.tap do |ev| ev.bid = bid.ref ev.ask = ask.ref ev.volume = volume ev.quote = quote end end
exchange_base_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 102 def exchange_base_account market.exchange_base_account end
exchange_quote_account()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 106 def exchange_quote_account market.exchange_quote_account end
execute_exchange()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 12 def execute_exchange bid_quote_account.unfreeze quote unless bid.new? ask_base_account.unfreeze volume unless ask.new? bid.consume volume ask.consume volume transfer quote, from: bid_quote_account, to: ask_quote_account transfer volume, from: ask_base_account, to: bid_base_account event.quote = quote end
execute_fees()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 25 def execute_fees transfer bid_fee, from: bid_base_account, to: exchange_base_account transfer ask_fee, from: ask_quote_account, to: exchange_quote_account event.bid_fee = bid_fee event.ask_fee = ask_fee end
quote()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 63 def quote @quote ||= begin CalculateQuote.new(volume: volume, unit_price: match.price_paid).perform end end
same_user?()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 90 def same_user? bid.user == ask.user end
transfer(_amount, from: nil, to: nil)
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 69 def transfer(_amount, from: nil, to: nil) from.withdraw _amount to.deposit _amount end
volume()
click to toggle source
# File lib/moneymarket/commands/execute_match.rb, line 59 def volume match.volume end