portfolio

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package portfolio persists bot balance snapshots (each tagged with the token's USD price at capture time) to a local SQLite database, and computes PnL from them.

There is no per-trade ledger available from the bidder daemon -- only balance snapshots (see ActionLogBalance in the bidder manager package) -- so PnL here is defined as a mark-to-market comparison: the market value of the portfolio at its earliest known snapshot vs. its latest, not a sum of realized trade gains/losses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotKey

type BotKey struct {
	Market   sgo.PublicKey
	Pipeline sgo.PublicKey
}

BotKey identifies one bot -- a bot is exactly one market+pipeline pair, which is how the bidder daemon itself tags every balance log entry.

type DB

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

DB wraps a SQLite connection holding balance_snapshot history.

func Open

func Open(path string) (*DB, error)

Open opens (or creates) the portfolio database at path and applies its schema.

func (*DB) Accounts

func (d *DB) Accounts() ([]sgo.PublicKey, error)

Accounts returns every distinct account that has at least one snapshot.

func (*DB) AccountsForBot

func (d *DB) AccountsForBot(bot BotKey) ([]sgo.PublicKey, error)

AccountsForBot returns every distinct account that has reported a balance under the given bot.

func (*DB) Bots

func (d *DB) Bots() ([]BotKey, error)

Bots returns every distinct (market, pipeline) pair seen across all balance snapshots -- one entry per bot that has ever reported a balance.

func (*DB) Close

func (d *DB) Close() error

func (*DB) DB

func (d *DB) DB() *sql.DB

DB returns the underlying *sql.DB, for passing to generic SQL tooling (e.g. the dashboard's table explorer) that shouldn't need its own separately-pooled connection to the same file.

func (*DB) FilePath

func (d *DB) FilePath() string

func (*DB) Insert

func (d *DB) Insert(s Snapshot) error

Insert records one balance snapshot.

func (*DB) Positions

func (d *DB) Positions(account sgo.PublicKey) ([]MintPosition, error)

Positions returns one MintPosition per mint ever seen for account, comparing that mint's earliest snapshot to its latest.

type MintPosition

type MintPosition struct {
	Mint           sgo.PublicKey
	Market         sgo.PublicKey
	Pipeline       sgo.PublicKey
	StartTime      time.Time
	StartBalance   uint64
	StartDecimals  *uint8
	StartUSDPrice  *float64
	StartUSDValue  *float64 // nil if StartUSDPrice unknown
	LatestTime     time.Time
	LatestBalance  uint64
	LatestDecimals *uint8
	LatestUSDPrice *float64
	LatestUSDValue *float64
	DeltaUSDValue  *float64 // LatestUSDValue - StartUSDValue; nil unless both known
}

MintPosition is one mint's starting vs. current mark-to-market value within a single account's history. Market/Pipeline identify which bot (a bot is exactly one market+pipeline pair) the position's latest snapshot was reported under.

type Snapshot

type Snapshot struct {
	Time     time.Time
	Market   sgo.PublicKey
	Pipeline sgo.PublicKey
	Account  sgo.PublicKey
	Mint     sgo.PublicKey
	Balance  uint64
	Decimals *uint8   // nil if not yet known
	USDPrice *float64 // nil if not yet available
}

Snapshot is one balance observation, optionally priced.

Source Files

  • portfolio.go

Jump to

Keyboard shortcuts

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