common

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: BSD-3-Clause Imports: 16 Imported by: 12

Documentation

Index

Constants

View Source
const (
	DefaultBinSizes = "1m, 5m, 15m, 30m, 1h, 4h, 1d"
)

Variables

View Source
var (
	ErrNoBalance = errors.New("no balance")
	Zero         = decimal.NewFromInt(0)
)
View Source
var (
	Day  = time.Hour * 24
	Week = time.Hour * 24 * 7
)

Functions

func Copy

func Copy(dst, src string) (err error)

func CopyWithMainPkg

func CopyWithMainPkg(dst, src string) (err error)

func FloatAdd

func FloatAdd(a, b float64) float64

FloatAdd return a*b

func FloatDiv

func FloatDiv(a, b float64) float64

FloatDiv return a/b

func FloatMul

func FloatMul(a, b float64) float64

FloatMul return a*b

func FloatSub

func FloatSub(a, b float64) float64

FloatSub return a-b

func FormatFloat

func FormatFloat(n float64, precision int) float64

FormatFloat format float with precision

func GetBinSizeDuration

func GetBinSizeDuration(str string) (duration time.Duration, err error)

GetBinSizeDuration get duration of the binsize

func GetExecDir

func GetExecDir() string

GetExecDir return exec dir

func MergeKlineChan

func MergeKlineChan(klines chan []interface{}, srcDuration, dstDuration time.Duration) (rets chan []interface{})

MergeKlineChan merge kline data

func OpenURL

func OpenURL(strURL string) error

func ParseBinSizes

func ParseBinSizes(str string) (durations []time.Duration, err error)

ParseBinSizes parse binsizes

func ParseBinStrs

func ParseBinStrs(str string) (strs []string)

ParseBinStrs parse binsizes to strs

Types

type CandleFn

type CandleFn func(candle *trademodel.Candle)

type Entry added in v0.0.7

type Entry struct {
	Value interface{}
	Label string
}

type KlineMerge

type KlineMerge struct {
	// contains filtered or unexported fields
}

KlineMerge merge kline to new duration

func NewKlineMerge

func NewKlineMerge(src, dst time.Duration) *KlineMerge

NewKlineMerge merge kline constructor

func NewKlineMergeStr

func NewKlineMergeStr(src, dst string) *KlineMerge

NewKlineMergeStr new KlineMerge with string duration

func (*KlineMerge) GetDst

func (km *KlineMerge) GetDst() int64

GetDst return kline dst duration secs

func (*KlineMerge) GetDstDuration

func (km *KlineMerge) GetDstDuration() time.Duration

GetDstDuration get kline dst duration

func (*KlineMerge) GetSrc

func (km *KlineMerge) GetSrc() int64

GetSrc return kline source duration secs

func (*KlineMerge) GetSrcDuration

func (km *KlineMerge) GetSrcDuration() time.Duration

GetSrcDuration get kline source duration

func (*KlineMerge) GetUnFinished added in v0.1.7

func (km *KlineMerge) GetUnFinished() (ret interface{})

func (*KlineMerge) IsFirst

func (km *KlineMerge) IsFirst() bool

IsFirst is first time

func (*KlineMerge) NeedMerge

func (km *KlineMerge) NeedMerge() bool

NeedMerge is kline need merge

func (*KlineMerge) Update

func (km *KlineMerge) Update(data interface{}) (ret interface{})

Update update candle, and return new kline candle return nil if no new kline candle

type LeverBalance added in v0.1.7

type LeverBalance struct {
	// contains filtered or unexported fields
}

func NewLeverBalance added in v0.1.7

func NewLeverBalance() *LeverBalance

func (*LeverBalance) AddTrade added in v0.1.7

func (b *LeverBalance) AddTrade(tr Trade) (profit, onceFee float64, err error)

func (*LeverBalance) CheckLiquidation added in v0.1.7

func (b *LeverBalance) CheckLiquidation(price float64) (liqPrice float64, isLiq bool)

func (*LeverBalance) Get added in v0.1.7

func (b *LeverBalance) Get() (total float64)

func (*LeverBalance) GetFeeTotal added in v0.1.7

func (b *LeverBalance) GetFeeTotal() float64

func (*LeverBalance) Pos added in v0.1.7

func (b *LeverBalance) Pos() (pos float64)

func (*LeverBalance) Set added in v0.1.7

func (b *LeverBalance) Set(total float64)

func (*LeverBalance) SetFee added in v0.1.7

func (b *LeverBalance) SetFee(fee float64)

func (*LeverBalance) SetLever added in v0.1.7

func (b *LeverBalance) SetLever(lever float64)

type Param

type Param struct {
	Name     string
	Type     string
	Label    string
	Info     string
	DefValue interface{}
	Enums    []Entry
	// contains filtered or unexported fields
}

func BoolParam added in v0.0.8

func BoolParam(name, label, info string, defValue bool, ptr *bool, enums ...Entry) Param

func FloatParam added in v0.0.8

func FloatParam(name, label, info string, defValue float64, ptr *float64, enums ...Entry) Param

func IntParam added in v0.0.8

func IntParam(name, label, info string, defValue int, ptr *int, enums ...Entry) Param

func StringParam added in v0.0.8

func StringParam(name, label, info, defValue string, ptr *string, enums ...Entry) Param

type ParamData

type ParamData map[string]interface{}

func ParseParams added in v0.0.8

func ParseParams(str string, params []Param) (data ParamData, err error)

func (ParamData) GetFloat

func (d ParamData) GetFloat(key string, defaultValue float64) float64

func (ParamData) GetString

func (d ParamData) GetString(key, defaultValue string) string

type VBalance

type VBalance struct {
	// contains filtered or unexported fields
}

func NewVBalance

func NewVBalance() *VBalance

func (*VBalance) AddTrade

func (b *VBalance) AddTrade(tr Trade) (profit, onceFee float64, err error)

func (*VBalance) AvgOpenPrice added in v0.1.7

func (b *VBalance) AvgOpenPrice() (price float64)

func (*VBalance) Get

func (b *VBalance) Get() (total float64)

func (*VBalance) GetFeeTotal

func (b *VBalance) GetFeeTotal() (fee float64)

func (*VBalance) Pos

func (b *VBalance) Pos() (pos float64)

func (*VBalance) Set

func (b *VBalance) Set(total float64)

func (*VBalance) SetFee

func (b *VBalance) SetFee(fee float64)

Jump to

Keyboard shortcuts

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