trade

package
v0.0.0-...-ffba611 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: Unlicense Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteTradesAndPrint

func ExecuteTradesAndPrint(title string, initialInvestment float64, ts []*Trade)

func RenderYieldFarmingPerformanceChart

func RenderYieldFarmingPerformanceChart(path string, farm *LPFarm) error

Types

type EMACrossOverStrategy

type EMACrossOverStrategy struct {
	ShortEMA *Indicator
	LongEMA  *Indicator
	Track    *coingecko.Market
	Trade    *coingecko.Market
	Trades   []*Trade
}

func NewEMACrossOverStrategy

func NewEMACrossOverStrategy(shortEMA, longEMA *Indicator, track, trade *coingecko.Market) (*EMACrossOverStrategy, error)

type Forecast

type Forecast struct {
	Farms             []*LPFarm
	Currency          coingecko.Fiat
	InitialInvestment float64
	Balance           float64
	StartDate         string
	Days              int
}

func NewForecast

func NewForecast(currency coingecko.Fiat, initialInvestment float64, days int) *Forecast

func (*Forecast) AddLPFarm

func (fc *Forecast) AddLPFarm(a, b *coingecko.Market, apr, finalAPR, additionalInvestmentMonthly float64) error

func (*Forecast) CreateMarket

func (fc *Forecast) CreateMarket(name, symbol string, startingPrice float64, changes []PriceChange) *coingecko.Market

func (*Forecast) ToJSON

func (fc *Forecast) ToJSON() (string, error)

type Indicator

type Indicator struct {
	Name         string `json:"name"`
	ByTimestamp  map[int64]float64
	ByDateString map[string]float64
}

func NewEMAIndicator

func NewEMAIndicator(days int, prices timeseries.Series) *Indicator

func (*Indicator) ForDate

func (i *Indicator) ForDate(date string) (ema float64)

func (*Indicator) ForTimestamp

func (i *Indicator) ForTimestamp(milli int64) (ema float64)

type LPFarm

type LPFarm struct {
	Name                       string
	A                          *coingecko.Market
	B                          *coingecko.Market
	Currency                   coingecko.Fiat
	InitialInvestment          float64
	StartDate                  string
	APR                        float64
	APRChangeRateAtHarvest     float64
	InitialAPR                 float64
	LastHarvestDate            string
	UnitsA                     float64
	UnitsB                     float64
	InitialUnitsA              float64
	InitialUnitsB              float64
	AdditionalInvestmentUnitsA float64
	AdditionalInvestmentUnitsB float64
	TotalValue                 float64                       // Total value of farm in given fiat currency.
	TotalValueHODL             float64                       // Total value if we simply HODL:d both assets instead, in given fiat currency.
	ChangeHistory              map[string]*LPFarmHistoryItem // All changes, e.g. when a harvest was performed or more LP was added.
}

func NewLPFarm

func NewLPFarm(a, b *coingecko.Market, c coingecko.Fiat, initialInvestment float64, startDate string, apr float64) (*LPFarm, error)

func (*LPFarm) AddLP

func (f *LPFarm) AddLP(date string, amount float64, isAdditionalInvestment bool) error

func (*LPFarm) GetChangeHistoryAsc

func (f *LPFarm) GetChangeHistoryAsc() (items []*LPFarmHistoryItem)

func (*LPFarm) GetPrices

func (f *LPFarm) GetPrices(date string) (priceA, priceB timeseries.ValueAt, err error)

func (*LPFarm) Harvest

func (f *LPFarm) Harvest(date string) (yield float64, err error)

func (*LPFarm) LogChange

func (f *LPFarm) LogChange(date string, priceA, priceB timeseries.ValueAt)

func (*LPFarm) PrintChange

func (f *LPFarm) PrintChange(date string)

func (*LPFarm) RebalanceLP

func (f *LPFarm) RebalanceLP(priceA, priceB timeseries.ValueAt)

func (*LPFarm) SetAPRChangeRateAtHarvest

func (f *LPFarm) SetAPRChangeRateAtHarvest(dailyChange float64)

type LPFarmHistoryItem

type LPFarmHistoryItem struct {
	Date                string
	PriceA              float64
	PriceB              float64
	UnitsA              float64
	UnitsB              float64
	TotalValue          float64
	TotalValueHODL      float64
	TotalValueHODLOnlyA float64
	TotalValueHODLOnlyB float64
	APR                 float64
}

type PriceChange

type PriceChange struct {
	IncPct  float64 // Price increse percentage
	IncDays int     // Number of days that the price increases
	DecPct  float64 // Price decrese percentage
	DecDays int     // Number of days that the price decreases
}

type Side

type Side int
const (
	Buy Side = iota + 1
	Sell
)

type Trade

type Trade struct {
	Currency coingecko.Fiat
	Side     Side
	Date     string
	Market   *coingecko.Market
	Size     float64 // a percentage expressed as a float64 in range (0.0 - 100.0]
	Price    float64
}

func NewBuyAtDate

func NewBuyAtDate(date string, size float64, m *coingecko.Market) (*Trade, error)

func NewSellAtDate

func NewSellAtDate(date string, size float64, m *coingecko.Market) (*Trade, error)

func NewTrade

func NewTrade(side Side, date string, size float64, m *coingecko.Market) (*Trade, error)

Jump to

Keyboard shortcuts

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