Categorygithub.com/MarketDataApp/sdk-go
modulepackage
0.1.0
Repository: https://github.com/marketdataapp/sdk-go.git
Documentation: pkg.go.dev

# README

Market Data's Official Go SDK

:warning: Pre-Alpha Version: This SDK is currently in development and is not stable. Not currently suitable for client use.

GoDoc Go Report Card Tests and linters Coverage License SDK Version GitHub go.mod Go version

Connect With The Market Data Community

Discord Twitter Helpdesk

Installation

To install the SDK, you can use the following command:

go get github.com/MarketDataApp/sdk-go

After installation, you can import it in your project like this:

import api "github.com/MarketDataApp/sdk-go"

Endpoints Status:

Endpoint CategoryEndpointv1 Statusv2 Status
MarketsStatus
StocksCandles
StocksQuotes
StocksEarnings
StocksTickers
StocksNews
OptionsExpirations
OptionsLookup
OptionsStrikes
OptionsOption Chain
OptionsQuotes
IndicesCandles
IndicesQuotes

Note on v2: Even though some v2 endpoints are available for use in this SDK, Market Data has not yet released v2 of its API for clients and v2 usage is restricted to admins only. Clients should onlly use v1 endpoints at this time. Even after v2 is released, we do not plan on deprecating v1 endpoints, so please build your applications with confidence using v1 endpoints.

Example Usage

See the examples files for each data type for examples of how to use each endpoint.

Authentication

To authenticate with the Market Data API, you need to set your token, which should have been e-mailed to you when you first signed up for an account. If you do not have a token, request a new one from the Market Data Dashboard. Set the token in the environment variable MARKETDATA_TOKEN. Alternatively, you can hardcode it in your code, but please be aware that this is not secure and could pose a risk if your code is shared.

export MARKETDATA_TOKEN="<your_api_token>"   # mac/linux
setx MARKETDATA_TOKEN "<your_api_token>"     # windows

Logging

The SDK systematically logs API responses to facilitate troubleshooting and analysis, adhering to the following rules:

  • Client Errors: Responses with status codes in the range 400-499 are logged to client_error.log.
  • Server Errors: Responses with status codes in the range 500-599 are logged to server_error.log.
  • Successful Requests: If debug mode is activated, responses with status codes in the range 200-299 are logged to success.log.

All log files are formatted in JSON and stored within the /logs directory. Each entry captures comprehensive details including the request URL, request headers, CF Ray ID (a unique identifier for the request), response status code, response headers, and the response body, providing a full context for each logged event.

Example of a log entry:

{
  "level":"info",
  "ts":"2024-01-25T15:34:10.642-0300",
  "msg":"Successful Request",
  "cf_ray":"84b29bd46f468d96-MIA",
  "request_url":"https://api.marketdata.app/v1/stocks/quotes/AAPL/",
  "ratelimit_consumed":0,
  "response_code":200,
  "delay_ms":254,
  "request_headers":{
    "Authorization": ["Bearer **********************************************************HMD0"],
    "User-Agent": ["sdk-go/0.0.4"]
  },
  "response_headers": {
    "Allow": ["GET, HEAD, OPTIONS"],
    "Alt-Svc": ["h3=\":443\"; ma=86400"],
    "Cf-Cache-Status": ["DYNAMIC"],
    "Cf-Ray": ["84b29bd46f468d96-MIA"],
    "Content-Type": ["application/json"],
    "Cross-Origin-Opener-Policy": ["same-origin"],
    "Date": ["Thu, 25 Jan 2024 18:34:10 GMT"],
    "Nel": ["{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}"],
    "Referrer-Policy": ["same-origin"],
    "Report-To": ["{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=9vEr7PiX6zgR6cdNLegGNMCOzC6yy9KHd0IIzN3yPl14KDMBB9kkMV19xVP79jOdqPWBS9Ena%2B43XHWh%2B7cKqAQc7GrRCm2ZWpX4xqhXidyQeRgNoPcWsSsyv5xSD8v9ywFQdNc%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}"],
    "Server": ["cloudflare"],
    "Vary": ["Accept, Origin"],
    "X-Api-Ratelimit-Consumed": ["0"],
    "X-Api-Ratelimit-Limit": ["100000"],
    "X-Api-Ratelimit-Remaining": ["100000"],
    "X-Api-Ratelimit-Reset": ["1706279400"],
    "X-Api-Response-Log-Id": ["77524556"],
    "X-Content-Type-Options": ["nosniff"],
    "X-Frame-Options": ["DENY"]
  },
  "response_body": {
    "ask": [194.39],
    "askSize": [1],
    "bid": [194.38],
    "bidSize": [4],
    "change": [-0.11],
    "changepct": [-0.0006],
    "last": [194.39],
    "mid": [194.38],
    "s": "ok",
    "symbol": ["AAPL"],
    "updated": [1706207650],
    "volume": [29497567]
  }
}

