PackageDescription: TradeKing(Bundle)

Trade King

Last published: March 11, 2015 by 'shaffer'

Client for the TradeKing web service interface: Requires SSL support. If Toothpick is installed, will produce #info level logging events.

*** VisualWorks 7.7.1 users will need the following modification (hat tip to Boris Popov):

Net.SSLConnection compile: 'validationBlock
^validationBlock isNil
ifTrue: [[:dnd | (dnd at: ''CN'') match: hostName]]
ifFalse: [validationBlock]'.

*** Demo script

"First go to the site and register as a developer and register your application to get your consumer key, secret then request an application access token and secret. Then download the pem file referenced below."

registry := Security.X509.X509Registry default.
certificate := Security.X509.Certificate fromFile:'COMODOHighAssuranceSecureServerCA.pem'.
registry addCertificate: certificate.

"Next add commonly used CA's to your trusted CA list:"

| pem bundle |
pem := (Net.HttpClient get: '') contents.
bundle := Security.X509.CertificateFileReader new readFrom: pem readStream.
Security.X509.X509Registry trustedCertificates addAll: bundle.

"Next configure a your TradeKing session"

consumerKey := 'your-consumer-key'.
consumerSecret := 'your-consumer-secret'.
myAccessToken := 'your-access-token'.
myAccessTokenSecret := 'your-access-token-secret'.

session := TradeKing.TradeKingSession
consumerKey: consumerKey
consumerSecret: consumerSecret.

"This session will trade on my behalf"
session token: myAccessToken secret: myAccessTokenSecret.
restClient := TradeKing.RESTClient new.
client := TradeKing.TradeKingClient session: session client: restClient.

client accounts inspect.
(client accountOrders: 'your-account-number') inspect.
(client getQuotes: #(AAPL) fieldIds: nil) inspect.

"You'll need to modify the date below since 'time sales' data is only available for the past 5 trading days."
(client timeSalesSymbols: 'IBM' interval: '1min' perPage: nil index: nil startDate: '2013-05-02' endDate: '2013-05-03' startTime: '09:30:00') inspect