TDAmeritradeAPI
Front-end library - with C, C++, Python, and Java interfaces - for the recently expanded TDAmeritrade API
Install / Use
/learn @jeog/TDAmeritradeAPIREADME
TDAmeritradeAPI
A front-end shared library - with C, C++, Python, and Java interfaces - for the recently expanded TDAmeritrade API. It provides object-oriented access to the simple HTTPS/JSON interface using libcurl and to the Streaming interface using uWebSockets.
After setting up a TDAmeritrade developer account you should be able to gain access to the API by following the instructions in the Authentication section below.
The library is designed to abstract away many of the lower level details of accessing the API while still providing almost complete control over authentication, access, data handling, and order execution.
-
Provides a collection of API calls and stand-alone tools for custom authentication management.
-
Does not completely parse returned data, allowing users to handle it as they see fit.
-
Exposes a stable C ABI to support a portable C++ interface and bindings for other languages.
If you're interested in contributing - or would like to write bindings for a currently unsupported language - please communicate your intentions first.
Communicating w/ 3rd party servers, accessing financial accounts, and automating trade execution are all operations that present risk and require responsibility. By using this software you agree that you understand and accept these risks and responsibilities. You accept sole responsibility for the results of said use. You completely absolve the author of any damages, financial or otherwise, incurred personally or by 3rd parties, directly or indirectly, by using this software - even those resulting from the gross negligence of the author. All communication with TDAmeritrade servers, access of accounts, and execution of orders must adhere to their policies and terms of service and is your repsonsibility, and yours alone.
Index
- Dependencies
- Updates
- Status
- Structure
- Getting Started
- Conventions
- Errors & Exceptions
- Authentication
- Access
- Utilities
- Licensing & Warranty
Dependencies
This project would not be possible without some of the great open-source projects listed below.
- libcurl - Client-side C library supporting a ton of transfer protocols
- openssl - C library for tls/ssl and crypto
- zlib - Compression library
- libuv - Cross-platform asynchronous I/O
- uWebSockets - A simple and efficient C++ WebSocket library. The source is included, compiled and archived with our library to limit dependency issues.
- nlohmann::json : - An extensive C++ json library that only requires adding a single header file.
- jna - Java Native Access
- org.json - Reference implementation of a Java JSON package
- cefpython3 - Python bindings for the Chromium Embedded Framework
Updates
- Remove symbology conversions from streaming session to fix bug with decimal-strike option symbols
- New single makefile build for unix/linux/mac in 'Release2/'
- Fix Account ID bug in streamer, allow for optional account
- Transfer timeouts for Getters
- Account Activity Subscription to Streaming Session
- Update OrdersGetter to return ALL status types by default
- HTTPSharedConnection allows multiple getter instances to share a single connection(by default)
- Streaming Session calls back with a heartbeat every 10 seconds
- Java Bindings - get and streaming interfaces
- credential_builder.py - streamlined approach to authentication and credential building
- DynamicDataStore - module that abstracts away data retrieval, providing a simple bar-based interface
- Mac build (see below)
- Raw Subscriptions for complete control over accessing the Streaming interface
- ADD, VIEW, UNSUBS commands for Streaming interface
Status
| | Get Interface | Streaming Interface | Execute Interface -------------------|---------------|---------------------|-------------------- C | Working | Working | OrderTicket, Builders, Send/Cancel C++ | Working | Working | OrderTicket, Builders, Send/Cancel Python | Working | Working | OrderTicket, Builders, Send/Cancel Java | Working | Working | Comming Soon
Note: 'Working' does not necessarily mean 'Stable'
Note: Execute Interface has undergone very little testing
Structure
|--------------------------------------|-----------------|------------|
| client python, java etc. | client C++ | client C |
|--------------------------------------| | |
| extension layer | | |
|--------------------------------------|-----------------| |
| C-lib interface (e.g ctypes.py, JNA) | C++ Proxy Layer | |
|=====================================================================|
| (binary compatible) C interface |
|---------------------------------------------------------------------|
| (non binary compatible) C++ interface to TDAmeritradeAPI |
|---------------------------------------------------------------------|
There are certain binary compatibility issues when exporting C++ code accross compilations(from name mangling, differing runtimes, changes to STL implementations etc.). Although we attempt to limit these issues with an ABI layer and 'proxy' objects, it's recommended to compile client code and the library using the same compiler/settings and link to the same libraries.
Getting Started
It's recommended you build from source. If not comfortable with this, or you just want to use the Python or Java interface, it may be easier to use a precompiled linux/windows library.
To more easily support different platforms, bindings, and use-cases while the library is in development we don't use a unified build system. The current approach:
- build dependencies
- build library
- install dependencies and library
- link to or load the library
We are currently in the process of converting to a (manually) generated makefile project - if you would like to contribute (or simply test on non-linux systems) please send an email or file an issue.
Build Dependencies
Unix/Linux
If using a package manager, like apt, install the libcurl, libssl, and zlib dev packages:
sudo apt-get install libcurl4-openssl-dev libssl-dev zlib1g-dev
Alternatively, you can download them manually via github:
git clone https://github.com/openssl/openssl.git
git clone https://github.com/curl/curl.git
git clone https://github.com/madler/zlib.git
... or the individual project sites:
Mac
You'll need the same libraries as the Unix/Linux build AND libuv.
brew install libuv
Windows
Compiled dependencies - 32 and 64 bit release builds of openssl, curl, zlib, and uv - are included in the vsbuild/deps/libs directory. If you'd still like to download and build them yourselves visit the links from the sections above. Pay attention to the install section below.
Build Library
The library is implemented in C++ and needs to be built accordingly. It exports a C/ABI layer which is wrapped by header defined C calls and C++ calls/objects, allowing for access from pure C, C++, Python via ctypes.py, and Java via JNA.
FunctionImpl(string) [C++ implementation code defined in lib]
Funtion_ABI(const char*) [C ABI code defined in lib and exported]
/\ /\ /\ /\
====||==||==||==||=====================[lib boundary]==========================
|| || || ||
|| || || || ---------------------[headers]----------------------------
|| || || || #ifdef __cplusplus
|| || || ||<=== Function(string) [C++ wrapper defined in header]
|| || || #else
|| || ||<======= Function(const char *) [C wrapper defined in header]
|| || #endif
|| || --------/\------------------------------------------------
|| || --------||------------------------------------------------
|| || Function("foo") [Client C/C++]
|| || ----------------------------------------------------------
|| ||
|| ||<=== ctypes.CDll.Function
