modules

package
v0.0.0-...-d4f6610 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pair2Assets

func Pair2Assets(pair TradingPair) (horizon.Asset, horizon.Asset)

Pair2Assets splits a TradingPair into its assets

func ParseAsset

func ParseAsset(code string, issuer string) horizon.Asset

ParseAsset returns a horizon asset from strings

func Path2Assets

func Path2Assets(path *PaymentPath) (horizon.Asset, horizon.Asset, horizon.Asset)

Path2Assets returns the assets inside a PaymentPath

func PathAsset2Asset

func PathAsset2Asset(p PathAsset) horizon.Asset

PathAsset2Asset turns a PathRecord asset into a horizon asset

func PathAsset2BuildAsset

func PathAsset2BuildAsset(p PathAsset) build.Asset

PathAsset2BuildAsset turns a PathRecord asset into a build asset

Types

type ArbitCycleConfig

type ArbitCycleConfig struct {
	MinRatio float64      `valid:"-" toml:"MIN_RATIO"`
	Groups   []GroupInput `valid:"-" toml:"GROUPS"`
}

ArbitCycleConfig holds the arbitrage strategy settings

func (ArbitCycleConfig) String

func (c ArbitCycleConfig) String() string

String impl.

type AssetGroup

type AssetGroup struct {
	HoldAsset horizon.Asset
	AssetBook []horizon.Asset
	PathList  []*PaymentPath
	PairBook  []PairBookEntry

	MinAmount *model.Number
	// contains filtered or unexported fields
}

AssetGroup is an operational asset set and its settings

type BasicOrderBookLevel

type BasicOrderBookLevel struct {
	Price  *model.Number
	Amount *model.Number
}

BasicOrderBookLevel is just a price and an amount

type DexAgent

type DexAgent struct {
	API            *horizonclient.Client
	SourceSeed     string
	TradingSeed    string
	SourceAccount  string
	TradingAccount string
	Network        network.Passphrase
	// contains filtered or unexported fields
}

DexAgent manages all transactions with the Stellar DEX

func MakeDexAgent

func MakeDexAgent(
	api *horizonclient.Client,
	sourceSeed string,
	tradingSeed string,
	sourceAccount string,
	tradingAccount string,
	network network.Passphrase,
	threadTracker *multithreading.ThreadTracker,
	rateLimiter func(),
	submitDone chan<- bool,
	operationalBuffer float64,
	minRatio float64,
	simMode bool,
	l logger.Logger,
) *DexAgent

MakeDexAgent is the factory method

func (*DexAgent) JustAssetBalance

func (dA *DexAgent) JustAssetBalance(asset horizonclient.Client) (float64, error)
	for _, balance := range account.Balances {
		if utils.AssetsEqual(balance.Asset, asset) {
			b, e := strconv.ParseFloat(balance.Balance, 64)
			if e != nil {
				return -1, fmt.Errorf("error: cannot parse balance: %s", e)
			}
			if balance.Asset.Type == utils.Native {
				return b - (dA.minReserve(account.SubentryCount) + dA.operationalBuffer), e
			}
			return b, e
		}
	}
	return -1, errors.New("could not find a balance for the asset passed in")
}

JustAssetBalance returns the balance of the given asset for the trading account

func (*DexAgent) SendPaymentCycle

func (dA *DexAgent) SendPaymentCycle(path *PaymentPath, maxAmount *model.Number) error

SendPaymentCycle executes a payment cycle

func (*DexAgent) SubmitOps

func (dA *DexAgent) SubmitOps(ops []build.TransactionMutator, asyncCallback func(hash string, e error)) error

SubmitOps submits the passed in operations to the network asynchronously in a single transaction

type DexWatcher

type DexWatcher struct {
	API     *horizon.Client
	Network build.Network
	// contains filtered or unexported fields
}

DexWatcher is an object that queries the DEX

func MakeDexWatcher

func MakeDexWatcher(
	api *horizon.Client,
	network build.Network,
	threadTracker *multithreading.ThreadTracker,
	rateLimiter func(),
	booksOut chan<- *horizon.OrderBookSummary,
	ledgerOut chan horizon.Ledger,
	l logger.Logger) *DexWatcher

MakeDexWatcher is the factory method

func (*DexWatcher) AddTrackedBook

func (w *DexWatcher) AddTrackedBook(ctx context.Context, pair TradingPair, limit string) error

AddTrackedBook adds a pair's orderbook to the BookTracker

func (*DexWatcher) GetLowAsk

func (w *DexWatcher) GetLowAsk(pair TradingPair) (*model.Number, *model.Number, error)

GetLowAsk returns the low ask's price and amount for a trading pair

