activetick

package module
v0.0.0-...-4e8f760 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2017 License: LGPL-3.0 Imports: 7 Imported by: 0

README

go-activetick

A Go library for accessing the ActiveTick HTTP API.

GoDoc Build Status Coverage Status

go-activetick is a library to access the ActiveTick HTTP API from Go.

ActiveTick is not affiliated and does not endorse or recommend this library.

Usage

atclient CLI
$ atclient -symbol SPY -begin_time 2016-10-04T14:30:00Z -end_time 2016-10-04T14:40:00Z -type tick
Fetch historical minute bars
package main

import (
    "fmt"
    "net/http"
    "time"

    "github.com/timpalpant/go-activetick"
)

func main() {
    endpoint := "http://localhost:5000"
    client := activetick.NewPagingClient(activetick.NewClient(&http.Client{}, endpoint))

	req := &activetick.BarDataRequest{
		Symbol:          "SPY",
		HistoryType:     activetick.HistoryTypeIntraday,
		IntradayMinutes: 1,
		BeginTime:       time.Now().Add(-48 * time.Hour),
		EndTime:         time.Now().Add(-47 * time.Hour),
	}

	resp, err := client.GetBarData(req)
	if err != nil {
		log.Fatal(err)
	}

	for _, record := range resp.Records {
		fmt.Printf("%v,%v,%v,%v,%v,%v\n", record.Time, record.Open,
			record.High, record.Low, record.Close, record.Volume)
	}
}
Fetch historical ticks
package main

import (
    "fmt"
    "net/http"

    "github.com/timpalpant/go-activetick"
)

func main() {
    endpoint := "http://localhost:5000"
    client := activetick.NewPagingClient(activetick.NewClient(&http.Client{}, endpoint))

	req := &activetick.TickDataRequest{
		Symbol:    "SPY",
		BeginTime: time.Now().Add(-48 * time.Hour),
		EndTime:   time.Now().Add(-47 * time.Hour),
		Trades:    true,
		Quotes:    true,
	}

	resp, err := client.GetTickData(req)
	if err != nil {
		log.Fatal(err)
	}

	for _, record := range resp.Records {
		if record.Type == activetick.TickTypeQuote {
			fmt.Printf("%v,%v,%v,%v,%v,%v,%v\n", record.Time,
				record.BidPrice, record.BidSize, record.BidExchange,
				record.AskPrice, record.AskSize, record.AskExchange)
		} else {
			fmt.Printf("%v,%v,%v,%v\n", record.Time,
				record.LastPrice, record.LastSize, record.LastExchange)
		}
	}
}

Contributing

Pull requests and issues are welcomed!

License

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

Documentation

Overview

Package activetick provides an API for accessing and using the ActiveTick HTTP API.

http://www.activetick.com/activetick/contents/PersonalServicesDataAPIOverview.aspx

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarDataRecord

type BarDataRecord struct {
	Time   time.Time
	Open   float64
	High   float64
	Low    float64
	Close  float64
	Volume int64
}

type BarDataRequest

type BarDataRequest struct {
	Symbol          string
	HistoryType     HistoryType
	IntradayMinutes int
	BeginTime       time.Time
	EndTime         time.Time
}

type BarDataResponse

