• Stars
    star
    447
  • Rank 97,039 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A trading robot, that can submit basic orders in an automated fashion using the TD API.

Python Trading Robot

Table of Contents

Overview

Current Version: 0.1.1

A trading robot written in Python that can run automated strategies using a technical analysis. The robot is designed to mimic a few common scenarios:

  1. Maintaining a portfolio of multiple instruments. The Portfolio object will be able to calculate common risk metrics related to a portfolio and give real-time feedback as you trade.

  2. Define an order that can be used to trade a financial instrument. With the Trade object, you can define simple or even complex orders using Python. These orders will also help similify common scenarios like defining both a take profit and stop loss at the same time.

  3. A real-time data table that includes both historical and real-time prices as they change. The StockFrame will make the process of storing your data easy and quick. Additionally, it will be setup so that way you can easily select your financial data as it comes in and do further analysis if needed.

  4. Define and calculate indicators using both historical and real-time prices. The Indicator object will help you easily define the input of your indicators, calculate them, and then update their values as new prices come.

Setup

Setup - Local Install:

If you are planning to make modifications to this project or you would like to access it before it has been indexed on PyPi. I would recommend you either install this project in editable mode or do a local install. For those of you, who want to make modifications to this project. I would recommend you install the library in editable mode.

If you want to install the library in editable mode, make sure to run the setup.py file, so you can install any dependencies you may need. To run the setup.py file, run the following command in your terminal.

pip install -e .

If you don't plan to make any modifications to the project but still want to use it across your different projects, then do a local install.

pip install .

This will install all the dependencies listed in the setup.py file. Once done you can use the library wherever you want.

Setup - PyPi Install:

The project can be found at PyPI, if you'd like to view the project please use this link. To install the library, run the following command from the terminal.

pip install python-trading-robot

Setup - PyPi Upgrade:

To upgrade the library, run the following command from the terminal.

pip install --upgrade python-trading-robot

Usage

To run the robot, you will need to provide a few pieces of information from your TD Ameritrade Developer account. The following items are need for authentication:

  • Client ID: Also, called your consumer key, this was provided when you registered an app with the TD Ameritrade Developer platform. An example of a client ID could look like the following MMMMYYYYYA6444VXXXXBBJC3DOOOO.

  • Redirect URI: Also called the callbakc URL or redirect URL, this was specified by you when you regiestered your app with the TD Ameritrade Developer platform. Here is an example of a redirect URI https://localhost/mycallback

  • Credentials Path: This is a file path that will point to a JSON file where your state info will be saved. Keep in mind that it is okay if it points to a non-existing file as once you run the script the file will be auto generated. For example, if I want my state info to be saved to my desktop, then it would look like the following: C:\Users\Desktop\ts_state.json

Once you've identfied those pieces of info, you can run the robot. Here is a simple example that will create a new instance of it:

from pyrobot.robot import PyRobot

# Initialize the robot
trading_robot = PyRobot(
    client_id='XXXXXX111111YYYY22',
    redirect_uri='https://localhost/mycallback',
    credentials_path='path/to/td_state.json'
)

For more detailed examples, go to the trading_robot.py file to see an example of how to use the library along with all the different objects inside.

Support these Projects

Patreon: Help support this project and future projects by donating to my Patreon Page. I'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require me to pay monthly fees.

YouTube: If you'd like to watch more of my content, feel free to visit my YouTube channel Sigma Coding.

More Repositories

1

sigma_coding_youtube

This is a collection of all the code that can be found on my YouTube channel Sigma Coding.
Jupyter Notebook
963
star
2

td-ameritrade-python-api

Unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard API and allows users to build data pipelines for the Streaming API.
Python
684
star
3

interactive-broker-python-api

A python packaged used to interact with the Interactive Brokers REST API.
Python
321
star
4

python-sec

A simple python library that allows for easy access of the SEC website so that someone can parse filings, collect data, and query documents.
Python
116
star
5

td-ameritrade-api

The unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard REST API and Streaming API.
Python
109
star
6

tradestation-python-api

A Python Client library for the TradeStation API.
Python
88
star
7

finance-news-aggregator

A news aggregator in python, that focuses primarily on business and market news sources.
Python
68
star
8

interactive-brokers-api

A python application used to interact with the Interactive Brokers REST API.
Python
57
star
9

ms-graph-python-client

A Python Client Application that allows users to interact with the Microsoft Graph API.
Python
50
star
10

portfolio-optimization

A python application, that demonstrates optimizing a portfolio using machine learning.
Python
40
star
11

sigma-coding

This is a repository used for educational purposes to demonstrate how to upload a Python package to PyPi.
Python
39
star
12

power-bi-python-api

The Unofficial Python API wrapper for the Microsoft Power BI REST API.
Python
38
star
13

azure-sql-data-project

A python application that is used to create instances of SQL Server instances on Microsoft Azure, and insert data into those databases.
Python
30
star
14

excel-custom-function-add-in

A tutorial on how to build an Excel Custom Function Add-In using the new Office JavaScript API.
TypeScript
17
star
15

python-bureau-economic-analysis-api-client

A Python API client used to pull and retrieve data from the US Bureau of Economic Analysis
Python
13
star
16

azure-functions-http

A tutorial that covers how to use Azure functions using the python programming language.
Python
10
star
17

trading-system

A python application that leverages Microsoft Azure to build a fully functional trading system.
Python
10
star
18

us-federal-treasury-python-api

A Python application which is used to pull data from the United States Federal Treasury API.
Python
7
star
19

sigma-template

Serves as a template folder for other repos I create.
Python
7
star
20

us-federal-register-python-api

A python API client for the United States Federal Register.
Python
5
star
21

trading-factory

My Azure Data Factory for managing my trading system.
Python
5
star
22

youtube-python-client

A Python client library for the YouTube API.
Python
5
star
23

united-states-congress-python-api

A Python API client for the United States Congressional data found GovInfo.com.
Python
5
star
24

trade-robot

A python package that allows you to place automated trades using the TD Ameritrade API.
Python
4
star
25

us-federal-reserve-python-api

A Python application which is used to pull data from the US Federal Reserve.
Python
4
star
26

amzn-associates-api

A python API client library used to interact with the Amazon Associates Marketing API.
Python
3
star
27

sigma-utilities

Random Code I used to help with different projects.
Python
3
star
28

epa-scraper-project

This is a python project that collects and stores data from the EPA website.
3
star
29

tap-federal-reserve

A singer Tap for extracting data from the United States Federal Reserver API (FRED).
Python
3
star
30

python-for-starters

A guide on how to get up and running with Python, VSCode, Git, & GitHub on Windows.
Python
2
star
31

new-office-add-in

TypeScript
2
star
32

energy-scraper

A python program that will go and scrape EPA data.
2
star
33

sigma-azure-management

A Python project that demonstrates managing different Azure Services.
TSQL
2
star
34

gmail-api-python

A Python project that uses the Gmail API in Python.
Python
2
star
35

trading-data-factory

A Python Application that leverages the Azure Data Factory to store trading data.
Python
2
star
36

azure-and-terraform

Terraform modules used to create Azure resources for other projects.
HCL
1
star
37

interview-items

A collection of items I use for interview purposes.
Jupyter Notebook
1
star
38

logistic-regression-model-stocks

Python
1
star
39

docker-trading-data-workflow

A docker application used to collect price data using a docker image.
Python
1
star
40

excel-python-com-server

Demonstrates how to create a Python COM Server using the Win32COM library.
Python
1
star