Documentation ¶
Overview ¶
Package ndl implements generic table API of Nasdaq Data Link (NDL).
Official documentation is at https://docs.data.nasdaq.com/docs/tables-1 .
Each NDL table has a schema, which is the list of column names and their types, in the order they appear in the table. This schema can be obtained for the originial table using FetchTableMetadata(). The relevant schema is also included in each downloaded table page, which may be a subset of the full schema if only a subset of columns was requested.
The raw NDL API can return only up to 10K rows in a single page. However, the JSON format used in this package includes a cursor for the next page, thus allowing paging when downloading more than 10K rows. This package implements transparent paging in RowIterator.
APIs for specific providers and products, such as Sharadar Equities and ETFs, are implemented in the subpackages.
Index ¶
- Constants
- Variables
- func TestTablePage(data [][]Value, schema Schema, cursor string) (string, error)
- func UseClient(ctx context.Context, apiKey string) context.Context
- type BulkDownloadHandle
- type CSVReader
- type Client
- type DatatableMeta
- type DownloadMonitorFactory
- type RowIterator
- type Schema
- type SchemaField
- type TableMetadata
- type TableQuery
- func (q *TableQuery) Columns(columns ...string) *TableQuery
- func (q *TableQuery) Copy() *TableQuery
- func (q *TableQuery) Cursor(cursor string) *TableQuery
- func (q *TableQuery) Equal(column string, values ...string) *TableQuery
- func (q *TableQuery) Ge(column string, value string) *TableQuery
- func (q *TableQuery) Gt(column string, value string) *TableQuery
- func (q *TableQuery) Le(column string, value string) *TableQuery
- func (q *TableQuery) Lt(column string, value string) *TableQuery
- func (q *TableQuery) Path() string
- func (q *TableQuery) PerPage(size int) *TableQuery
- func (q *TableQuery) Read(ctx context.Context) *RowIterator
- func (q *TableQuery) Values() url.Values
- type TableStatus
- type TableVersion
- type Value
- type ValueLoader
Constants ¶
const ( StatusFresh = "fresh" StatusRegenerating = "regenerating" StatusCreating = "creating" )
Values of the Status field of BulkDownloadHandle.
Variables ¶
var URL = "https://data.nasdaq.com/api/v3"
URL is the default base URL of the server. It may be overwritten in tests before creating a new client.
Functions ¶
func TestTablePage ¶
TestTablePage generates the JSON string in a format as returned by the NDL Table API. For use in tests.
Types ¶
type BulkDownloadHandle ¶
type BulkDownloadHandle struct { Link string Status string SnapshotTime string LastRefreshedTime string MonitorFactory DownloadMonitorFactory // contains filtered or unexported fields }
BulkDownloadHandle is a simplified result of the first asynchronous bulk download call.
func BulkDownload ¶
func BulkDownload(ctx context.Context, table string) (*BulkDownloadHandle, error)
BulkDownload receives the bulk download metadata with the data link.
type CSVReader ¶
type CSVReader struct {
// contains filtered or unexported fields
}
CSVReader implements a streaming CSV reader, one row at a time, with a Close() method to release its resources.
func BulkDownloadCSV ¶
func BulkDownloadCSV(ctx context.Context, h *BulkDownloadHandle) (*CSVReader, error)
BulkDownloadCSV starts downloading the actual data pointed to by BulkDownloadHandle. It downloads the zip archive with a single CSV file into memory, and returns a CSVReader which streams the contents of that file. When error is nil, make sure to call CSVReader.Close() when done with the CSV stream.
func (*CSVReader) AddCloser ¶
AddCloser to the list of closers. Method Close() will call each registered closer in LIFO order.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for querying NDL tables and time-series.
type DatatableMeta ¶
type DatatableMeta struct { VendorCode string `json:"vendor_code"` TableCode string `json:"datatable_code"` Name string `json:"name"` Description string `json:"description"` Schema Schema `json:"columns"` Filters []string `json:"filters"` PrimaryKey []string `json:"primary_key"` Premium bool `json:"premium"` Status TableStatus `json:"status"` Version TableVersion `json:"data_version"` }
DatatableMeta is the JSON struct for the table metadata.
type DownloadMonitorFactory ¶
type DownloadMonitorFactory = func(*http.Response) io.ReadCloser
DownloadMonitorFactory creates a pass-through io.Reader from http.Response.Body which allows to monitor bulk data download progress.
func LoggingMonitorFactory ¶
func LoggingMonitorFactory(ctx context.Context, name string, interval int64) DownloadMonitorFactory
LoggingMonitorFactory is the default download monitor factory which logs the progress report of data identified by name every interval bytes. If interval is not positive, it is set to 10MB.
type RowIterator ¶
type RowIterator struct {
// contains filtered or unexported fields
}
RowIterator iterates over query results row by row. Paging is handled transparently.
func (*RowIterator) Next ¶
func (it *RowIterator) Next(row ValueLoader) (bool, error)
Next loads the next row. If there are no more rows, the second value is false. Note, that error may be non-nil regardless of the end of iterator.
type Schema ¶
type Schema []SchemaField
Schema definition for a table.
func (Schema) MapCSVColumns ¶
MapCSVColumns creates a map of {field name -> CSV column index} based on the CSV header. Every schema field must be present in the header, otherwise it's an error.
type SchemaField ¶
SchemaField is the schema definition for a single table column.
type TableMetadata ¶
type TableMetadata struct {
Datatable DatatableMeta `json:"datatable"`
}
TableMetadata is the format returned by the metadata API.
func FetchTableMetadata ¶
func FetchTableMetadata(ctx context.Context, table string) (*TableMetadata, error)
FetchTableMetadata obtains metadata about the requested table specified as PUBLISHER/TABLE.
type TableQuery ¶
type TableQuery struct {
// contains filtered or unexported fields
}
TableQuery is a builder for a table query.
func NewTableQuery ¶
func NewTableQuery(table string) *TableQuery
NewTableQuery creates a new query.
func (*TableQuery) Columns ¶
func (q *TableQuery) Columns(columns ...string) *TableQuery
Columns constraints the query result to only these columns.
func (*TableQuery) Copy ¶
func (q *TableQuery) Copy() *TableQuery
Copy creates a deep copy of the query. It is primarily used in its builder methods.
func (*TableQuery) Cursor ¶
func (q *TableQuery) Cursor(cursor string) *TableQuery
Cursor sets the cursor ID for a paging query.
func (*TableQuery) Equal ¶
func (q *TableQuery) Equal(column string, values ...string) *TableQuery
Equal adds an equality filter: the value of the column must equal one of the given values. This and other builder methods always create a deep copy of the query, leaving the original intact.
func (*TableQuery) Ge ¶
func (q *TableQuery) Ge(column string, value string) *TableQuery
Ge adds a strict inequality filter: a numerical column's value must be >= value.
func (*TableQuery) Gt ¶
func (q *TableQuery) Gt(column string, value string) *TableQuery
Gt adds a strict inequality filter: a numerical column's value must be > value.
func (*TableQuery) Le ¶
func (q *TableQuery) Le(column string, value string) *TableQuery
Le adds a strict inequality filter: a numerical column's value must be <= value.
func (*TableQuery) Lt ¶
func (q *TableQuery) Lt(column string, value string) *TableQuery
Lt adds a strict inequality filter: a numerical column's value must be < value.
func (*TableQuery) Path ¶
func (q *TableQuery) Path() string
Path returns the URL path to add to the base URL.
func (*TableQuery) PerPage ¶
func (q *TableQuery) PerPage(size int) *TableQuery
PerPage sets the maximum number of results in a single response, [0..10000].
func (*TableQuery) Read ¶
func (q *TableQuery) Read(ctx context.Context) *RowIterator
Read sets up the iterator over the result rows, which will execute the query as needed and handle paging transparently.
func (*TableQuery) Values ¶
func (q *TableQuery) Values() url.Values
Values returns the query values for the query. Each call creates a new object, so the caller is free to modify it without affecting the query.
type TableStatus ¶
type TableStatus struct { RefreshedAt db.Time `json:"refreshed_at"` Status string `json:"status"` ExpectedAt string `json:"expected_at"` UpdateFrequency string `json:"update_frequency"` }
TableStatus is a part of DatatableMeta.
type TableVersion ¶
type TableVersion struct { Code string `json:"code"` Default bool `json:"default"` Description string `json:"description"` }
TableVersion is a part of DatatableMeta.
type ValueLoader ¶
ValueLoader is the interface that a row type of a specific table must implement.
Directories ¶
Path | Synopsis |
---|---|
Package sharadar implements specific schemas and methods for downloading Sharadar equity and fund prices tables through Nasdaq Data Link.
|
Package sharadar implements specific schemas and methods for downloading Sharadar equity and fund prices tables through Nasdaq Data Link. |