Skip to content

Instantly share code, notes, and snippets.

@cawka
Created May 24, 2018 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cawka/45b484d49e90decadfe9c483d75334f8 to your computer and use it in GitHub Desktop.
Save cawka/45b484d49e90decadfe9c483d75334f8 to your computer and use it in GitHub Desktop.
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