Git Product home page Git Product logo

go-tda's Introduction

go-tda

Go Reference Go Report Card License

Latest: v0.8.3 | Stable*: v0.8.3

  • *(Suggested Pre-v1.0.0)

what is this project?

this is a go implementation of a td-ameritrade API hook. the goal of this project is to incentivize others to build algorithmic trading models on top of these packages. the purpose for this projects existence is really speed; a lot of td-ameritrade hooks are built in Python, which is fine, but they are so unbelievably slow. when you have to wait multiple seconds to make a request, you know it's bad. we have built an incredibly light handler function that routes all calls in the library, making speeds predictable and lightning fast. this, on top of well optimized and efficient Marshaling of JSON to custom Structs, means that you can make up to 15 requests per second if you wish.

  • the average response times for all functions in this library is 152ms (weighted average of over 100,000 test requests)
  • a light function like RealTime can achieve request times as low as 80ms

how can i use this project?

quick start

  1. go to developer.tdameritrade.com and register for an account
  • optionally, if you'd like to trade using the trade package, you will have to register for a td-ameritrade brokerage account - this is NOT neccesary, as you can use the data from tda to trade on any platform you wish
  1. create an app on td ameritrade developer at https://developer.tdameritrade.com/user/me/apps, or by going to the My Apps tab while logged in

  2. go to your app (once it has been approved), and get the api key under the "Consumer Key" section

  • create a file called tda-config.env
  • move that file to your $HOME directory (~/)
  • edit the file and add the following information in the format:
APIKEY=Your_APIKEY_Here
UTC_DIFF=+0:00 // This is a placeholder; for MST, you would use -06:00, etc. It is your Difference from UTC time
  1. go get github.com/samjtro/go-tda
  • you're now ready to go! import the library by package ( github.com/samjtro/go-tda/data for the data package, for instance )
  • if you have any questions, check the go reference; or, scroll down to the code samples below

package details

  • data: contains RealTime and PriceHistory; used for getting either a RealTime quote of a ticker, or a long-term PriceHistory dataframe of a stock from tda (most common use-case)
  • movers: contains Get; returns a list of movers for the day by index & direction
  • option: contains Single; returns Option Chains of your desired parameters
  • instrument: contains Fundamental & Get; returns information on a desired ticker or CUSIP
  • account will contain account monitoring and trading functions but is not functional as of right now

if you still have a question about something after checking the go reference and code samples, or something isn't quite working right, either file an issue or a pull request on the repo OR send me an email @ [email protected]

code samples

data package

quote, err := data.RealTime("AAPL")

if err != nil {
        panic(err)
}

df, err := data.PriceHistory("AAPL", "month", "1", "daily", "1")

if err != nil {
        panic(err)
}

instrument package

simple, err := instrument.Simple("AAPL")

if err != nil {
	panic(err)
}

fundamental, err = instrument.Fundamental("AAPL")

if err != nil {
	panic(err)
}

movers package

movers, err := movers.Get("$DJI", "up", "percent")

if err != nil {
	panic(err)
}

option package

single, err := option.Single("AAPL", "ALL", "ALL", "15", "2022-09-20")

if err != nil {
	panic(err)
}

what can i do with this project?

like previously mentioned, the goal is for you to use this in a wide variety of capacities. do what you wish with this project, but...

see the license; it is permissive, there are guidelines for proper reproduction & crediting :)

go-tda's People

Contributors

samjtro avatar

Stargazers

 avatar  avatar

Watchers

 avatar

go-tda's Issues

Continuous Integration for testing new commits

I am building a Github Actions workflow to utilize credentials from a testing app on developer.tdameritrade.com in order to test new commits. The main reason for this is to ensure the integrity of new commits; if more people start working on this project, that will be a requirement. It will essentially just run the go tests I've already built out in the test folder with the credentials from the testing app to authenticate the requests, that way on every commit you are required to have tested (something not all people tend to do). It will also enable us to share the status of the repo in the Readme, in case a legitimate need for breaking the code has been introduced.

Development of this workflow is happening here: branch:testing-ci

Any help would be greatly appreciated! I have finished the go.yml for general testing (easy), but need to figure out the best way to store the tda-config.env file securely (might involve editing the utils.go file to enable placing the .env file in the repo itself).

GetBearerToken & authenticated requests for account package / trading functionality

For trading & general account functionality, you need a Bearer Token for the TD-Ameritrade API. I need to do more research into how it works, but the gist I've gotten so far is that you are issued one for 30 minutes to execute trades, create / delete / modify watchlists, etc. This is a separate authentication from the general API which makes the requests for the rest of the packages in this library, which is just based on an API Key issued through developer.tdameritrade.com.

I haven't gotten this secondary authentication to work. GetBearerToken() was supposed to do this function, but it does not. I am also confused as to where we are supposed to be authenticating through for the username/password for the TD-Ameritrade brokerage account, there is no explanation anywhere in the documentation for the API.

I need to do some more digging for this. Current code for GetBearerToken is below:

func GetBearerToken(accountID string) (string, error) {
	req, _ := http.NewRequest("GET", endpoint_bearer, nil)
	q := req.URL.Query()
	q.Add("grant_type", "authorization_code")
	q.Add("client_id", accountID)
	req.URL.RawQuery = q.Encode()
	resp, err := utils.Handler(req)

	if err != nil {
		return "", err
	}

	body := fmt.Sprintf("Bearer <%s>", resp)

	return body, nil
}

Custom structs for strategy spreads

Need to decide on a path forward for these sooner rather than later. Functions will either be individually typed (ie func Butterfly() []BUTTERFLY {}) OR grouped (ie func Butterfly() []STRATEGY {}). Need to do research into what the responses will look like from tda in all circumstances. If there are significant differences, individually typed but if not, group it.

account woes

GetBearerToken refuses to work. I am not entirely sure what I am doing wrong, but I predict it is something to do with the request validity. I am screwing up some parameters somewhere and it's annoying me. Will have to do more testing privately, but for now I can't move on with any other account modules.
trade is going well. I have most of the strings, as well as the endpoints & Place function ready to go, and as soon as I fix the Bearer Token API call, I will be able to start trading (I think). The only worry I have is in my http.POST configuration. I haven't used http.POST extensively before, and I'm worried the setup I have is going to cause errors. But until I have the Bearer, who knows.

Documentation updates

Update documentation for all major packages. It has fallen far behind since v0.5.0 and it needs some major revisions.

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.