Created
May 24, 2018 21:19
-
-
Save cawka/45b484d49e90decadfe9c483d75334f8 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
class Apex | |
def initialize(username, password) | |
@endpointLegit = "https://public-api.apexclearing.com/legit/api/v2" | |
@endpointMarginProvider = "https://public-api.apexclearing.com/margin-provider/api/v1" | |
@endpointActivitiesProvider = "https://public-api.apexclearing.com/activities-provider/api/v1" | |
authorize(username, password) | |
end | |
def authorize(username, password) | |
response = RestClient.post("#{@endpointLegit}/session", | |
{ | |
:user => "", | |
:username => username, | |
:password => password | |
}.to_json, | |
{content_type: :json, accept: :json} | |
) | |
@cookies = response.cookies | |
end | |
def margins(date, account) | |
response = RestClient.get("#{@endpointMarginProvider}/margins/#{account}", | |
{ | |
:params => { | |
:processDate => date.to_s | |
}, | |
:cookies => @cookies | |
} | |
) | |
JSON.parse(response.body) | |
end | |
def activities(from, to, account) | |
response = RestClient.get("#{@endpointActivitiesProvider}/activities/#{account}", | |
{ | |
:params => { | |
:activityType => [:TRADES, :POSITION_ADJUSTMENTS, :MONEY_MOVEMENTS], | |
:startDate => from.to_s, | |
:endDate => to.to_s | |
}, | |
:cookies => @cookies | |
} | |
) | |
JSON.parse(response.body) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment