Coder Social home page Coder Social logo

tradeking's Introduction

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

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.

tradeking's People

Contributors

xgp avatar

Watchers

 avatar  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.