-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bugmark/master
merging
- Loading branch information
Showing
38 changed files
with
505 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# ----- setup ----- | ||
|
||
Dir.chdir File.expand_path(__dir__) | ||
require_relative '../../Base/lib/dotenv' | ||
TRIAL_DIR = dotenv_trial_dir(__dir__) | ||
|
||
# ----- libraries ----- | ||
|
||
require_relative '../../Base/lib/exchange' | ||
require_relative '../../Base/lib/trial_settings' | ||
require_relative '../../Base/lib/helpers' | ||
require 'awesome_print' | ||
require 'securerandom' | ||
|
||
# ----- info ----- | ||
|
||
puts "EXCHANGE_DIR=#{Exchange.src_dir}" | ||
puts 'EXERCISE SETTINGS' | ||
ap(TrialSettings.settings, sort_keys: true) | ||
|
||
# ----- load ----- | ||
|
||
puts 'LOADING RAILS' | ||
Exchange.load_rails | ||
|
||
# ----- reset ----- | ||
|
||
puts 'CROSSING OFFERS' | ||
|
||
Offer.is_buy_fixed.open.each do |offer| | ||
ContractCmd::Cross.new(offer, :expand).project | ||
print "." | ||
end | ||
|
||
Offer.is_buy_unfixed.open.each do |offer| | ||
ContractCmd::Cross.new(offer, :expand).project | ||
print "." | ||
end | ||
|
||
Offer.is_sell.open.each do |offer| | ||
ContractCmd::Cross.new(offer, :transfer).project | ||
print "." | ||
end | ||
|
||
Offer.is_sell_fixed.open.each do |offer| | ||
ContractCmd::Cross.new(offer, :reduce).project | ||
print "." | ||
end | ||
|
||
Offer.is_sell_unfixed.open.each do |offer| | ||
ContractCmd::Cross.new(offer, :reduce).project | ||
print "." | ||
end | ||
|
||
puts "." | ||
puts "DONE." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# ----- setup ----- | ||
|
||
Dir.chdir File.expand_path(__dir__) | ||
require_relative '../../Base/lib/dotenv' | ||
TRIAL_DIR = dotenv_trial_dir(__dir__) | ||
|
||
# ----- libraries ----- | ||
|
||
require_relative '../../Base/lib/exchange' | ||
require_relative '../../Base/lib/trial_settings' | ||
require_relative '../../Base/lib/helpers' | ||
require 'awesome_print' | ||
require 'securerandom' | ||
|
||
# ----- info ----- | ||
|
||
puts "EXCHANGE_DIR=#{Exchange.src_dir}" | ||
puts 'EXERCISE SETTINGS' | ||
ap(TrialSettings.settings, sort_keys: true) | ||
|
||
# ----- load ----- | ||
|
||
puts 'LOADING RAILS' | ||
Exchange.load_rails | ||
|
||
# ----- reset ----- | ||
|
||
puts 'UPDATE USER BALANCES' | ||
|
||
users = User.all.select do |user| | ||
user.balance < 200.0 | ||
end | ||
|
||
users.each do |user| | ||
delta = 200.0 - user.balance | ||
args = { | ||
uuid: user.uuid , | ||
amount: delta , | ||
note: "Low-balance adjustment" | ||
} | ||
puts "Updating balance for #{user.email}" | ||
UserCmd::Deposit.new(args).project | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require "ostruct" | ||
|
||
class Balance | ||
attr_reader :events | ||
|
||
def initialize(events) | ||
@events = balance_events(events) | ||
end | ||
|
||
def rows | ||
events.reduce([]) do |acc, event| | ||
adjustment = adjustment(event) | ||
new_balance = (acc.last&.balance || 0) + adjustment(event) | ||
acc + [new_row(event, adjustment, new_balance)] | ||
end | ||
end | ||
|
||
private | ||
|
||
def new_row(event, adjustment, balance) | ||
row = OpenStruct.new | ||
row.balance = balance | ||
row.adjustment = adjustment | ||
row.id = event.id | ||
row.uuid = event.event_uuid | ||
row.date = event.projected_at.strftime("%m-%d %H:%M:%S") | ||
row.cmd_type = event.cmd_type | ||
row.event_type = event.event_type.gsub("Event::", "") | ||
row.payload = event.payload | ||
row.note = event.note | ||
row | ||
end | ||
|
||
def adjustment(event) | ||
increment_types = %w(UserDeposited) | ||
type = event.event_type.split("::").last | ||
amount = event.payload["amount"] || 0 | ||
increment_types.include?(type) ? amount : -1 * amount | ||
end | ||
|
||
def balance_events(events) | ||
list = %w(UserCreated UserDeposited UserWithdrawn) | ||
events.to_a.select do |event| | ||
type = event.event_type.split("::").last | ||
list.include?(type) | ||
end | ||
end | ||
end |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.