xgp / tradeking

The missing TradeKing API for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NOTICES

This has not been updated since Ally Financial bought Tradeking. Ally shut down my access because my use did not meet their policy. If someone is still building apps for Ally/Tradeking and wants to maintain this, please send me a message.

Fork of Ccook's Conniption project. This is now significantly departed. We now use xjc to automatically build Java classes for the model with XSD built by hand from TradeKing's XML examples. Full FIXML parsing is also now supported using Java classes built from the FIX Protocol FIXML schemas.

Tradeking

The missing TradeKing API for Java.

Getting an API Key from TradeKing

Installing

Keys and tokens given to you by TradeKing can be stored as environment variables (via System.getEnv()) or as system properties (via System.getProperty()). System properties take precedence.

Keys

TK_ACCOUNT_NO
API_KEY
API_SECRET
ACCESS_TOKEN
ACCESS_TOKEN_SECRET

For environment variables, put these lines in /etc/environment or /etc/profile (Linux) or /etc/launchd.conf (Mac, requires restart).

Building from souurce

Use the maven clean install directive to compile and make sure everythng works. I highly recommend you do not use -DskipTests. The tests will check your connection to TradeKing.

Maven

<dependency>
    <groupId>com.github.xgp</groupId>
    <artifactId>tradeking-api</artifactId>
    <version>1.1.0</version>
</dependency>

Usage

TradeKing

This is the main entry point to using the API. The other classes you should care about are all in model. Usage is pretty straightforward:

TradeKing tk = new TradeKing(new TradeKingForeman());

// get the market clock https://developers.tradeking.com/documentation/market-clock-get
ClockResponse c = tk.clock();

// get your account https://developers.tradeking.com/documentation/accounts-get
AccountsResponse a = tk.accounts();

// get some market quotes https://developers.tradeking.com/documentation/market-ext-quotes-get-post
QuotesResponse q = tk.quotes("TWTR", "FB");

// stream market quotes https://developers.tradeking.com/documentation/streaming-market-quotes-get-post
Future f = tk.quotes(new StreamHandler<Quote>() {
    public void handle(Quote quote) {
            System.out.println(quote.toString());
        }
    }, "TWTR", "FB");

// place a non-executing, preview order
FIXMLBuilder builder = new FIXMLBuilder()
    .id(ForemanConstants.TK_ACCOUNT_NO.toString())
    .timeInForce(TimeInForceField.DAY_ORDER)
    .symbol("TWTR")
    .priceType(PriceType.LIMIT)
    .securityType(SecurityType.STOCK)
    .quantity(1)
    .executionPrice(18.01)
    .side(MarketSideField.BUY);
OrderResponse p = tk.preview(ForemanConstants.TK_ACCOUNT_NO, builder.build().toString());

// place a real order
OrderResponse o = tk.order(ForemanConstants.TK_ACCOUNT_NO, builder.build().toString());

// check the status of your orders
OrdersResponse os = tk.orders(ForemanConstants.TK_ACCOUNT_NO);

Warnings

This assumes the most simpliest of Accounts. Don't use if you're doing complex shit. I also haven't implemented options functionality yet. Use at your own risk.

License, Attribution, etc

This is licensed under the Apache License, version 2. It is in no way associated with TradeKing or TradeKing Group, Inc.

Please read TradeKing's documentation carefully! Use only as they suggest.

About

The missing TradeKing API for Java

License:Apache License 2.0


Languages

Language:Java 100.0%