Documentation
¶
Index ¶
- Constants
- Variables
- func InstructionIDToName(id int32) string
- func PeekAccount(data []byte) uint32
- type AccountHeader
- type AttrsMap
- func (a AttrsMap) BinaryLen() (size int)
- func (a AttrsMap) KVs() map[string]string
- func (a AttrsMap) MarshalBinary() ([]byte, error)
- func (a *AttrsMap) MarshalJSON() ([]byte, error)
- func (a AttrsMap) Sort()
- func (a *AttrsMap) UnmarshalBinary(data []byte) (err error)
- func (a *AttrsMap) UnmarshalJSON(data []byte) (err error)
- type CallbackHandle
- type Client
- func (c *Client) GetAllPriceAccounts(ctx context.Context, commitment rpc.CommitmentType) ([]PriceAccountEntry, error)
- func (c *Client) GetAllProductAccounts(ctx context.Context, commitment rpc.CommitmentType) ([]ProductAccountEntry, error)
- func (c *Client) GetAllProductKeys(ctx context.Context, commitment rpc.CommitmentType) ([]solana.PublicKey, error)
- func (c *Client) GetMappingAccount(ctx context.Context, mappingKey solana.PublicKey, ...) (MappingAccountEntry, error)
- func (c *Client) GetPriceAccount(ctx context.Context, priceKey solana.PublicKey, commitment rpc.CommitmentType) (PriceAccountEntry, error)
- func (c *Client) GetPriceAccountsRecursive(ctx context.Context, commitment rpc.CommitmentType, ...) ([]PriceAccountEntry, error)
- func (c *Client) GetProductAccount(ctx context.Context, productKey solana.PublicKey, ...) (ProductAccountEntry, error)
- func (c *Client) StreamPriceAccounts() *PriceAccountStream
- type CommandAddPrice
- type CommandAddPublisher
- type CommandDelPublisher
- type CommandHeader
- type CommandInitPrice
- type CommandSetMinPub
- type CommandUpdPrice
- type CommandUpdProduct
- type CommandUpdTest
- type Ema
- type Env
- type Instruction
- type InstructionBuilder
- func (i *InstructionBuilder) AddMapping(fundingKey solana.PublicKey, tailMappingKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) AddPrice(fundingKey solana.PublicKey, productKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) AddProduct(fundingKey solana.PublicKey, mappingKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) AddPublisher(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) AggPrice(fundingKey solana.PublicKey, priceKey solana.PublicKey) *Instruction
- func (i *InstructionBuilder) DelPublisher(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) InitMapping(fundingKey solana.PublicKey, mappingKey solana.PublicKey) *Instruction
- func (i *InstructionBuilder) InitPrice(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) InitTest(fundingKey solana.PublicKey, testKey solana.PublicKey) *Instruction
- func (i *InstructionBuilder) SetMinPub(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) UpdPrice(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) UpdPriceNoFailOnError(fundingKey solana.PublicKey, priceKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) UpdProduct(fundingKey solana.PublicKey, productKey solana.PublicKey, ...) *Instruction
- func (i *InstructionBuilder) UpdTest(fundingKey solana.PublicKey, testKey solana.PublicKey, payload CommandUpdTest) *Instruction
- type MappingAccount
- type MappingAccountEntry
- type PriceAccount
- type PriceAccountEntry
- type PriceAccountStream
- type PriceComp
- type PriceEventHandler
- type PriceInfo
- type PriceUpdate
- type ProductAccount
- type ProductAccountEntry
- type ProductAccountHeader
- type RawProductAccount
Examples ¶
Constants ¶
const ( AccountTypeUnknown = uint32(iota) AccountTypeMapping AccountTypeProduct AccountTypePrice )
The Account type enum identifies what each Pyth account stores.
const ( PriceStatusUnknown = uint32(iota) PriceStatusTrading PriceStatusHalted PriceStatusAuction )
Price status.
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.
const Magic = uint32(0xa1b2c3d4)
Magic is the 32-bit number prefixed on each account.
const ProductAccountHeaderLen = 48
ProductAccountHeaderLen is the binary offset of the AttrsData field within RawProductAccount.
const V2 = uint32(2)
V2 identifies the version 2 data format stored in an account.
Variables ¶
var Devnet = Env{
Program: solana.MustPublicKeyFromBase58("gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s"),
Mapping: solana.MustPublicKeyFromBase58("BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2"),
}
Devnet is the Pyth program on the Solana devnet cluster.
var Mainnet = Env{
Program: solana.MustPublicKeyFromBase58("FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH"),
Mapping: solana.MustPublicKeyFromBase58("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),
}
Mainnet is the Pyth program on the Solana mainnet cluster.
var Testnet = Env{
Program: solana.MustPublicKeyFromBase58("8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz"),
Mapping: solana.MustPublicKeyFromBase58("AFmdnt9ng1uVxqCmqwQJDAYC5cKTkw8gJKSM5PnzuF6z"),
}
Testnet is the Pyth program on the Solana testnet cluster.
Functions ¶
func InstructionIDToName ¶
InstructionIDToName returns a human-readable name of a Pyth instruction type.
func PeekAccount ¶
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 ¶
type AttrsMap struct {
Pairs [][2]string
}
AttrsMap is a list of string key-value pairs with stable order.
func NewAttrsMap ¶
NewAttrsMap returns a new attribute map with an initial arbitrary order.
The provided Go map may be nil.
func ReadAttrsMapFromBinary ¶
ReadAttrsMapFromBinary consumes all bytes from a binary reader, returning an AttrsMap and the number of bytes read.
func (AttrsMap) MarshalBinary ¶
MarshalBinary marshals AttrsMap to its on-chain format.
func (*AttrsMap) MarshalJSON ¶
MarshalJSON returns a JSON string map.
func (AttrsMap) Sort ¶
func (a AttrsMap) Sort()
Sort sorts the keys of an AttrsMap by lexicographic order.
func (*AttrsMap) UnmarshalBinary ¶
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 ¶
UnmarshalJSON loads a JSON string map.
type CallbackHandle ¶
type CallbackHandle struct {
// contains filtered or unexported fields
}
CallbackHandle tracks the lifetime of a callback registration.
func (CallbackHandle) Unsubscribe ¶
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 (*Client) GetAllPriceAccounts ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) }
type CommandAddPrice ¶
CommandAddPrice is the payload of Instruction_AddPrice.
type CommandAddPublisher ¶
type CommandAddPublisher struct {
Publisher solana.PublicKey
}
CommandAddPublisher is the payload of Instruction_AddPublisher.
type CommandDelPublisher ¶
type CommandDelPublisher struct {
Publisher solana.PublicKey
}
CommandDelPublisher is the payload of Instruction_DelPublisher.
type CommandHeader ¶
CommandHeader is an 8-byte header at the beginning any instruction data.
func (*CommandHeader) Valid ¶
func (h *CommandHeader) Valid() bool
Valid performs basic checks on instruction data.
type CommandInitPrice ¶
CommandInitPrice is the payload of Instruction_InitPrice.
type CommandSetMinPub ¶
CommandSetMinPub is the payload of Instruction_SetMinPub.
type CommandUpdPrice ¶
CommandUpdPrice is the payload of Instruction_UpdPrice or Instruction_UpdPriceNoFailOnError.
type CommandUpdProduct ¶
type CommandUpdProduct struct {
AttrsMap
}
CommandUpdProduct is the payload of Instruction_UpdProduct.
type CommandUpdTest ¶
CommandUpdTest is the payload Instruction_UpdTest.
type Env ¶
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 ¶
type Instruction struct { Header CommandHeader Payload interface{} // contains filtered or unexported fields }
func DecodeInstruction ¶
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 ¶
func (inst *Instruction) Accounts() []*solana.AccountMeta
func (*Instruction) Data ¶
func (inst *Instruction) Data() ([]byte, error)
func (*Instruction) ProgramID ¶
func (inst *Instruction) ProgramID() solana.PublicKey
type InstructionBuilder ¶
type InstructionBuilder struct {
// contains filtered or unexported fields
}
InstructionBuilder creates new instructions to interact with the Pyth on-chain program.
func NewInstructionBuilder ¶
func NewInstructionBuilder(programKey solana.PublicKey) *InstructionBuilder
NewInstructionBuilder creates a new InstructionBuilder targeting the given Pyth program.
func (*InstructionBuilder) AddMapping ¶
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 ¶
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 ¶
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 ¶
func (i *InstructionBuilder) AddPublisher( fundingKey solana.PublicKey, priceKey solana.PublicKey, payload CommandAddPublisher, ) *Instruction
AddPublisher adds a publisher to a price account.
func (*InstructionBuilder) AggPrice ¶
func (i *InstructionBuilder) AggPrice( fundingKey solana.PublicKey, priceKey solana.PublicKey, ) *Instruction
AggPrice computes the aggregate price for a product account.
func (*InstructionBuilder) DelPublisher ¶
func (i *InstructionBuilder) DelPublisher( fundingKey solana.PublicKey, priceKey solana.PublicKey, payload CommandDelPublisher, ) *Instruction
DelPublisher deletes a publisher from a price account.
func (*InstructionBuilder) InitMapping ¶
func (i *InstructionBuilder) InitMapping( fundingKey solana.PublicKey, mappingKey solana.PublicKey, ) *Instruction
InitMapping initializes the first mapping list account.
func (*InstructionBuilder) InitPrice ¶
func (i *InstructionBuilder) InitPrice( fundingKey solana.PublicKey, priceKey solana.PublicKey, payload CommandInitPrice, ) *Instruction
InitPrice (re)initializes a price account.
func (*InstructionBuilder) InitTest ¶
func (i *InstructionBuilder) InitTest( fundingKey solana.PublicKey, testKey solana.PublicKey, ) *Instruction
InitTest initializes a test account.
func (*InstructionBuilder) SetMinPub ¶
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 ¶
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 ¶
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 ¶
func (i *InstructionBuilder) UpdProduct( fundingKey solana.PublicKey, productKey solana.PublicKey, payload CommandUpdProduct, ) *Instruction
UpdProduct updates a product account.
func (*InstructionBuilder) UpdTest ¶
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 ¶
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 ¶
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 ¶
type PriceAccountEntry struct { *PriceAccount Pubkey solana.PublicKey `json:"pubkey"` Slot uint64 `json:"slot"` }
PriceAccountEntry is a versioned price account and its pubkey.
type PriceAccountStream ¶
type PriceAccountStream struct {
// contains filtered or unexported fields
}
PriceAccountStream is an ongoing stream of on-chain price account updates.
func (*PriceAccountStream) Close ¶
func (p *PriceAccountStream) Close()
Close must be called when no more updates are needed.
func (*PriceAccountStream) Err ¶
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 ¶
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 ¶
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()
func NewPriceEventHandler ¶
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 ¶
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 ¶
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 ¶
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 ¶
HasChanged returns whether there was a change between this and another price info.
type PriceUpdate ¶
type PriceUpdate struct { Account *PriceAccount PreviousInfo *PriceInfo CurrentInfo *PriceInfo }
PriceUpdate is returned to callbacks when an aggregate or component price has been updated.
type ProductAccount ¶
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 ¶
func (p *ProductAccount) UnmarshalBinary(buf []byte) error
UnmarshalBinary decodes the product account from the on-chain format.
func (*ProductAccount) UnmarshalJSON ¶
func (p *ProductAccount) UnmarshalJSON(buf []byte) error
UnmarshalJSON decodes the product account contents from JSON.
type ProductAccountEntry ¶
type ProductAccountEntry struct { *ProductAccount Pubkey solana.PublicKey `json:"pubkey"` Slot uint64 `json:"slot"` }
ProductAccountEntry is a versioned product account and its pubkey.
type ProductAccountHeader ¶
type ProductAccountHeader struct { AccountHeader `json:"-"` FirstPrice solana.PublicKey `json:"first_price"` // first price account in list }
type RawProductAccount ¶
type RawProductAccount struct { ProductAccountHeader AttrsData [464]byte }