type BarDataResponse struct {
	Records []*BarDataRecord
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods to interact with the ActiveTick HTTP API. TODO: Implement snapshot quotes (/quoteData) and streaming quotes (/quoteStream).

func NewClient

func NewClient(client *http.Client, endpoint string) *Client

func (*Client) GetBarData

func (c *Client) GetBarData(req *BarDataRequest) (*BarDataResponse, error)

func (*Client) GetTickData

func (c *Client) GetTickData(req *TickDataRequest) (*TickDataResponse, error)

type DataItemType

type DataItemType int
const (
	DataByte          DataItemType = 1
	DataByteArray     DataItemType = 2
	DataUInteger32    DataItemType = 3
	DataUInteger64    DataItemType = 4
	DataInteger32     DataItemType = 5
	DataInteger64     DataItemType = 6
	DataPrice         DataItemType = 7
	DataString        DataItemType = 8
	DataUnicodeString DataItemType = 9
	DataDateTime      DataItemType = 10
	DataDouble        DataItemType = 11
)

type Exchange

type Exchange string
const (
	ExchangeAMEX                            Exchange = "A"
	ExchangeNasdaqOmxBx                     Exchange = "B"
	ExchangeNationalStockExchange           Exchange = "C"
	ExchangeFinraAdf                        Exchange = "D"
	ExchangeCQS                             Exchange = "E"
	ExchangeForex                           Exchange = "F"
	ExchangeInternationalSecuritiesExchange Exchange = "I"
	ExchangeEdgaExchange                    Exchange = "J"
	ExchangeEdgxExchange                    Exchange = "K"
	ExchangeChicagoStockExchange            Exchange = "M"
	ExchangeNyseEuronext                    Exchange = "N"
	ExchangeNyseArcaExchange                Exchange = "P"
	ExchangeNasdaqOmx                       Exchange = "Q"
	ExchangeCTS                             Exchange = "S"
	ExchangeCTANasdaqOMX                    Exchange = "T"
	ExchangeOTCBB                           Exchange = "U"
	ExchangeNNOTC                           Exchange = "u"
	ExchangeChicagoBoardOptionsExchange     Exchange = "W"
	ExchangeNasdaqOmxPhlx                   Exchange = "X"
	ExchangeBatsYExchange                   Exchange = "Y"
	ExchangeBatsExchange                    Exchange = "Z"
	ExchangeCanadaToronto                   Exchange = "T"
	ExchangeCanadaVenture                   Exchange = "V"
	ExchangeComposite                       Exchange = " "
)

type HistoryType

type HistoryType int
const (
	HistoryTypeIntraday HistoryType = 0
	HistoryTypeDaily    HistoryType = 1
	HistoryTypeWeekly   HistoryType = 2
)

type OptionChainRequest

type OptionChainRequest struct {
	Symbol string
}

type OptionChainResponse

type OptionChainResponse struct {
	Records []string
}

type PagingClient

type PagingClient struct {
	// contains filtered or unexported fields
}

PagingClient wraps Client to automatically manage multiple paged requests.

func NewPagingClient

func NewPagingClient(client *Client) *PagingClient

func (*PagingClient) GetBarData

func (pc *PagingClient) GetBarData(req *BarDataRequest) (*BarDataResponse, error)

The HTTP API will return at most 20,000 records. If there are more than that, only the latest 20,000 in time are returned. So to fetch all data we need to page backward.

func (*PagingClient) GetTickData

func (pc *PagingClient) GetTickData(req *TickDataRequest) (*TickDataResponse, error)

The HTTP API will return at most 100,000 ticks. If there are more than that, only the first 100,000 in time are returned. So to fetch all data we need to page forward.

type QuoteDataRequest

type QuoteDataRequest struct {
	Symbols     []string
	QuoteFields []QuoteField
}

type QuoteDataResponse

type QuoteDataResponse struct {
	Records []*QuoteSnapshotRecord
}

type QuoteField

type QuoteField int
const (
	QuoteFieldSymbol                           QuoteField = 1
	QuoteFieldOpenPrice                        QuoteField = 2
	QuoteFieldPreviousClosePrice               QuoteField = 3
	QuoteFieldClosePrice                       QuoteField = 4
	QuoteFieldLastPrice                        QuoteField = 5
	QuoteFieldBidPrice                         QuoteField = 6
	QuoteFieldAskPrice                         QuoteField = 7
	QuoteFieldHighPrice                        QuoteField = 8
	QuoteFieldLowPrice                         QuoteField = 9
	QuoteFieldDayHighPrice                     QuoteField = 10
	QuoteFieldDayLowPrice                      QuoteField = 11
	QuoteFieldPreMarketOpenPrice               QuoteField = 12
	QuoteFieldExtendedHoursLastPrice           QuoteField = 13
	QuoteFieldAfterMarketClosePrice            QuoteField = 14
	QuoteFieldBidExchange                      QuoteField = 15
	QuoteFieldAskExchange                      QuoteField = 16
	QuoteFieldLastExchange                     QuoteField = 17
	QuoteFieldLastCondition                    QuoteField = 18
	QuoteFieldQuoteCondition                   QuoteField = 19
	QuoteFieldLastTradeDateTime                QuoteField = 20
	QuoteFieldLastQuoteDateTime                QuoteField = 21
	QuoteFieldDayHighDateTime                  QuoteField = 22
	QuoteFieldDayLowDateTime                   QuoteField = 23
	QuoteFieldLastSize                         QuoteField = 24
	QuoteFieldBidSize                          QuoteField = 25
	QuoteFieldAskSize                          QuoteField = 26
	QuoteFieldVolume                           QuoteField = 27
	QuoteFieldPreMarketVolume                  QuoteField = 28
	QuoteFieldAfterMarketVolume                QuoteField = 29
	QuoteFieldTradeCount                       QuoteField = 30
	QuoteFieldPreMarketTradeCount              QuoteField = 31
	QuoteFieldAfterMarketTradeCount            QuoteField = 32
	QuoteFieldFundamentalEquityName            QuoteField = 33
	QuoteFieldFundamentalEquityPrimaryExchange QuoteField = 34
)

type QuoteSnapshotRecord

type QuoteSnapshotRecord struct {
	Symbol                           string
	OpenPrice                        float64
	PreviousClosePrice               float64
	ClosePrice                       float64
	LastPrice                        float64
	BidPrice                         float64
	AskPrice                         float64
	HighPrice                        float64
	LowPrice                         float64
	DayHighPrice                     float64
	DayLowPrice                      float64
	PreMarketOpenPrice               float64
	ExtendedHoursLastPrice           float64
	AfterMarketClosePrice            float64
	BidExchange                      Exchange
	AskExchange                      Exchange
	LastExchange                     Exchange
	LastCondition                    int
	QuoteCondition                   int
	LastTradeTime                    time.Time
	LastQuoteTime                    time.Time
	DayHighTime                      time.Time
	DayLowTime                       time.Time
	LastSize                         int
	BidSize                          int
	AskSize                          int
	Volume                           int
	PreMarketVolume                  int
	AfterMarketVolume                int
	TradeCount                       int
	PreMarketTradeCount              int
	AfterMarketTradeCount            int
	FundamentalEquityName            string
	FundamentalEquityPrimaryExchange Exchange
}

type QuoteStreamRecord

type QuoteStreamRecord struct {
	Symbol         string
	QuoteCondition int
	BidExchange    Exchange
	AskExchange    Exchange
	BidPrice       float64
	AskPrice       float64
	BidSize        int
	AskSize        int
	QuoteTime      time.Time
}

type QuoteStreamRequest

type QuoteStreamRequest struct {
	Symbols []string
}

type SymbolStatus

type SymbolStatus int
const (
	SymbolStatusSuccess      SymbolStatus = 1
	SymbolStatusInvalid      SymbolStatus = 2
	SymbolStatusUnavailable  SymbolStatus = 3
	SymbolStatusNoPermission SymbolStatus = 4
)

type TickDataRequest

type TickDataRequest struct {
	Symbol    string
	Trades    bool
	Quotes    bool
	BeginTime time.Time
	EndTime   time.Time
}

type TickDataResponse

type TickDataResponse struct {
	Records []*TickRecord
}

type TickRecord

type TickRecord struct {
	Type         TickType
	Time         time.Time
	LastPrice    float64
	LastSize     int64
	LastExchange Exchange
	Condition    [4]TradeCondition
	BidPrice     float64
	AskPrice     float64
	BidSize      int64
	AskSize      int64
	BidExchange  Exchange
	AskExchange  Exchange
}

type TickType

type TickType string
const (
	TickTypeQuote TickType = "Q"
	TickTypeTrade TickType = "T"
)

type TradeCondition

type TradeCondition int
const (
	TradeConditionRegular                       TradeCondition = 0
	TradeConditionAcquisition                   TradeCondition = 1
	TradeConditionAveragePrice                  TradeCondition = 2
	TradeConditionAutomaticExecution            TradeCondition = 3
	TradeConditionBunched                       TradeCondition = 4
	TradeConditionBunchSold                     TradeCondition = 5
	TradeConditionCAPElection                   TradeCondition = 6
	TradeConditionCash                          TradeCondition = 7
	TradeConditionClosing                       TradeCondition = 8
	TradeConditionCross                         TradeCondition = 9
	TradeConditionDerivativelyPriced            TradeCondition = 10
	TradeConditionDistribution                  TradeCondition = 11
	TradeConditionFormT                         TradeCondition = 12
	TradeConditionFormTOutOfSequence            TradeCondition = 13
	TradeConditionInterMarketSweep              TradeCondition = 14
	TradeConditionMarketCenterOfficialClose     TradeCondition = 15
	TradeConditionMarketCenterOfficialOpen      TradeCondition = 16
	TradeConditionMarketCenterOpening           TradeCondition = 17
	TradeConditionMarketCenterReOpenning        TradeCondition = 18
	TradeConditionMarketCenterClosing           TradeCondition = 19
	TradeConditionNextDay                       TradeCondition = 20
	TradeConditionPriceVariation                TradeCondition = 21
	TradeConditionPriorReferencePrice           TradeCondition = 22
	TradeConditionRule155Amex                   TradeCondition = 23
	TradeConditionRule127Nyse                   TradeCondition = 24
	TradeConditionOpening                       TradeCondition = 25
	TradeConditionOpened                        TradeCondition = 26
	TradeConditionRegularStoppedStock           TradeCondition = 27
	TradeConditionReOpening                     TradeCondition = 28
	TradeConditionSeller                        TradeCondition = 29
	TradeConditionSoldLast                      TradeCondition = 30
	TradeConditionSoldLastStoppedStock          TradeCondition = 31
	TradeConditionSoldOutOfSequence             TradeCondition = 32
	TradeConditionSoldOutOfSequenceStoppedStock TradeCondition = 33
	TradeConditionSplit                         TradeCondition = 34
	TradeConditionStockOption                   TradeCondition = 35
	TradeConditionYellowFlag                    TradeCondition = 36
)

type TradeFlag

type TradeFlag int
const (
	TradeFlagRegularMarketLastPrice  TradeFlag = 0x1
	TradeFlagRegularMarketVolume     TradeFlag = 0x2
	TradeFlagHighPrice               TradeFlag = 0x4
	TradeFlagLowPrice                TradeFlag = 0x8
	TradeFlagDayHighPrice            TradeFlag = 0x10
	TradeFlagDayLowPrice             TradeFlag = 0x20
	TradeFlagExtendedMarketLastPrice TradeFlag = 0x40
	TradeFlagPreMarketVolume         TradeFlag = 0x80
	TradeFlagAfterMarketVolume       TradeFlag = 0x100
	TradeFlagPreMarketOpenPrice      TradeFlag = 0x200
	TradeFlagOpenPrice               TradeFlag = 0x400
)

type TradeStreamRecord

type TradeStreamRecord struct {
	Symbol          string
	Flags           TradeFlag
	TradeConditions [4]TradeCondition
	LastExchange    Exchange
	LastPrice       float64
	LastSize        int
	LastDate        time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL