pyth

package module
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 21 Imported by: 7

README

Pyth Network Go client

Access high-fidelity market data on Solana

Go Reference unit tests

Summary

Pyth Network delivers real-time market data to the Solana blockchain.

This library allows you to query, stream and publish price data using the Go programming language.

Getting Started

Add the Pyth client to your project using the Go CLI.

go get go.blockdaemon.com/pyth@latest

Find docs and usage examples on pkg.go.dev.

Attributions

Documentation

Index

Examples

Constants

View Source
const (
	AccountTypeUnknown = uint32(iota)
	AccountTypeMapping
	AccountTypeProduct
	AccountTypePrice
)

The Account type enum identifies what each Pyth account stores.

View Source
const (
	PriceStatusUnknown = uint32(iota)
	PriceStatusTrading
	PriceStatusHalted
	PriceStatusAuction
)

Price status.

View Source
const (
	Instruction_InitMapping = int32(iota)
	Instruction_AddMapping
	Instruction_AddProduct
	Instruction_UpdProduct
	Instruction_AddPrice
	Instruction_AddPublisher
	Instruction_DelPublisher
	Instruction_UpdPrice
	Instruction_AggPrice
	Instruction_InitPrice
	Instruction_InitTest
	Instruction_UpdTest
	Instruction_SetMinPub
	Instruction_UpdPriceNoFailOnError
)

Pyth program instructions.

View Source
const Magic = uint32(0xa1b2c3d4)

Magic is the 32-bit number prefixed on each account.

View Source
const ProductAccountHeaderLen = 48

ProductAccountHeaderLen is the binary offset of the AttrsData field within RawProductAccount.

View Source
const V2 = uint32(2)

V2 identifies the version 2 data format stored in an account.

Variables

View Source
var Devnet = Env{
	Program: solana.MustPublicKeyFromBase58("gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s"),
	Mapping: solana.MustPublicKeyFromBase58("BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2"),
}

Devnet is the Pyth program on the Solana devnet cluster.

View Source
var Mainnet = Env{
	Program: solana.MustPublicKeyFromBase58("FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"),
	Mapping: solana.MustPublicKeyFromBase58("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),
}

Mainnet is the Pyth program on the Solana mainnet cluster.

View Source
var Testnet = Env{
	Program: solana.MustPublicKeyFromBase58("8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz"),
	Mapping: solana.MustPublicKeyFromBase58("AFmdnt9ng1uVxqCmqwQJDAYC5cKTkw8gJKSM5PnzuF6z"),
}

Testnet is the Pyth program on the Solana testnet cluster.

Functions

func InstructionIDToName added in v0.2.0

func InstructionIDToName(id int32) string

InstructionIDToName returns a human-readable name of a Pyth instruction type.

func PeekAccount

func PeekAccount(data []byte) uint32

PeekAccount determines the account type given the account's data bytes.

Types

type AccountHeader

type AccountHeader struct {
	Magic       uint32 // set exactly to 0xa1b2c3d4
	Version     uint32 // currently V2
	AccountType uint32 // account type following the header
	Size        uint32 // size of the account including the header
}

AccountHeader is a 16-byte header at the beginning of each account type.

func (AccountHeader) Valid

func (h AccountHeader) Valid() bool

Valid performs basic checks on an account.

type AttrsMap added in v0.2.0

type AttrsMap struct {
	Pairs [][2]string
}

AttrsMap is a list of string key-value pairs with stable order.

func NewAttrsMap added in v0.2.0

func NewAttrsMap(fromGo map[string]string) (out AttrsMap, err error)

NewAttrsMap returns a new attribute map with an initial arbitrary order.

The provided Go map may be nil.

func ReadAttrsMapFromBinary added in v0.2.0

func ReadAttrsMapFromBinary(rd *bytes.Reader) (out AttrsMap, n int, err error)

ReadAttrsMapFromBinary consumes all bytes from a binary reader, returning an AttrsMap and the number of bytes read.

func (AttrsMap) BinaryLen added in v0.3.0

func (a AttrsMap) BinaryLen() (size int)

BinaryLen returns this AttrsMap's length in binary encoding.

func (AttrsMap) KVs added in v0.2.0

func (a AttrsMap) KVs() map[string]string

KVs returns the AttrsMap as an unordered Go map.

func (AttrsMap) MarshalBinary added in v0.2.0

func (a AttrsMap) MarshalBinary() ([]byte, error)

MarshalBinary marshals AttrsMap to its on-chain format.

func (*AttrsMap) MarshalJSON added in v0.3.0

func (a *AttrsMap) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON string map.

func (AttrsMap) Sort added in v0.3.0

func (a AttrsMap) Sort()

Sort sorts the keys of an AttrsMap by lexicographic order.

func (*AttrsMap) UnmarshalBinary added in v0.2.0

func (a *AttrsMap) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals AttrsMap from its on-chain format.

Will return an error if it fails to consume the entire provided byte slice.

func (*AttrsMap) UnmarshalJSON added in v0.3.0

func (a *AttrsMap) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON loads a JSON string map.

type CallbackHandle added in v0.3.1

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

CallbackHandle tracks the lifetime of a callback registration.

func (CallbackHandle) Unsubscribe added in v0.3.1

func (c CallbackHandle) Unsubscribe()

Unsubscribe de-registers a callback from the handler.

Calling Unsubscribe is optional. The handler calls it automatically when the underlying stream closes.

type Client

type Client struct {
	Env          Env
	RPC          *rpc.Client
	WebSocketURL string
	Log          *zap.Logger

	AccountsBatchSize int // number of accounts to get with getMultipleAccounts()
}

Client interacts with Pyth via Solana's JSON-RPC API.

Do not instantiate Client directly, use NewClient instead.

func NewClient added in v0.2.0

func NewClient(env Env, rpcURL string, wsURL string) *Client

NewClient creates a new client to the Pyth on-chain program.

func (*Client) GetAllPriceAccounts added in v0.3.2

func (c *Client) GetAllPriceAccounts(ctx context.Context, commitment rpc.CommitmentType) ([]PriceAccountEntry, error)

GetAllPriceAccounts returns all price accounts.

Aborts and returns an error if any product account failed to fetch.

func (*Client) GetAllProductAccounts added in v0.3.2

func (c *Client) GetAllProductAccounts(ctx context.Context, commitment rpc.CommitmentType) ([]ProductAccountEntry, error)

GetAllProductAccounts returns all product accounts.

Aborts and returns an error if any product account failed to fetch.

Example
client := NewClient(Devnet, testRPC, testWS)
products, _ := client.GetAllProductAccounts(context.TODO(), rpc.CommitmentProcessed)
// Print first product as JSON.
products[0].Slot = 1234
jsonData, _ := json.MarshalIndent(&products[0], "", "  ")
fmt.Println(string(jsonData))
Output:

{
  "first_price": "4EQrNZYk5KR1RnjyzbaaRbHsv8VqZWzSUtvx58wLsZbj",
  "attrs": {
    "asset_type": "Crypto",
    "base": "BCH",
    "description": "BCH/USD",
    "generic_symbol": "BCHUSD",
    "quote_currency": "USD",
    "symbol": "Crypto.BCH/USD"
  },
  "pubkey": "89GseEmvNkzAMMEXcW9oTYzqRPXTsJ3BmNerXmgA1osV",
  "slot": 1234
}

func (*Client) GetAllProductKeys added in v0.3.0

func (c *Client) GetAllProductKeys(ctx context.Context, commitment rpc.CommitmentType) ([]solana.PublicKey, error)

GetAllProductKeys lists all mapping accounts for product account pubkeys.

Example
client := NewClient(Devnet, testRPC, testWS)
products, _ := client.GetAllProductKeys(context.TODO(), rpc.CommitmentProcessed)
// Print first 5 product account pubkeys.
for _, key := range products[:5] {
	fmt.Println(key)
}
Output:

89GseEmvNkzAMMEXcW9oTYzqRPXTsJ3BmNerXmgA1osV
JCnD5WiurZfoeVPEi2AXVgacg73Wd2iRDDjZDbSwdr9D
G89jkM5wFLpmnbvRbeePUumxsJyzoXaRfgBVjyx2CPzQ
GaBJpKtnyUbyKe34XuyegR7W98a9PT5cg985G974NY8R
Fwosgw2ikRvdzgKcQJwMacyczk3nXgoW3AtVtyVvXSAb

func (*Client) GetMappingAccount added in v0.3.0

func (c *Client) GetMappingAccount(ctx context.Context, mappingKey solana.PublicKey, commitment rpc.CommitmentType) (MappingAccountEntry, error)

GetMappingAccount retrieves a single mapping account from the blockchain.

func (*Client) GetPriceAccount added in v0.1.1

func (c *Client) GetPriceAccount(ctx context.Context, priceKey solana.PublicKey, commitment rpc.CommitmentType) (PriceAccountEntry, error)

GetPriceAccount retrieves a price account from the blockchain.

func (*Client) GetPriceAccountsRecursive added in v0.3.2

func (c *Client) GetPriceAccountsRecursive(ctx context.Context, commitment rpc.CommitmentType, priceKeys ...solana.PublicKey) ([]PriceAccountEntry, error)

GetPriceAccountsRecursive retrieves the price accounts of the given public keys.

If these price accounts have successors, their contents will be fetched as well, recursively. When called with the ProductAccountHeader.FirstPrice, it will fetch all price accounts of a product.

func (*Client) GetProductAccount added in v0.1.1

func (c *Client) GetProductAccount(ctx context.Context, productKey solana.PublicKey, commitment rpc.CommitmentType) (ProductAccountEntry, error)

GetProductAccount retrieves a product account from the blockchain.

Example
client := NewClient(Devnet, testRPC, testWS)
productPubkey := solana.MustPublicKeyFromBase58("EWxGfxoPQSNA2744AYdAKmsQZ8F9o9M7oKkvL3VM1dko")
product, _ := client.GetProductAccount(context.TODO(), productPubkey, rpc.CommitmentProcessed)
product.Slot = 1234
// Print first product as JSON.
jsonData, _ := json.MarshalIndent(product, "", "  ")
fmt.Println(string(jsonData))
Output:

{
  "first_price": "E36MyBbavhYKHVLWR79GiReNNnBDiHj6nWA7htbkNZbh",
  "attrs": {
    "asset_type": "FX",
    "base": "EUR",
    "description": "EUR/USD",
    "generic_symbol": "EURUSD",
    "quote_currency": "USD",
    "symbol": "FX.EUR/USD",
    "tenor": "Spot"
  },
  "pubkey": "EWxGfxoPQSNA2744AYdAKmsQZ8F9o9M7oKkvL3VM1dko",
  "slot": 1234
}

func (*Client) StreamPriceAccounts

func (c *Client) StreamPriceAccounts() *PriceAccountStream

StreamPriceAccounts creates a new stream of price account updates.

It will reconnect automatically if the WebSocket connection breaks or stalls.

Example
client := NewClient(Devnet, testRPC, testWS)
stream := client.StreamPriceAccounts()
// Close stream after a while.
go func() {
	<-time.After(3 * time.Second)
	stream.Close()
}()
// Print updates.
for update := range stream.Updates() {
	fmt.Println(update.Agg.Price)
}
Output:

type CommandAddPrice added in v0.2.0

type CommandAddPrice struct {
	Exponent  int32
	PriceType uint32
}

CommandAddPrice is the payload of Instruction_AddPrice.

type CommandAddPublisher added in v0.2.0

type CommandAddPublisher struct {
	Publisher solana.PublicKey
}

CommandAddPublisher is the payload of Instruction_AddPublisher.

type CommandDelPublisher added in v0.2.0

type CommandDelPublisher struct {
	Publisher solana.PublicKey
}

CommandDelPublisher is the payload of Instruction_DelPublisher.

type CommandHeader added in v0.2.0

type CommandHeader struct {
	Version uint32 // currently V2
	Cmd     int32
}

CommandHeader is an 8-byte header at the beginning any instruction data.

func (*CommandHeader) Valid added in v0.2.0

func (h *CommandHeader) Valid() bool

Valid performs basic checks on instruction data.

type CommandInitPrice added in v0.2.0

type CommandInitPrice struct {
	Exponent  int32
	PriceType uint32
}

CommandInitPrice is the payload of Instruction_InitPrice.

type CommandSetMinPub added in v0.2.0

type CommandSetMinPub struct {
	MinPub  uint8
	Padding [3]byte
}

CommandSetMinPub is the payload of Instruction_SetMinPub.

type CommandUpdPrice added in v0.2.0

type CommandUpdPrice struct {
	Status  uint32
	Unused  uint32
	Price   int64
	Conf    uint64
	PubSlot uint64
}

CommandUpdPrice is the payload of Instruction_UpdPrice or Instruction_UpdPriceNoFailOnError.

type CommandUpdProduct added in v0.2.0

type CommandUpdProduct struct {
	AttrsMap
}

CommandUpdProduct is the payload of Instruction_UpdProduct.

type CommandUpdTest added in v0.2.0

type CommandUpdTest struct {
	Exponent int32
	SlotDiff [32]int8
	Price    [32]int64
	Conf     [32]uint64
}

CommandUpdTest is the payload Instruction_UpdTest.

type Ema

type Ema struct {
	Val   int64
	Numer int64
	Denom int64
}

Ema is an exponentially-weighted moving average.

type Env added in v0.3.0

type Env struct {
	Program solana.PublicKey // Program ID
	Mapping solana.PublicKey // Root mapping key
}

Env identifies deployment of the Pyth on-chain program.

type Instruction added in v0.2.0

type Instruction struct {
	Header  CommandHeader
	Payload interface{}
	// contains filtered or unexported fields
}

func DecodeInstruction added in v0.2.0

func DecodeInstruction(
	programKey solana.PublicKey,
	accounts []*solana.AccountMeta,
	data []byte,
) (*Instruction, error)

DecodeInstruction attempts to reconstruct a Pyth command from an on-chain instruction.

Security

Please note that this function may behave differently than the Pyth on-chain program. Especially edge cases and invalid input is handled according to "best effort".

This function also performs no account ownership nor permission checks.

It is best to only use this instruction on successful program executions.

func (*Instruction) Accounts added in v0.2.0

func (inst *Instruction) Accounts() []*solana.AccountMeta

func (*Instruction) Data added in v0.2.0

func (inst *Instruction) Data() ([]byte, error)

func (*Instruction) ProgramID added in v0.2.0

func (inst *Instruction) ProgramID() solana.PublicKey

type InstructionBuilder added in v0.2.0

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

InstructionBuilder creates new instructions to interact with the Pyth on-chain program.

func NewInstructionBuilder added in v0.2.0

func NewInstructionBuilder(programKey solana.PublicKey) *InstructionBuilder

NewInstructionBuilder creates a new InstructionBuilder targeting the given Pyth program.

func (*InstructionBuilder) AddMapping added in v0.2.0

func (i *InstructionBuilder) AddMapping(
	fundingKey solana.PublicKey,
	tailMappingKey solana.PublicKey,
	newMappingKey solana.PublicKey,
) *Instruction

AddMapping initializes and adds new mapping account to list.

func (*InstructionBuilder) AddPrice added in v0.2.0

func (i *InstructionBuilder) AddPrice(
	fundingKey solana.PublicKey,
	productKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandAddPrice,
) *Instruction

AddPrice adds a new price account to a product account.

func (*InstructionBuilder) AddProduct added in v0.2.0

func (i *InstructionBuilder) AddProduct(
	fundingKey solana.PublicKey,
	mappingKey solana.PublicKey,
	productKey solana.PublicKey,
) *Instruction

AddProduct initializes and adds new product reference data account.

func (*InstructionBuilder) AddPublisher added in v0.2.0

func (i *InstructionBuilder) AddPublisher(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandAddPublisher,
) *Instruction

AddPublisher adds a publisher to a price account.

func (*InstructionBuilder) AggPrice added in v0.2.0

func (i *InstructionBuilder) AggPrice(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
) *Instruction

AggPrice computes the aggregate price for a product account.

func (*InstructionBuilder) DelPublisher added in v0.2.0

func (i *InstructionBuilder) DelPublisher(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandDelPublisher,
) *Instruction

DelPublisher deletes a publisher from a price account.

func (*InstructionBuilder) InitMapping added in v0.2.0

func (i *InstructionBuilder) InitMapping(
	fundingKey solana.PublicKey,
	mappingKey solana.PublicKey,
) *Instruction

InitMapping initializes the first mapping list account.

func (*InstructionBuilder) InitPrice added in v0.2.0

func (i *InstructionBuilder) InitPrice(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandInitPrice,
) *Instruction

InitPrice (re)initializes a price account.

func (*InstructionBuilder) InitTest added in v0.2.0

func (i *InstructionBuilder) InitTest(
	fundingKey solana.PublicKey,
	testKey solana.PublicKey,
) *Instruction

InitTest initializes a test account.

func (*InstructionBuilder) SetMinPub added in v0.2.0

func (i *InstructionBuilder) SetMinPub(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandSetMinPub,
) *Instruction

SetMinPub sets the minimum publishers of a price account.

func (*InstructionBuilder) UpdPrice added in v0.2.0

func (i *InstructionBuilder) UpdPrice(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandUpdPrice,
) *Instruction

UpdPrice publishes a new component price to a price account.

func (*InstructionBuilder) UpdPriceNoFailOnError added in v0.3.7

func (i *InstructionBuilder) UpdPriceNoFailOnError(
	fundingKey solana.PublicKey,
	priceKey solana.PublicKey,
	payload CommandUpdPrice,
) *Instruction

UpdPriceNoFailOnError publishes a new component price to a price account, ignoring errors.

func (*InstructionBuilder) UpdProduct added in v0.2.0

func (i *InstructionBuilder) UpdProduct(
	fundingKey solana.PublicKey,
	productKey solana.PublicKey,
	payload CommandUpdProduct,
) *Instruction

UpdProduct updates a product account.

func (*InstructionBuilder) UpdTest added in v0.2.0

func (i *InstructionBuilder) UpdTest(
	fundingKey solana.PublicKey,
	testKey solana.PublicKey,
	payload CommandUpdTest,
) *Instruction

UpdTest runs an aggregate price test.

type MappingAccount

type MappingAccount struct {
	AccountHeader
	Num      uint32           // number of keys
	Pad1     uint32           // reserved field
	Next     solana.PublicKey // pubkey of next mapping account
	Products [640]solana.PublicKey
}

MappingAccount is a piece of a singly linked-list of all products on Pyth.

func (*MappingAccount) ProductKeys added in v0.3.0

func (m *MappingAccount) ProductKeys() []solana.PublicKey

ProductKeys returns the slice of product keys referenced by this mapping, excluding empty entries.

func (*MappingAccount) UnmarshalBinary

func (m *MappingAccount) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes a mapping account from the on-chain format.

type MappingAccountEntry added in v0.3.2

type MappingAccountEntry struct {
	*MappingAccount
	Pubkey solana.PublicKey `json:"pubkey"`
	Slot   uint64           `json:"slot"`
}

MappingAccountEntry is a versioned mapping account and its pubkey.

type PriceAccount

type PriceAccount struct {
	AccountHeader
	PriceType  uint32           // price or calculation type
	Exponent   int32            // price exponent
	Num        uint32           // number of component prices
	NumQt      uint32           // number of quoters that make up aggregate
	LastSlot   uint64           // slot of last valid (not unknown) aggregate price
	ValidSlot  uint64           // valid slot of aggregate price
	Twap       Ema              // exponential moving average price
	Twac       Ema              // exponential moving confidence interval
	Drv1, Drv2 int64            // reserved for future use
	Product    solana.PublicKey // ProductAccount key
	Next       solana.PublicKey // next PriceAccount key in linked list
	PrevSlot   uint64           // valid slot of previous update
	PrevPrice  int64            // aggregate price of previous update
	PrevConf   uint64           // confidence interval of previous update
	Drv3       int64            // reserved for future use
	Agg        PriceInfo        // aggregate price info
	Components [32]PriceComp    // price components for each quoter
}

PriceAccount represents a continuously-updating price feed for a product.

func (*PriceAccount) GetComponent

func (p *PriceAccount) GetComponent(publisher *solana.PublicKey) *PriceComp

GetComponent returns the first price component with the given publisher key. Might return nil.

func (*PriceAccount) UnmarshalBinary

func (p *PriceAccount) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes the price account from the on-chain format.

type PriceAccountEntry added in v0.3.2

type PriceAccountEntry struct {
	*PriceAccount
	Pubkey solana.PublicKey `json:"pubkey"`
	Slot   uint64           `json:"slot"`
}

PriceAccountEntry is a versioned price account and its pubkey.

type PriceAccountStream added in v0.3.0

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

PriceAccountStream is an ongoing stream of on-chain price account updates.

func (*PriceAccountStream) Close added in v0.3.0

func (p *PriceAccountStream) Close()

Close must be called when no more updates are needed.

func (*PriceAccountStream) Err added in v0.3.0

func (p *PriceAccountStream) Err() error

Err returns the reason why the price account stream is closed. Will block until the stream has actually closed. Returns nil if closure was expected.

func (*PriceAccountStream) Updates added in v0.3.0

func (p *PriceAccountStream) Updates() <-chan PriceAccountEntry

Updates returns a channel with new price account updates.

type PriceComp

type PriceComp struct {
	Publisher solana.PublicKey // key of contributing publisher
	Agg       PriceInfo        // price used to compute the current aggregate price
	Latest    PriceInfo        // latest price of publisher
}

PriceComp contains the price and confidence contributed by a specific publisher.

type PriceEventHandler added in v0.3.1

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

PriceEventHandler provides a callback-style interface to Pyth updates.

Example
// Connect to Pyth on Solana devnet.
client := NewClient(Devnet, testRPC, testWS)

// Open new event stream.
stream := client.StreamPriceAccounts()
handler := NewPriceEventHandler(stream)

// Subscribe to price account changes.
priceKey := solana.MustPublicKeyFromBase58("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix")
handler.OnPriceChange(priceKey, func(info PriceUpdate) {
	price, conf, ok := info.Current()
	if ok {
		log.Printf("Price change: $%s ± $%s", price, conf)
	}
})

// Close stream after a while.
<-time.After(10 * time.Second)
stream.Close()
Output:

func NewPriceEventHandler added in v0.3.1

func NewPriceEventHandler(stream *PriceAccountStream) *PriceEventHandler

NewPriceEventHandler creates a new event handler over the stream.

A stream must not be re-used between event handlers.

func (*PriceEventHandler) Err added in v0.3.1

func (p *PriceEventHandler) Err() error

Err returns the reason why the underlying price account stream is closed.

Will block until the stream has actually closed. Returns nil if closure was expected.

After this function returns the event handler will not send any more callbacks. You could use this function as a barrier for any cleanup tasks relating to callbacks.

func (*PriceEventHandler) OnComponentChange added in v0.3.1

func (p *PriceEventHandler) OnComponentChange(priceKey solana.PublicKey, publisher solana.PublicKey, callback func(PriceUpdate)) CallbackHandle

OnComponentChange registers a callback function to be called whenever the price component of the given (price account, publisher account) pair changes.

func (*PriceEventHandler) OnPriceChange added in v0.3.1

func (p *PriceEventHandler) OnPriceChange(priceKey solana.PublicKey, callback func(PriceUpdate)) CallbackHandle

OnPriceChange registers a callback function to be called whenever the aggregate price of the provided price account changes.

type PriceInfo

type PriceInfo struct {
	Price   int64  // current price
	Conf    uint64 // confidence interval around the price
	Status  uint32 // status of price
	CorpAct uint32
	PubSlot uint64 // valid publishing slot
}

PriceInfo contains a price and confidence at a specific slot.

This struct can represent either a publisher's contribution or the outcome of price aggregation.

func (*PriceInfo) HasChanged added in v0.3.1

func (p *PriceInfo) HasChanged(other *PriceInfo) bool

HasChanged returns whether there was a change between this and another price info.

func (*PriceInfo) IsZero added in v0.3.1

func (p *PriceInfo) IsZero() bool

func (*PriceInfo) Value added in v0.3.1

func (p *PriceInfo) Value(exponent int32) (price decimal.Decimal, conf decimal.Decimal, ok bool)

Value returns the parsed price and conf values.

If ok is false, the value is invalid.

type PriceUpdate added in v0.3.1

type PriceUpdate struct {
	Account      *PriceAccount
	PreviousInfo *PriceInfo
	CurrentInfo  *PriceInfo
}

PriceUpdate is returned to callbacks when an aggregate or component price has been updated.

func (PriceUpdate) Current added in v0.3.1

func (p PriceUpdate) Current() (price decimal.Decimal, conf decimal.Decimal, ok bool)

Current returns the value of the last price update.

If ok is false, the value is invalid.

func (PriceUpdate) Previous added in v0.3.1

func (p PriceUpdate) Previous() (price decimal.Decimal, conf decimal.Decimal, ok bool)

Previous returns the value of the previously seen price update.

If ok is false, the value is invalid.

type ProductAccount added in v0.1.1

type ProductAccount struct {
	ProductAccountHeader
	Attrs AttrsMap `json:"attrs"` // key-value string pairs of additional data
}

ProductAccount contains metadata for a single product, such as its symbol and its base/quote currencies.

func (*ProductAccount) UnmarshalBinary added in v0.1.1

func (p *ProductAccount) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes the product account from the on-chain format.

func (*ProductAccount) UnmarshalJSON added in v0.3.0

func (p *ProductAccount) UnmarshalJSON(buf []byte) error

UnmarshalJSON decodes the product account contents from JSON.

type ProductAccountEntry added in v0.3.0

type ProductAccountEntry struct {
	*ProductAccount
	Pubkey solana.PublicKey `json:"pubkey"`
	Slot   uint64           `json:"slot"`
}

ProductAccountEntry is a versioned product account and its pubkey.

type ProductAccountHeader added in v0.3.0

type ProductAccountHeader struct {
	AccountHeader `json:"-"`
	FirstPrice    solana.PublicKey `json:"first_price"` // first price account in list
}

type RawProductAccount added in v0.3.0

type RawProductAccount struct {
	ProductAccountHeader
	AttrsData [464]byte
}

Jump to

Keyboard shortcuts

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