Categorygithub.com/timothycsanders/go-tradier
modulepackage
1.0.0
Repository: https://github.com/timothycsanders/go-tradier.git
Documentation: pkg.go.dev

# README

go-tradier

A Go library for accessing the Tradier Developer API.

GoDoc Build Status Coverage Status

go-tradier is a library to access the Tradier Developer API from Go. It provides a thin wrapper for working with the JSON REST endpoints.

Tradier is the first Brokerage API company, powering the world's leading trading, investing and digital advisor platforms. Tradier is not affiliated and does not endorse or recommend this library.

Usage

tcli

The tcli tool is a small command-line interface for making requests.

$ go install github.com/gnagel/go-tradier/tcli
$ tcli -tradier.account XXXXX -tradier.apikey XXXXX -command positions

Fetch real-time top-of-book quotes

package main

import (
  "fmt"

  "github.com/gnagel/go-tradier"
)

func main() {
  params := tradier.DefaultParams("your-api-key-here")
  client := tradier.NewClient(params)

  quotes, err := client.GetQuotes([]string{"AAPL", "SPY"})
  if err != nil {
    panic(err)
  }

  for _, quote := range quotes {
    fmt.Printf("%v: bid $%.02f (%v shares), ask $%.02f (%v shares)\n",
      quote.Symbol, quote.Bid, quote.BidSize, quote.Ask, quote.AskSize)
  }
}

Stream real-time top-of-book trades and quotes (L1 TAQ) data.

package main

import (
	"fmt"

	"github.com/gnagel/go-tradier"
)

func main() {
	params := tradier.DefaultParams("your-api-key-here")
	client := tradier.NewClient(params)

	eventsReader, err := client.StreamMarketEvents(
		[]string{"AAPL", "SPY"},
		[]tradier.Filter{tradier.FilterQuote, tradier.FilterTrade})
	if err != nil {
		panic(err)
	}

	eventsCh := make(chan *tradier.StreamEvent)
	eventStream := tradier.NewMarketEventStream(eventsReader, eventsCh)
	defer eventStream.Stop()

	demuxer := tradier.StreamDemuxer{
		Quotes: func(quote *tradier.QuoteEvent) {
			fmt.Printf("QUOTE %v: bid $%.02f (%v shares), ask $%.02f (%v shares)\n",
				quote.Symbol, quote.Bid, quote.BidSize, quote.Ask, quote.AskSize)
		},
		Trades: func(trade *tradier.TradeEvent) {
			fmt.Printf("TRADE %v: $%.02f (%v shares) at %v\n",
				trade.Symbol, trade.Price, trade.Size, trade.DateMs)
		},
	}

	demuxer.HandleChan(eventsCh)
}

Place and then cancel an order for SPY.

package main

import (
	"fmt"
	"time"

	"github.com/gnagel/go-tradier"
)

func main() {
	params := tradier.DefaultParams("your-api-key-here")
	client := tradier.NewClient(params)
	client.SelectAccount("your-account-id-here")

	// Place a limit order for 1 share of SPY at $1.00.
	orderId, err := client.PlaceOrder(tradier.Order{
		Class:    tradier.Equity,
		Type:     tradier.LimitOrder,
		Symbol:   "SPY",
		Side:     tradier.Buy,
		Quantity: 1,
		Price:    1.00,
		Duration: tradier.Day,
	})
	if err != nil {
		panic(err)
	}
	fmt.Printf("Placed order: %v\n", orderId)

	time.Sleep(2 * time.Second)
	order, err := client.GetOrderStatus(orderId)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Order status: %v\n", order.Status)

	// Cancel the order.
	fmt.Printf("Canceling order: %v\n", orderId)
	if err := client.CancelOrder(orderId); err != nil {
		panic(err)
	}
}

Contributing

Pull requests and issues are welcomed!

License

go-tradier is released under the GNU Lesser General Public License, Version 3.0

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DefaultParams returns ClientParams initialized with default values.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
Order sides.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Order durations.
No description provided by the author
Order classes.
Error returned by Tradier if we make too big of a request.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Order types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Option types.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Order statuses.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrNoAccountSelected is returned if account-specific methods are attempted to be used without selecting an account first.
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client provides methods for making requests to the Tradier API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DateTime wraps time.Time and adds flexible implementations for unmarshaling JSON in the different forms it appears in the Tradier API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MarketEventStream scans the newline-delimited market stream sent by Tradier and decodes each event into a StreamEvent.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StreamDemuxer demuxes the different types of messages in a market events stream.
StreamEvent is used to unmarshal stream events before they are demuxed.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
If there is only a single event, then tradier sends back an object, but if there are multiple events, then it sends a list of objects...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
If there is only a single event, then tradier sends back an object, but if there are multiple events, then it sends a list of objects...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author