Troubleshooting: Debug Mode

The SDK provides a debug mode that can be enabled to help you understand how the SDK is working and troubleshoot any issues you might encounter. When debug mode is enabled, the SDK will print the log to the console. This includes the full URL of the request, all request and response headers, and more.

To enable debug mode, you need to call the Debug method on the MarketDataClient instance and pass true as the argument.

Debug Code Example

package main

import (
	api "github.com/MarketDataApp/sdk-go"
	"log"
)

func main() {
	client, err := api.GetClient()
	if err != nil {
		log.Fatalf("Failed to get client: %v", err)
	}

	client.Debug(true)

	quote, err := client.StockQuotes().Symbol("AAPL").Get()
	if err != nil {
		log.Fatalf("Failed to get stock quotes: %v", err)
	}

	log.Printf("Quote: %+v\n", quote)
}

Please note that the information printed in debug mode can be quite verbose. It is recommended to use this mode only when you are facing issues and need to understand what's happening under the hood. When debug mode is activated all requests are logged, not just requests that fail.

Debug mode can be particularly useful when you are first getting started with the SDK. It can help you understand how the SDK constructs requests, how it handles responses, and how it manages errors. By examining the debug output, you can gain a deeper understanding of the SDK's inner workings and be better prepared to handle any issues that might arise.

# Packages

No description provided by the author
No description provided by the author
Package models defines the data structures used to represent the responses from the Market Data API.

# Functions

AddToLog adds a new HTTP request log entry to the HttpRequestLogs.
No description provided by the author
GetLogs returns a pointer to the HttpRequestLogs instance.
IndexCandles creates a new IndicesCandlesRequest and associates it with the provided client.
IndexQuotes creates a new IndexQuoteRequest and associates it with the provided client.
MarketStatus creates a new MarketStatusRequest and associates it with the provided client.
NewClient initializes and returns a new instance of MarketDataClient with default settings.
No description provided by the author
OptionChain creates a new OptionChainRequest and associates it with the provided client.
OptionLookup creates a new OptionsLookupRequest and associates it with the provided client.
OptionQuotes creates a new OptionQuotesRequest and associates it with the provided client.
OptionsExpirations creates a new OptionsExpirationsRequest and associates it with the provided client.
OptionsStrikes creates a new OptionsStrikesRequest and associates it with the provided client.
Get sends the StockCandlesRequest, unpacks the StockCandlesResponse, and returns a slice of StockCandle.
StockCandles creates a new CandlesRequest and associates it with the provided client.
StockEarnings creates a new StockEarningsRequest and associates it with the provided client.
StockNews creates a new StockNewsRequest and associates it with the provided client.
StockQuote creates a new StockQuoteRequest and associates it with the provided client.
StockTickers creates a new TickersRequest and associates it with the provided client.

# Constants

Version specifies the current version of the SDK.

# Variables

No description provided by the author
No description provided by the author
MaxLogEntries is the maximum number of log entries that will be stored in memory.
MemoryLimit is the limit (in bytes) of log entries that will be stored in memory.
No description provided by the author
No description provided by the author

# Structs

HttpRequestLog represents a single HTTP request log entry.
HttpRequestLogs represents a collection of HTTP request logs.
IndexQuoteRequest represents a request to the /indices/quote endpoint.
IndicesCandlesRequest represents a request to the /v1/indices/candles endpoint.
No description provided by the author
MarketStatusRequest represents a request for market status information.
OptionChainRequest represents a request to the /options/chain endpoint.
OptionsLookupRequest represents a request for retrieving options data based on user input.
OptionQuotesRequest represents a request for retrieving options quotes.
OptionsExpirationsRequest represents a request for retrieving options expirations data.
OptionsStrikesRequest represents a request to the options strikes endpoint.
StockCandlesRequest represents a request to the /v1/stocks/candles endpoint.
StockCandlesRequestV2 represents a request to the /v2/stocks/candles endpoint.
StockEarningsRequest represents a request to the /stocks/earnings endpoint.
StockNewsRequest represents a request to the /stocks/news endpoint.
StockQuoteRequest represents a request to the /stocks/quote endpoint.
TickersRequest represents a request to the /stocks/tickers endpoint.

# Interfaces

No description provided by the author