Created
May 24, 2018 21:21
-
-
Save cawka/af0562d8233549bc5d3d9e37a9479acd to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rest-client' | |
require 'date' | |
require 'csv' | |
require 'json' | |
require 'yaml' | |
require 'optparse' | |
require './apex' | |
config = YAML.load_file('_config.yml') | |
config['startDate'] = Date.today - 3 | |
config['endDate'] = Date.today - 1 | |
options = {} | |
OptionParser.new { |opts| | |
opts.banner = "Usage: ./get-activity.rb [options]" | |
opts.on("--start=DATE", "Start date") { |date| | |
config['startDate'] = Date.parse(date) | |
} | |
opts.on("--end=DATE", "End date") { |date| | |
config['endDate'] = Date.parse(date) | |
} | |
opts.on("--accounts=ACCOUNTS", "Accounts to use") { |accounts| | |
config['accounts'] = accounts.split ',' | |
} | |
}.parse! | |
csv_headers = ['Type', 'Account', 'Trade Date', 'Settle Date', 'Tag #', 'Timestamp', 'Symbol', 'Description', 'Trade Action', 'Qty', 'Price', 'Fees', 'Commissions', 'Net Amount'] | |
headers = ['activityType', 'accountType', 'tradeDate', 'settleDate', 'tagNumber', 'timestamp', 'symbol', 'description', 'tradeAction', 'quantity', 'price', 'fees', 'commissions', 'netAmount'] | |
apex = Apex.new(config['username'], config['password']) | |
config['accounts'].each { |account| | |
puts account | |
CSV.open("activity-#{config['startDate']}-#{config['endDate']}-#{account}.csv", "wb", | |
:write_headers => true, | |
:quote_char=>'"', | |
:col_sep =>",", | |
:force_quotes => true, | |
:headers => csv_headers) { |csv| | |
values = apex.activities(config['startDate'], config['endDate'], account) | |
values.each { |row| | |
csv << headers.map { |i| row[i] } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment