Documentation ¶
Overview ¶
Package ticketbuyer provides an implementation of automatic ticket purchasing for a fonero wallet.
Index ¶
- Constants
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type Config
- type PurchaseManager
- type PurchaseStats
- type TicketPurchaser
- func (t *TicketPurchaser) Account() uint32
- func (t *TicketPurchaser) AccountName() (string, error)
- func (t *TicketPurchaser) BalanceToMaintain() fnoutil.Amount
- func (t *TicketPurchaser) Config() (*Config, error)
- func (t *TicketPurchaser) ExpiryDelta() int
- func (t *TicketPurchaser) MaxFee() fnoutil.Amount
- func (t *TicketPurchaser) MaxInMempool() int
- func (t *TicketPurchaser) MaxPerBlock() int
- func (t *TicketPurchaser) MaxPriceAbsolute() fnoutil.Amount
- func (t *TicketPurchaser) MaxPriceRelative() float64
- func (t *TicketPurchaser) MinFee() fnoutil.Amount
- func (t *TicketPurchaser) PoolAddress() fnoutil.Address
- func (t *TicketPurchaser) PoolFees() float64
- func (t *TicketPurchaser) Purchase(height int64) (*PurchaseStats, error)
- func (t *TicketPurchaser) SetAccount(account uint32)
- func (t *TicketPurchaser) SetBalanceToMaintain(balanceToMaintain int64)
- func (t *TicketPurchaser) SetExpiryDelta(expiryDelta int)
- func (t *TicketPurchaser) SetMaxFee(maxFee int64)
- func (t *TicketPurchaser) SetMaxInMempool(maxInMempool int)
- func (t *TicketPurchaser) SetMaxPerBlock(maxPerBlock int)
- func (t *TicketPurchaser) SetMaxPriceAbsolute(maxPriceAbsolute int64)
- func (t *TicketPurchaser) SetMaxPriceRelative(maxPriceRelative float64)
- func (t *TicketPurchaser) SetMinFee(minFee int64)
- func (t *TicketPurchaser) SetPoolAddress(poolAddress fnoutil.Address)
- func (t *TicketPurchaser) SetPoolFees(poolFees float64)
- func (t *TicketPurchaser) SetVotingAddress(votingAddress fnoutil.Address)
- func (t *TicketPurchaser) VotingAddress() fnoutil.Address
Constants ¶
const ( // TicketFeeMean is the string indicating that the mean ticket fee // should be used when determining ticket fee. TicketFeeMean = "mean" // TicketFeeMedian is the string indicating that the median ticket fee // should be used when determining ticket fee. TicketFeeMedian = "median" // PriceTargetVWAP is the string indicating that the volume // weighted average price should be used as the price target. PriceTargetVWAP = "vwap" // PriceTargetPool is the string indicating that the ticket pool // price should be used as the price target. PriceTargetPool = "pool" // PriceTargetDual is the string indicating that a combination of the // ticket pool price and the ticket VWAP should be used as the // price target. PriceTargetDual = "dual" )
const ( // AvgPriceVWAPMode indicates to use only the VWAP. AvgPriceVWAPMode = iota // AvgPricePoolMode indicates to use only the average // price in the ticket pool. AvgPricePoolMode // AvgPriceDualMode indicates to use bothe the VWAP and // the average pool price. AvgPriceDualMode )
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
Types ¶
type Config ¶
type Config struct { AccountName string AvgPriceMode string AvgPriceVWAPDelta int BalanceToMaintainAbsolute int64 BalanceToMaintainRelative float64 BlocksToAvg int DontWaitForTickets bool ExpiryDelta int FeeSource string FeeTargetScaling float64 MinFee int64 MaxFee int64 MaxPerBlock int MaxPriceAbsolute int64 MaxPriceRelative float64 MaxInMempool int PoolAddress fnoutil.Address PoolFees float64 NoSpreadTicketPurchases bool VotingAddress fnoutil.Address TxFee int64 }
Config stores the configuration options for ticket buyer.
type PurchaseManager ¶
type PurchaseManager struct {
// contains filtered or unexported fields
}
PurchaseManager is the main handler of websocket notifications to pass to the purchaser and internal quit notifications.
func NewPurchaseManager ¶
func NewPurchaseManager(w *wallet.Wallet, purchaser *TicketPurchaser, ntfnChan <-chan *wallet.MainTipChangedNotification, passphrase []byte) *PurchaseManager
NewPurchaseManager creates a new PurchaseManager.
func (*PurchaseManager) NotificationHandler ¶
func (p *PurchaseManager) NotificationHandler()
NotificationHandler handles notifications, which trigger ticket purchases.
func (*PurchaseManager) Purchaser ¶
func (p *PurchaseManager) Purchaser() *TicketPurchaser
Purchaser returns the ticket buyer instance associated with the purchase manager.
func (*PurchaseManager) Start ¶
func (p *PurchaseManager) Start()
Start starts the purchase manager goroutines.
func (*PurchaseManager) Stop ¶
func (p *PurchaseManager) Stop()
Stop signals all purchase manager goroutines to shutdown.
func (*PurchaseManager) WaitForShutdown ¶
func (p *PurchaseManager) WaitForShutdown()
WaitForShutdown blocks until all purchase manager goroutines have finished executing.
type PurchaseStats ¶
type PurchaseStats struct { Height int64 PriceMaxScale float64 PriceAverage fnoutil.Amount PriceNext fnoutil.Amount PriceCurrent fnoutil.Amount Purchased int LeftWindow int Balance fnoutil.Amount TicketPrice fnoutil.Amount }
PurchaseStats stats is a collection of statistics related to the ticket purchase.
type TicketPurchaser ¶
type TicketPurchaser struct {
// contains filtered or unexported fields
}
TicketPurchaser is the main handler for purchasing tickets. It decides whether or not to do so based on information obtained from daemon and wallet chain servers.
func NewTicketPurchaser ¶
func NewTicketPurchaser(cfg *Config, fnodChainSvr *fnorpcclient.Client, w *wallet.Wallet, activeNet *chaincfg.Params) (*TicketPurchaser, error)
NewTicketPurchaser creates a new TicketPurchaser.
func (*TicketPurchaser) Account ¶
func (t *TicketPurchaser) Account() uint32
Account returns the account to use for purchasing tickets.
func (*TicketPurchaser) AccountName ¶
func (t *TicketPurchaser) AccountName() (string, error)
AccountName returns the account name to use for purchasing tickets.
func (*TicketPurchaser) BalanceToMaintain ¶
func (t *TicketPurchaser) BalanceToMaintain() fnoutil.Amount
BalanceToMaintain returns the balance to be maintained in the wallet.
func (*TicketPurchaser) Config ¶
func (t *TicketPurchaser) Config() (*Config, error)
Config returns the current ticket buyer configuration.
func (*TicketPurchaser) ExpiryDelta ¶
func (t *TicketPurchaser) ExpiryDelta() int
ExpiryDelta returns the expiry delta.
func (*TicketPurchaser) MaxFee ¶
func (t *TicketPurchaser) MaxFee() fnoutil.Amount
MaxFee returns the max ticket fee per KB to use when purchasing tickets.
func (*TicketPurchaser) MaxInMempool ¶
func (t *TicketPurchaser) MaxInMempool() int
MaxInMempool returns the max tickets to allow in the mempool.
func (*TicketPurchaser) MaxPerBlock ¶
func (t *TicketPurchaser) MaxPerBlock() int
MaxPerBlock returns the max tickets to purchase for a block.
func (*TicketPurchaser) MaxPriceAbsolute ¶
func (t *TicketPurchaser) MaxPriceAbsolute() fnoutil.Amount
MaxPriceAbsolute returns the max absolute price to purchase a ticket.
func (*TicketPurchaser) MaxPriceRelative ¶
func (t *TicketPurchaser) MaxPriceRelative() float64
MaxPriceRelative returns the scaling factor which is multipled by average price to calculate a relative max for the ticket price.
func (*TicketPurchaser) MinFee ¶
func (t *TicketPurchaser) MinFee() fnoutil.Amount
MinFee returns the min ticket fee per KB to use when purchasing tickets.
func (*TicketPurchaser) PoolAddress ¶
func (t *TicketPurchaser) PoolAddress() fnoutil.Address
PoolAddress returns the pool address where ticket fees are sent.
func (*TicketPurchaser) PoolFees ¶
func (t *TicketPurchaser) PoolFees() float64
PoolFees returns the percent of ticket per ticket fee mandated by the pool.
func (*TicketPurchaser) Purchase ¶
func (t *TicketPurchaser) Purchase(height int64) (*PurchaseStats, error)
Purchase is the main handler for purchasing tickets for the user. TODO Not make this an inlined pile of crap.
func (*TicketPurchaser) SetAccount ¶
func (t *TicketPurchaser) SetAccount(account uint32)
SetAccount sets the account to use for purchasing tickets.
func (*TicketPurchaser) SetBalanceToMaintain ¶
func (t *TicketPurchaser) SetBalanceToMaintain(balanceToMaintain int64)
SetBalanceToMaintain sets the balance to be maintained in the wallet.
func (*TicketPurchaser) SetExpiryDelta ¶
func (t *TicketPurchaser) SetExpiryDelta(expiryDelta int)
SetExpiryDelta sets the expiry delta.
func (*TicketPurchaser) SetMaxFee ¶
func (t *TicketPurchaser) SetMaxFee(maxFee int64)
SetMaxFee sets the max ticket fee per KB to use when purchasing tickets.
func (*TicketPurchaser) SetMaxInMempool ¶
func (t *TicketPurchaser) SetMaxInMempool(maxInMempool int)
SetMaxInMempool sets the max tickets to allow in the mempool.
func (*TicketPurchaser) SetMaxPerBlock ¶
func (t *TicketPurchaser) SetMaxPerBlock(maxPerBlock int)
SetMaxPerBlock sets the max tickets to purchase for a block.
func (*TicketPurchaser) SetMaxPriceAbsolute ¶
func (t *TicketPurchaser) SetMaxPriceAbsolute(maxPriceAbsolute int64)
SetMaxPriceAbsolute sets the max absolute price to purchase a ticket.
func (*TicketPurchaser) SetMaxPriceRelative ¶
func (t *TicketPurchaser) SetMaxPriceRelative(maxPriceRelative float64)
SetMaxPriceRelative sets scaling factor.
func (*TicketPurchaser) SetMinFee ¶
func (t *TicketPurchaser) SetMinFee(minFee int64)
SetMinFee sets the min ticket fee per KB to use when purchasing tickets.
func (*TicketPurchaser) SetPoolAddress ¶
func (t *TicketPurchaser) SetPoolAddress(poolAddress fnoutil.Address)
SetPoolAddress sets the pool address where ticket fees are sent.
func (*TicketPurchaser) SetPoolFees ¶
func (t *TicketPurchaser) SetPoolFees(poolFees float64)
SetPoolFees sets the percent of ticket per ticket fee mandated by the pool.
func (*TicketPurchaser) SetVotingAddress ¶
func (t *TicketPurchaser) SetVotingAddress(votingAddress fnoutil.Address)
SetVotingAddress sets the address to send ticket outputs to.
func (*TicketPurchaser) VotingAddress ¶
func (t *TicketPurchaser) VotingAddress() fnoutil.Address
VotingAddress returns the address to send ticket outputs to.