Documentation ¶
Index ¶
- type OBGraph
- type OrderBookGraph
- func (graph *OrderBookGraph) AddOffer(offer xdr.OfferEntry)
- func (graph *OrderBookGraph) Apply(ledger uint32) error
- func (graph *OrderBookGraph) Clear()
- func (graph *OrderBookGraph) Discard()
- func (graph *OrderBookGraph) FindAsksAndBids(selling, buying xdr.Asset, maxPriceLevels int) ([]xdr.OfferEntry, []xdr.OfferEntry, uint32)
- func (graph *OrderBookGraph) FindFixedPaths(maxPathLength int, sourceAsset xdr.Asset, amountToSpend xdr.Int64, ...) ([]Path, uint32, error)
- func (graph *OrderBookGraph) FindPaths(maxPathLength int, destinationAsset xdr.Asset, destinationAmount xdr.Int64, ...) ([]Path, uint32, error)
- func (graph *OrderBookGraph) IsEmpty() bool
- func (graph *OrderBookGraph) Offers() []xdr.OfferEntry
- func (graph *OrderBookGraph) OffersMap() map[xdr.Int64]xdr.OfferEntry
- func (graph *OrderBookGraph) Pending() ([]xdr.OfferEntry, []xdr.Int64)
- func (graph *OrderBookGraph) RemoveOffer(offerID xdr.Int64) OBGraph
- type Path
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OBGraph ¶
type OBGraph interface { AddOffer(offer xdr.OfferEntry) Apply(ledger uint32) error Discard() Offers() []xdr.OfferEntry OffersMap() map[xdr.Int64]xdr.OfferEntry RemoveOffer(xdr.Int64) OBGraph Pending() ([]xdr.OfferEntry, []xdr.Int64) Clear() }
OBGraph is an interface for orderbook graphs
type OrderBookGraph ¶
type OrderBookGraph struct {
// contains filtered or unexported fields
}
OrderBookGraph is an in memory graph representation of all the offers in the stellar ledger
func NewOrderBookGraph ¶
func NewOrderBookGraph() *OrderBookGraph
NewOrderBookGraph constructs a new OrderBookGraph
func (*OrderBookGraph) AddOffer ¶
func (graph *OrderBookGraph) AddOffer(offer xdr.OfferEntry)
AddOffer will queue an operation to add the given offer to the order book in the internal batch. You need to run Apply() to apply all enqueued operations.
func (*OrderBookGraph) Apply ¶
func (graph *OrderBookGraph) Apply(ledger uint32) error
Apply will attempt to apply all the updates in the internal batch to the order book. When Apply is successful, a new empty, instance of internal batch will be created.
func (*OrderBookGraph) Clear ¶
func (graph *OrderBookGraph) Clear()
Clear removes all offers from the graph.
func (*OrderBookGraph) Discard ¶
func (graph *OrderBookGraph) Discard()
Discard removes all operations which have been queued but not yet applied to the OrderBookGraph
func (*OrderBookGraph) FindAsksAndBids ¶
func (graph *OrderBookGraph) FindAsksAndBids( selling, buying xdr.Asset, maxPriceLevels int, ) ([]xdr.OfferEntry, []xdr.OfferEntry, uint32)
FindAsksAndBids returns all asks and bids for a given trading pair Asks consists of all offers which sell `selling` in exchange for `buying` sorted by price (in terms of `buying`) from cheapest to most expensive Bids consists of all offers which sell `buying` in exchange for `selling` sorted by price (in terms of `selling`) from cheapest to most expensive Both Asks and Bids will span at most `maxPriceLevels` price levels
func (*OrderBookGraph) FindFixedPaths ¶
func (graph *OrderBookGraph) FindFixedPaths( maxPathLength int, sourceAsset xdr.Asset, amountToSpend xdr.Int64, destinationAssets []xdr.Asset, maxAssetsPerPath int, ) ([]Path, uint32, error)
FindFixedPaths returns a list of payment paths where the source and destination assets are fixed. All returned payment paths will start by spending `amountToSpend` of `sourceAsset` and will end with some positive balance of `destinationAsset`. `sourceAccountID` is optional. if `sourceAccountID` is provided then no offers created by `sourceAccountID` will be considered when evaluating payment paths
func (*OrderBookGraph) FindPaths ¶
func (graph *OrderBookGraph) FindPaths( maxPathLength int, destinationAsset xdr.Asset, destinationAmount xdr.Int64, sourceAccountID *xdr.AccountId, sourceAssets []xdr.Asset, sourceAssetBalances []xdr.Int64, validateSourceBalance bool, maxAssetsPerPath int, ) ([]Path, uint32, error)
FindPaths returns a list of payment paths originating from a source account and ending with a given destinaton asset and amount.
func (*OrderBookGraph) IsEmpty ¶
func (graph *OrderBookGraph) IsEmpty() bool
IsEmpty returns true if the orderbook graph is not populated
func (*OrderBookGraph) Offers ¶
func (graph *OrderBookGraph) Offers() []xdr.OfferEntry
Offers returns a list of offers contained in the order book
func (*OrderBookGraph) OffersMap ¶
func (graph *OrderBookGraph) OffersMap() map[xdr.Int64]xdr.OfferEntry
OffersMap returns a ID => OfferEntry map of offers contained in the order book.
func (*OrderBookGraph) Pending ¶
func (graph *OrderBookGraph) Pending() ([]xdr.OfferEntry, []xdr.Int64)
Pending returns a list of queued offers which will be added to the order book and a list of queued offers which will be removed from the order book.
func (*OrderBookGraph) RemoveOffer ¶
func (graph *OrderBookGraph) RemoveOffer(offerID xdr.Int64) OBGraph
RemoveOffer will queue an operation to remove the given offer from the order book in the internal batch. You need to run Apply() to apply all enqueued operations.
type Path ¶
type Path struct { SourceAmount xdr.Int64 SourceAsset xdr.Asset DestinationAsset xdr.Asset DestinationAmount xdr.Int64 InteriorNodes []xdr.Asset // contains filtered or unexported fields }
Path represents a payment path from a source asset to some destination asset
func (*Path) DestinationAssetString ¶
DestinationAssetString returns the string representation of the path's destination asset
func (*Path) SourceAssetString ¶
SourceAssetString returns the string representation of the path's source asset