func (*DexWatcher) GetOrderBook

func (w *DexWatcher) GetOrderBook(api *horizon.Client, pair TradingPair) (orderBook horizon.OrderBookSummary, e error)

GetOrderBook gets the SDEX order book

func (*DexWatcher) GetPaths

func (w *DexWatcher) GetPaths(endAsset horizon.Asset, amount *model.Number, tradingAccount string) (*FindPathResponse, error)

GetPaths gets and parses the find-path data for an asset from horizon

func (*DexWatcher) GetTopBid

func (w *DexWatcher) GetTopBid(pair TradingPair) (*model.Number, *model.Number, error)

GetTopBid returns the top bid's price and amount for a trading pair

func (*DexWatcher) StreamLedgers

func (w *DexWatcher) StreamLedgers(
	ctx context.Context,
	cursor *horizon.Cursor,
	handler horizon.LedgerHandler,
	limit int,
	order string,
)

StreamLedgers streams Stellar ledgers

func (*DexWatcher) StreamManager

func (w *DexWatcher) StreamManager(pairList []TradingPair)

StreamManager just refreshes the streams as they expire; horizon closes them after 55 seconds on its own

type FindPathResponse

type FindPathResponse struct {
	Embedded struct {
		Records []PathRecord `json:"records"`
	} `json:"_embedded"`
}

FindPathResponse holds the raw JSON for a horizon call

type GroupInput

type GroupInput struct {
	HoldAssetCode   string       `valid:"-" toml:"HOLD_ASSET_CODE"`
	HoldAssetIssuer string       `valid:"-" toml:"HOLD_ASSET_ISSUER"`
	UseBalance      bool         `valid:"-" toml:"USE_BALANCE"`
	StaticAmount    float64      `valid:"-" toml:"STATIC_AMOUNT"`
	MinAmount       float64      `valid:"-" toml:"MIN_AMOUNT"`
	Assets          []assetInput `valid:"-" toml:"ASSETS"`
}

GroupInput holds the inbound strings for the asset groups

type PairBookEntry

type PairBookEntry struct {
	ID   int
	Pair TradingPair
}

PairBookEntry is a numbered trading pair

type PathAsset

type PathAsset struct {
	AssetType   string `json:"asset_type"`
	AssetCode   string `json:"asset_code"`
	AssetIssuer string `json:"asset_issuer"`
}

PathAsset is a single asset in a path

type PathFindOutcome

type PathFindOutcome struct {
	BestPath     *PaymentPath
	MaxAmount    *model.Number
	MetThreshold bool
}

PathFindOutcome sends the outcome of the find-best-path

type PathFinder

type PathFinder struct {
	AssetGroups []*AssetGroup
	// contains filtered or unexported fields
}

PathFinder keeps track of all the possible payment paths

func MakePathFinder

func MakePathFinder(
	dexWatcher DexWatcher,
	stratConfig ArbitCycleConfig,
	rateLimiter func(),
	findIt chan bool,
	pathReturn chan<- PathFindOutcome,
	refresh <-chan bool,
	l logger.Logger,
) (*PathFinder, error)

MakePathFinder is a factory method

func (*PathFinder) FindBestPathConcurrent

func (p *PathFinder) FindBestPathConcurrent()

FindBestPathConcurrent determines and returns the most profitable payment path with goroutines

type PathPair

type PathPair struct {
	PairID int
	Pair   TradingPair
}

PathPair is a trading pair with a price inversion flag

type PathRecord

type PathRecord struct {
	SourceAssetType        string      `json:"source_asset_type"`
	SourceAmount           string      `json:"source_amount"`
	DestinationAssetType   string      `json:"destination_asset_type"`
	DestinationAssetCode   string      `json:"destination_asset_code"`
	DestinationAssetIssuer string      `json:"destination_asset_issuer"`
	DestinationAmount      string      `json:"destination_amount"`
	Path                   []PathAsset `json:"path"`
}

PathRecord is a single horizon find path record

type PaymentPath

type PaymentPath struct {
	HoldAsset    horizon.Asset
	PathAssetA   horizon.Asset
	PathAssetB   horizon.Asset
	PathSequence []PathPair
	UseBalance   bool
	StaticAmount *model.Number
	MinAmount    *model.Number
}

PaymentPath is a pair of assets for a payment path and their encoded tradingPair

type TradingPair

type TradingPair struct {
	Base  horizon.Asset
	Quote horizon.Asset
}

TradingPair represents a trading pair

type TransData

type TransData struct {
	Path   *PaymentPath
	Amount *model.Number
}

TransData contains the data needed to contruct a path payment

Jump to

Keyboard shortcuts

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