utils

package
v0.0.0-...-ea1cebd Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxPreciseFloat64Integer int64 = 1 << 53
View Source
const MinPreciseFloat64Integer int64 = -(1 << 53)

Variables

View Source
var D10 *apd.Decimal = Reduce(apd.New(10, 0)) // Shoudln't be mutated
View Source
var D100 *apd.Decimal = Reduce(apd.New(100, 0)) // Shoudln't be mutated
View Source
var One *apd.Decimal = Reduce(apd.New(1, 0)) // Shoudln't be mutated
View Source
var Zero *apd.Decimal = Reduce(apd.New(0, 0)) // Shoudln't be mutated

Functions

func Abs

func Abs(a *apd.Decimal) *apd.Decimal

|a|

func Add

func Add(a, b *apd.Decimal) *apd.Decimal

a + b

func CeilFloat

func CeilFloat(val float64, precision uint32) float64

func Div

func Div(a, b *apd.Decimal) *apd.Decimal

a/b

func Eq

func Eq(a, b *apd.Decimal) bool

a == b

func FindPrecisionFromTickSize

func FindPrecisionFromTickSize(tickSize string) *int

Ticksize format should be 0.xxx

func FloorFloat

func FloorFloat(val float64, precision uint32) float64

func FromFloat64

func FromFloat64(x float64) *apd.Decimal

Only 15 places precision

func FromString

func FromString(x string) *apd.Decimal

func FromStringErr

func FromStringErr(x string) (*apd.Decimal, error)

func FromUint

func FromUint(x uint) *apd.Decimal

func GenClientOrderID

func GenClientOrderID(identifierID string) (string, error)

func Greater

func Greater(a, b *apd.Decimal) bool

a > b

func GreaterOrEq

func GreaterOrEq(a, b *apd.Decimal) bool

a >= b

func Less

func Less(a, b *apd.Decimal) bool

a < b

func LessOrEq

func LessOrEq(a, b *apd.Decimal) bool

a <= b

func MinInt

func MinInt(a, b int) int

func Mod

func Mod(a, b *apd.Decimal) *apd.Decimal

a%b

func Mul

func Mul(a, b *apd.Decimal) *apd.Decimal

a/b

func Neg

func Neg(a *apd.Decimal) *apd.Decimal

-a

func NewZero

func NewZero() *apd.Decimal

func Reduce

func Reduce(x *apd.Decimal) *apd.Decimal

func ReplaceError

func ReplaceError(new, old error) error

func Round

func Round(a *apd.Decimal) *apd.Decimal

func RoundFloat

func RoundFloat(val float64, precision uint32) float64

func SetFloat64

func SetFloat64(a float64) *apd.Decimal

Convert float64 to decimal

func Sub

func Sub(a, b *apd.Decimal) *apd.Decimal

a - b

func TimePtr

func TimePtr(t time.Time) *time.Time

func TimeUNIXMillis

func TimeUNIXMillis(t time.Time) int64

func ToFlatString

func ToFlatString(x *apd.Decimal) string

Returns flat, non scientific string representation 1000 will be "1000" not like this "1E3" 0.001 will be as "0.001" not like "1E-3"

func ToIntegerInFloat64

func ToIntegerInFloat64(a *apd.Decimal) (float64, error)

func WSConnectAndWatch

func WSConnectAndWatch(ctx context.Context, cfg *WSConfig, lg *zap.Logger) (<-chan WSMessage, error)

func WSWatch

func WSWatch(ctx context.Context, c *websocket.Conn, cfg *WSConfig, lg *zap.Logger) (<-chan WSMessage, error)

Types

type APDJSON

type APDJSON struct {
	Value *apd.Decimal
}

func (*APDJSON) UnmarshalJSON

func (num *APDJSON) UnmarshalJSON(in []byte) error

type CancellableTimer

type CancellableTimer struct {
	C chan struct{}
	// contains filtered or unexported fields
}

func NewCancellableTimer

func NewCancellableTimer() *CancellableTimer

func (*CancellableTimer) Start

func (t *CancellableTimer) Start(d time.Duration)

func (*CancellableTimer) Stop

func (t *CancellableTimer) Stop()

Stop can be called many times. Works on already stopeed timer.

type ChangeableMinuteRateLimiter

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

func NewChangeableMinuteRateLimiter

func NewChangeableMinuteRateLimiter(maxPerMinute int) *ChangeableMinuteRateLimiter

func (*ChangeableMinuteRateLimiter) SetNextDuration

func (r *ChangeableMinuteRateLimiter) SetNextDuration(d time.Duration)

func (*ChangeableMinuteRateLimiter) SetRemaining

func (r *ChangeableMinuteRateLimiter) SetRemaining(at time.Time, remaining uint)

func (*ChangeableMinuteRateLimiter) Wait

func (r *ChangeableMinuteRateLimiter) Wait()

type MinuteRateLimiter

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

func NewMinuteRateLimiter

func NewMinuteRateLimiter(maxPerMinute int) *MinuteRateLimiter

func (*MinuteRateLimiter) Wait

func (r *MinuteRateLimiter) Wait()

type NullJSONValue

type NullJSONValue struct{}

NullJSONValue is used as workaround for Golang's case-insensitive JSON

func (*NullJSONValue) MarshalJSON

func (m *NullJSONValue) MarshalJSON() ([]byte, error)

func (*NullJSONValue) UnmarshalJSON

func (m *NullJSONValue) UnmarshalJSON(data []byte) error

type RemainingForMinute

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

type WSConfig

type WSConfig struct {
	Endpoint           string
	InitialTextMessage []byte
	KeepAlive          bool
	Timeout            time.Duration
	HeartbeatInterval  time.Duration
}

WSConfig webservice configuration

type WSMessage

type WSMessage struct {
	Payload             []byte
	DisconnectedWithErr error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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