modules

package
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2019 License: MIT Imports: 14 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 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) MakePathPayment

func (dA *DexAgent) MakePathPayment(path *PaymentPath, amount *model.Number, minRatio *model.Number) (build.PaymentBuilder, error)

MakePathPayment constructs and returns a path payment transaction for a given path object

func (*DexAgent) SendByFoundPath

func (dA *DexAgent) SendByFoundPath(path *PathRecord, holdAsset *horizon.Asset, maxAmount *model.Number) 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
	SourceAccount  string
	TradingAccount string
	// contains filtered or unexported fields
}

DexWatcher is an object that queries the DEX

func MakeDexWatcher

func MakeDexWatcher(
	api *horizon.Client,
	network build.Network,
	sourceAccount string,
	tradingAccount string,
	l logger.Logger) *DexWatcher

MakeDexWatcher is the factory method

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) (*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

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 PathFinder

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

PathFinder keeps track of all the possible payment paths

func MakePathFinder

func MakePathFinder(
	dexWatcher DexWatcher,
	stratConfig ArbitCycleConfig,
	l logger.Logger,
) (*PathFinder, error)

MakePathFinder is a factory method

func (*PathFinder) FindBestPath

func (p *PathFinder) FindBestPath() (*PaymentPath, *model.Number, bool, error)

FindBestPath determines and returns the most profitable payment path, its max amount, and whether its good enough

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 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() (*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
	FirstPair  TradingPair
	MidPair    TradingPair
	LastPair   TradingPair
}

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

Jump to

Keyboard shortcuts

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