gospice

package module
v3.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

gospice

Golang SDK for Spice.ai

See Go Docs at pkg.go.dev/github.com/spiceai/gospice/v3.

For full documentation visit docs.spice.ai.

Usage

Note: There is a bug in Apache Arrow v13 that causes a high rate of errors from concurrent queries. We've addressed this in our fork. To apply the fix, add the following to your go.mod file until the fix is released upstream:

replace github.com/apache/arrow/go/v13 => github.com/spicehq/arrow/go/v13 v13.0.0-20231011105758-b46797bef61d
  1. Get the gospice package.
go get github.com/spiceai/gospice/v3
  1. Import the package.
import "github.com/spiceai/gospice/v3"
  1. Create a SpiceClient passing in your API key. Get your free API key at spice.ai.
spice := NewSpiceClient()
defer spice.Close()
  1. Initialize the SpiceClient.
if err := spice.Init("API Key"); err != nil {
    panic(fmt.Errorf("error initializing SpiceClient: %w", err))
}
  1. Execute a query and get back an Apache Arrow Reader.
    reader, err := spice.Query(context.Background(), "SELECT * FROM eth.recent_blocks ORDER BY number LIMIT 10")
    if err != nil {
        panic(fmt.Errorf("error querying: %w", err))
    }
    defer reader.Release()
  1. Iterate through the reader to access the records.
    for reader.Next() {
        record := reader.Record()
        defer record.Release()
        fmt.Println(record)
    }

Example

Run go run . to execute a sample query and print the results to the console.

See client_test.go for examples on querying Ethereum and Polygon blocks.

Documentation

Index

Constants

View Source
const (
	MAX_MESSAGE_SIZE_BYTES = 100 * 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	HttpUrl      string `json:"http_url,omitempty"`
	FlightUrl    string `json:"flight_url,omitempty"`
	FirecacheUrl string `json:"firecache_url,omitempty"`
}

func LoadConfig

func LoadConfig() ClientConfig

type Price

type Price struct {
	Timestamp string  `json:"timestamp"`
	Price     float64 `json:"price"`
	High      float64 `json:"high"`
	Low       float64 `json:"low"`
	Open      float64 `json:"open"`
	Close     float64 `json:"close"`
}

type Quote

type Quote struct {
	Prices    map[string]string `mapstructure:"prices,omitempty" json:"prices,omitempty"`
	MinPrice  string            `mapstructure:"minPrice,omitempty" json:"minPrice,omitempty"`
	MaxPrice  string            `mapstructure:"maxPrice,omitempty" json:"maxPrice,omitempty"`
	MeanPrice string            `mapstructure:"avePrice,omitempty" json:"avePrice,omitempty"`
}

type QuoteParams

type QuoteParams struct {
	StartTime   time.Time
	EndTime     time.Time
	Granularity string
}

type SpiceClient

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

SpiceClient is a client for Spice.ai - Data and AI infrastructure for web3 https://spice.ai For documentation visit https://docs.spice.ai/sdks/go-sdk

func NewSpiceClient

func NewSpiceClient() *SpiceClient

NewSpiceClient creates a new SpiceClient

func NewSpiceClientWithAddress

func NewSpiceClientWithAddress(flightAddress string, firecacheAddress string) *SpiceClient

func (*SpiceClient) Close

func (c *SpiceClient) Close() error

Close closes the SpiceClient and cleans up resources

func (*SpiceClient) FireQuery

func (c *SpiceClient) FireQuery(ctx context.Context, sql string) (array.RecordReader, error)

FireQuery executes a query against Spice.ai Firecache and returns a Apache Arrow RecordReader For more information on Apache Arrow RecordReader visit https://godoc.org/github.com/apache/arrow/go/arrow/array#RecordReader

func (*SpiceClient) GetHistoricalPrices

func (c *SpiceClient) GetHistoricalPrices(ctx context.Context, pairs []string, params *QuoteParams) (map[string][]Price, error)

func (*SpiceClient) GetPrices

func (c *SpiceClient) GetPrices(ctx context.Context, pairs []string) (map[string]Quote, error)

func (*SpiceClient) Init

func (c *SpiceClient) Init(apiKey string) error

Init initializes the SpiceClient

func (*SpiceClient) Query

func (c *SpiceClient) Query(ctx context.Context, sql string) (array.RecordReader, error)

Query executes a query against Spice.ai and returns a Apache Arrow RecordReader For more information on Apache Arrow RecordReader visit https://godoc.org/github.com/apache/arrow/go/arrow/array#RecordReader

func (*SpiceClient) SetMaxRetries

func (c *SpiceClient) SetMaxRetries(maxRetries uint)

Sets the maximum number of times to retry Query and FireQuery calls. The default is 3. Setting to 0 will disable retries.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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