modules

package
v0.3.2-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 23 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 {
	HoldAssetCode   string       `valid:"-" toml:"HOLD_ASSET_CODE"`
	HoldAssetIssuer string       `valid:"-" toml:"HOLD_ASSET_ISSUER"`
	MinRatio        float64      `valid:"-" toml:"MIN_RATIO"`
	UseBalance      bool         `valid:"-" toml:"USE_BALANCE"`
	StaticAmount    float64      `valid:"-" toml:"STATIC_AMOUNT"`
	MinAmount       float64      `valid:"-" toml:"MIN_AMOUNT"`
	Assets          []assetInput `valid:"-" toml:"ASSETS"`
}

ArbitCycleConfig holds the arbitrage strategy settings

func (ArbitCycleConfig) String

func (c ArbitCycleConfig) String() string

String impl.

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            *horizon.Client
	SourceSeed     string
	TradingSeed    string
	SourceAccount  string
	TradingAccount string
	Network        build.Network
	// contains filtered or unexported fields
}

DexAgent manages all transactions with the Stellar DEX

func MakeDexAgent

func MakeDexAgent(
	api *horizon.Client,
	sourceSeed string,
	tradingSeed string,
	sourceAccount string,
	tradingAccount string,
	network build.Network,
	threadTracker *multithreading.ThreadTracker,
	operationalBuffer float64,
	minRatio float64,
	useBalance bool,
	staticAmount float64,
	minAmount float64,
	simMode bool,
	l logger.Logger,
) *DexAgent

MakeDexAgent is the factory method

func (*DexAgent) JustAssetBalance

func (dA *DexAgent) JustAssetBalance(asset horizon.Asset) (float64, error)

JustAssetBalance returns asset balance

func (*DexAgent) SendByFoundPath

func (dA *DexAgent) SendByFoundPath(path *PathRecord, holdAsset *horizon.Asset, maxAmount *model.Number, hold chan bool, done chan bool) error

SendByFoundPath executes a payment cycle for the find-path protocol

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,
	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 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 {
	HoldAsset horizon.Asset
	AssetBook []groupedAsset
	PathList  []*PaymentPath
	PairBook  map[int]TradingPair
	// contains filtered or unexported fields
}

PathFinder keeps track of all the possible payment paths

func MakePathFinder

func MakePathFinder(
	dexWatcher DexWatcher,
	stratConfig ArbitCycleConfig,
	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

func (*PathFinder) WhatAmount

func (p *PathFinder) WhatAmount() (bool, *model.Number)

WhatAmount returns the payment amount settings

func (*PathFinder) WhatRatio

func (p *PathFinder) WhatRatio() *model.Number

WhatRatio returns the minimum ratio

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 PathRequester

type PathRequester struct {
	HoldAsset horizon.Asset
	// contains filtered or unexported fields
}

PathRequester keeps the assetbook and settings for the path-requesting method this prototype performed strictly worse than pathFinder so it's not implemented at this time preserving this for future revamp ideas

func MakePathRequester

func MakePathRequester(
	dexWatcher DexWatcher,
	stratConfig ArbitCycleConfig,
	l logger.Logger,
) (*PathRequester, error)

MakePathRequester is a factory method

func (*PathRequester) AnalysePaths

func (p *PathRequester) AnalysePaths(tradingAccount string) (*PathRecord, *model.Number, bool, error)

AnalysePaths asks horizon about available paths and checks if any are profitable

type PaymentPath

type PaymentPath struct {
	HoldAsset    horizon.Asset
	PathAssetA   horizon.Asset
	PathAssetB   horizon.Asset
	PathSequence []PathPair
}

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