Giter Club home page Giter Club logo

qapi's Introduction

Build Status GoDoc #qapi

qapi is an abstraction over the Questrade REST API, written in Go.

##Logging In You will need to sign up for a practice account, or create an API key for your trading account. You can do so at http://www.questrade.com/api/home

To login, you will need to provide the refresh token generated on the Questrade API admin site During login, the refresh token is exchanged for an access token, which qapi uses to make authenticated API calls. Upon successful login, Questrade returns a replacement refresh token, which is necessary to login again after the current session expires. See http://www.questrade.com/api/documentation/security for more info.

##Usage

// Create a new client on the practice server
client, err := qapi.NewClient("< REFRESH TOKEN >", true)

// Get accounts
userId, accts, err := client.GetAccounts()

// Get balances for the first account
balances, err := client.GetBalances(accts[0].Number)

// Print the market value of the combined balances
for _, b := range balances.CombinedBalances {
    fmt.Printf("Market Value: $%.2f %s\n", b.MarketValue, b.Currency)
}

// To get a quote the API uses internal symbol ID’s.
results, err := client.SearchSymbols("AAPL", 0)

var symId int
for _, r := range results {
    if r.Symbol == "AAPL" && r.ListingExchange == "NASDAQ" {
        symId = r.SymbolID
        break
    }
}

// Get a real-time quote - qapi supports getting quotes of multiple symbols with GetQuotes()
quote, err := client.GetQuote(symId)
fmt.Printf("AAPL Bid Price: $%.2f\n", quote.BidPrice)

// Create an order request
req := qapi.OrderRequest{
    AccountID: accts[0].Number,
    SymbolID: symId,
    Quantity: 10,
    OrderType: "Limit",
    LimitPrice: 10.00,
    TimeInForce: "Day",
    Action: "Buy",
    PrimaryRoute: "AUTO",
    SecondaryRoute: "AUTO",
}

// Get the impact the order will have on your selected account
impact, err := client.GetOrderImpact(req)
fmt.Printf("Buying power effect: $%.2f\n", impact.BuyingPowerEffect)

// Place the order and print the OrderID
orders, err := client.PlaceOrder(req)
fmt.Printf("Order ID: %d", orders[0].ID)
    
// Delete the order
err :- client.DeleteOrder(req.AccountID, orders[0].ID)

// We’re done with the application forever - deauthorize the API key
client.RevokeAuth()

For an example program that uses this library check out my S&P 500 candlestick data scraping program

##TODO

  • Start writing tests.
  • Verify some of the enumerations in the API responses - some of them on the documentation site appears incomplete

##Disclaimer NOTE - This library is not endorsed or supported by Questrade in any way, shape or form. This library is released under the MIT License.

qapi's People

Contributors

abourget avatar alexurquhart avatar cprovencher avatar wenbenz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.