Documentation ¶
Index ¶
- Variables
- type FundManager
- func (f *FundManager) AddItem(item *Item) error
- func (f *FundManager) AddPair(p *Pair) error
- func (f *FundManager) AddUSDTrackingData(k *kline.DataFromKline) error
- func (f *FundManager) CreateSnapshot(t time.Time)
- func (f *FundManager) Exists(item *Item) bool
- func (f *FundManager) GenerateReport() *Report
- func (f *FundManager) GetFundingForEAC(exch string, a asset.Item, c currency.Code) (*Item, error)
- func (f *FundManager) GetFundingForEAP(exch string, a asset.Item, p currency.Pair) (*Pair, error)
- func (f *FundManager) GetFundingForEvent(ev common.EventHandler) (*Pair, error)
- func (f *FundManager) IsUsingExchangeLevelFunding() bool
- func (f *FundManager) Reset()
- func (f *FundManager) Transfer(amount decimal.Decimal, sender, receiver *Item, inclusiveFee bool) error
- func (f *FundManager) USDTrackingDisabled() bool
- type IFundTransferer
- type IFundingManager
- type IPairReader
- type IPairReleaser
- type IPairReserver
- type Item
- func (i *Item) BasicEqual(exch string, a asset.Item, currency, pairedCurrency currency.Code) bool
- func (i *Item) CanPlaceOrder() bool
- func (i *Item) Equal(item *Item) bool
- func (i *Item) IncreaseAvailable(amount decimal.Decimal)
- func (i *Item) MatchesCurrency(c currency.Code) bool
- func (i *Item) MatchesExchange(item *Item) bool
- func (i *Item) MatchesItemCurrency(item *Item) bool
- func (i *Item) Release(amount, diff decimal.Decimal) error
- func (i *Item) Reserve(amount decimal.Decimal) error
- type ItemSnapshot
- type Pair
- func (p *Pair) BaseAvailable() decimal.Decimal
- func (p *Pair) BaseInitialFunds() decimal.Decimal
- func (p *Pair) CanPlaceOrder(side order.Side) bool
- func (p *Pair) IncreaseAvailable(amount decimal.Decimal, side order.Side)
- func (p *Pair) QuoteAvailable() decimal.Decimal
- func (p *Pair) QuoteInitialFunds() decimal.Decimal
- func (p *Pair) Release(amount, diff decimal.Decimal, side order.Side) error
- func (p *Pair) Reserve(amount decimal.Decimal, side order.Side) error
- type Report
- type ReportItem
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFundsNotFound used when funds are requested but the funding is not found in the manager ErrFundsNotFound = errors.New("funding not found") // ErrAlreadyExists used when a matching item or pair is already in the funding manager ErrAlreadyExists = errors.New("funding already exists") // ErrUSDTrackingDisabled used when attempting to track USD values when disabled ErrUSDTrackingDisabled = errors.New("USD tracking disabled") )
Functions ¶
This section is empty.
Types ¶
type FundManager ¶
type FundManager struct {
// contains filtered or unexported fields
}
FundManager is the benevolent holder of all funding levels across all currencies used in the backtester
func SetupFundingManager ¶
func SetupFundingManager(usingExchangeLevelFunding, disableUSDTracking bool) *FundManager
SetupFundingManager creates the funding holder. It carries knowledge about levels of funding across all execution handlers and enables fund transfers
func (*FundManager) AddItem ¶
func (f *FundManager) AddItem(item *Item) error
AddItem appends a new funding item. Will reject if exists by exchange asset currency
func (*FundManager) AddPair ¶
func (f *FundManager) AddPair(p *Pair) error
AddPair adds a pair to the fund manager if it does not exist
func (*FundManager) AddUSDTrackingData ¶
func (f *FundManager) AddUSDTrackingData(k *kline.DataFromKline) error
AddUSDTrackingData adds USD tracking data to a funding item only in the event that it is not USD and there is data
func (*FundManager) CreateSnapshot ¶
func (f *FundManager) CreateSnapshot(t time.Time)
CreateSnapshot creates a Snapshot for an event's point in time as funding.snapshots is a map, it allows for the last event in the chronological list to establish the canon at X time
func (*FundManager) Exists ¶
func (f *FundManager) Exists(item *Item) bool
Exists verifies whether there is a funding item that exists with the same exchange, asset and currency
func (*FundManager) GenerateReport ¶
func (f *FundManager) GenerateReport() *Report
GenerateReport builds report data for result HTML report
func (*FundManager) GetFundingForEAC ¶
GetFundingForEAC This will construct a funding based on the exchange, asset, currency code
func (*FundManager) GetFundingForEAP ¶
GetFundingForEAP This will construct a funding based on the exchange, asset, currency pair
func (*FundManager) GetFundingForEvent ¶
func (f *FundManager) GetFundingForEvent(ev common.EventHandler) (*Pair, error)
GetFundingForEvent This will construct a funding based on a backtesting event
func (*FundManager) IsUsingExchangeLevelFunding ¶
func (f *FundManager) IsUsingExchangeLevelFunding() bool
IsUsingExchangeLevelFunding returns if using usingExchangeLevelFunding
func (*FundManager) Transfer ¶
func (f *FundManager) Transfer(amount decimal.Decimal, sender, receiver *Item, inclusiveFee bool) error
Transfer allows transferring funds from one pretend exchange to another
func (*FundManager) USDTrackingDisabled ¶
func (f *FundManager) USDTrackingDisabled() bool
USDTrackingDisabled clears all settings
type IFundTransferer ¶
type IFundTransferer interface { IsUsingExchangeLevelFunding() bool Transfer(decimal.Decimal, *Item, *Item, bool) error GetFundingForEAC(string, asset.Item, currency.Code) (*Item, error) GetFundingForEvent(common.EventHandler) (*Pair, error) GetFundingForEAP(string, asset.Item, currency.Pair) (*Pair, error) }
IFundTransferer allows for funding amounts to be transferred implementation can be swapped for live transferring
type IFundingManager ¶
type IFundingManager interface { Reset() IsUsingExchangeLevelFunding() bool GetFundingForEAC(string, asset.Item, currency.Code) (*Item, error) GetFundingForEvent(common.EventHandler) (*Pair, error) GetFundingForEAP(string, asset.Item, currency.Pair) (*Pair, error) Transfer(decimal.Decimal, *Item, *Item, bool) error GenerateReport() *Report AddUSDTrackingData(*kline.DataFromKline) error CreateSnapshot(time.Time) USDTrackingDisabled() bool }
IFundingManager limits funding usage for portfolio event handling
type IPairReader ¶
type IPairReader interface { BaseInitialFunds() decimal.Decimal QuoteInitialFunds() decimal.Decimal BaseAvailable() decimal.Decimal QuoteAvailable() decimal.Decimal }
IPairReader is used to limit pair funding functions to readonly
type IPairReleaser ¶
type IPairReleaser interface { IncreaseAvailable(decimal.Decimal, order.Side) Release(decimal.Decimal, decimal.Decimal, order.Side) error }
IPairReleaser limits funding usage for exchange event handling
type IPairReserver ¶
type IPairReserver interface { IPairReader CanPlaceOrder(order.Side) bool Reserve(decimal.Decimal, order.Side) error }
IPairReserver limits funding usage for portfolio event handling
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item holds funding data per currency item
func CreateItem ¶
func CreateItem(exch string, a asset.Item, ci currency.Code, initialFunds, transferFee decimal.Decimal) (*Item, error)
CreateItem creates a new funding item
func (*Item) BasicEqual ¶
BasicEqual checks for equality via passed in values
func (*Item) CanPlaceOrder ¶
CanPlaceOrder checks if the item has any funds available
func (*Item) IncreaseAvailable ¶
IncreaseAvailable adds funding to the available amount
func (*Item) MatchesCurrency ¶
MatchesCurrency checks that an item's currency is equal
func (*Item) MatchesExchange ¶
MatchesExchange checks that an item's exchange is equal
func (*Item) MatchesItemCurrency ¶
MatchesItemCurrency checks that an item's currency is equal
type ItemSnapshot ¶
type ItemSnapshot struct { Time time.Time Available decimal.Decimal USDClosePrice decimal.Decimal USDValue decimal.Decimal }
ItemSnapshot holds USD values to allow for tracking across backtesting results
type Pair ¶
Pair holds two currencies that are associated with each other
func CreatePair ¶
CreatePair adds two funding items and associates them with one another the association allows for the same currency to be used multiple times when usingExchangeLevelFunding is false. eg BTC-USDT and LTC-USDT do not share the same USDT level funding
func (*Pair) BaseAvailable ¶
BaseAvailable returns the available funds from the base in a currency pair
func (*Pair) BaseInitialFunds ¶
BaseInitialFunds returns the initial funds from the base in a currency pair
func (*Pair) CanPlaceOrder ¶
CanPlaceOrder does a > 0 check to see if there are any funds to place an order with changes which currency to affect based on the order side
func (*Pair) IncreaseAvailable ¶
IncreaseAvailable adds funding to the available amount changes which currency to affect based on the order side
func (*Pair) QuoteAvailable ¶
QuoteAvailable returns the available funds from the quote in a currency pair
func (*Pair) QuoteInitialFunds ¶
QuoteInitialFunds returns the initial funds from the quote in a currency pair
type Report ¶
type Report struct { DisableUSDTracking bool UsingExchangeLevelFunding bool Items []ReportItem USDTotalsOverTime map[time.Time]ItemSnapshot }
Report holds all funding data for result reporting
type ReportItem ¶
type ReportItem struct { Exchange string Asset asset.Item Currency currency.Code TransferFee decimal.Decimal InitialFunds decimal.Decimal FinalFunds decimal.Decimal USDInitialFunds decimal.Decimal USDInitialCostForOne decimal.Decimal USDFinalFunds decimal.Decimal USDFinalCostForOne decimal.Decimal Snapshots []ItemSnapshot USDPairCandle *kline.DataFromKline Difference decimal.Decimal ShowInfinite bool PairedWith currency.Code }
ReportItem holds reporting fields