margin

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMarginType returned when the margin type is invalid
	ErrInvalidMarginType = errors.New("invalid margin type")
	// ErrMarginTypeUnsupported returned when the margin type is unsupported
	ErrMarginTypeUnsupported = errors.New("unsupported margin type")
	// ErrNewAllocatedMarginRequired returned when the new allocated margin is missing and is required
	ErrNewAllocatedMarginRequired = errors.New("new allocated margin required")
	// ErrOriginalPositionMarginRequired is returned when original position margin is empty and is required
	ErrOriginalPositionMarginRequired = errors.New("original allocated margin required")
)

Functions

func IsValidString

func IsValidString(m string) bool

IsValidString checks to see if the supplied string is a valid margin type

Types

type BorrowCost

type BorrowCost struct {
	Cost decimal.Decimal
	Size decimal.Decimal
}

BorrowCost contains the borrow rate costs

type LendingPayment

type LendingPayment struct {
	Payment decimal.Decimal
	Size    decimal.Decimal
}

LendingPayment contains a lending rate payment

type PositionChangeRequest

type PositionChangeRequest struct {
	// Required fields
	Exchange string
	Pair     currency.Pair
	Asset    asset.Item
	// Optional fields depending on desired outcome/exchange requirements
	MarginType              Type
	OriginalAllocatedMargin float64
	NewAllocatedMargin      float64
	MarginSide              string
}

PositionChangeRequest used for wrapper functions to change margin fields for a position

type PositionChangeResponse

type PositionChangeResponse struct {
	Exchange        string
	Pair            currency.Pair
	Asset           asset.Item
	AllocatedMargin float64
	MarginType      Type
}

PositionChangeResponse holds response data for margin change requests

type Rate

type Rate struct {
	Time             time.Time
	MarketBorrowSize decimal.Decimal
	HourlyRate       decimal.Decimal
	YearlyRate       decimal.Decimal
	HourlyBorrowRate decimal.Decimal
	YearlyBorrowRate decimal.Decimal
	LendingPayment   LendingPayment
	BorrowCost       BorrowCost
}

Rate has the funding rate details and optionally the borrow rate

type RateHistoryRequest

type RateHistoryRequest struct {
	Exchange         string
	Asset            asset.Item
	Currency         currency.Code
	Pair             currency.Pair
	StartDate        time.Time
	EndDate          time.Time
	GetPredictedRate bool

	GetLendingPayments bool
	GetBorrowRates     bool
	GetBorrowCosts     bool

	// CalculateOffline allows for the borrow rate, lending payment amount
	// and borrow costs to be calculated offline. It requires the takerfeerate
	// and existing rates
	CalculateOffline bool
	TakeFeeRate      decimal.Decimal
	// Rates is used when calculating offline and determiningPayments
	// Each Rate must have the Rate and Size fields populated
	Rates []Rate
}

RateHistoryRequest is used to request a funding rate

type RateHistoryResponse

type RateHistoryResponse struct {
	Rates              []Rate
	SumBorrowCosts     decimal.Decimal
	AverageBorrowSize  decimal.Decimal
	SumLendingPayments decimal.Decimal
	AverageLendingSize decimal.Decimal
	PredictedRate      Rate
	TakerFeeRate       decimal.Decimal
}

RateHistoryResponse has the funding rate details

type Type

type Type uint8

Type defines the different margin types supported by exchanges

const (
	// Unset is the default value
	Unset = Type(0)
	// Isolated means a margin trade is isolated from other margin trades
	Isolated Type = 1 << (iota - 1)
	// Multi means a margin trade is not isolated from other margin trades
	// it can sometimes be referred to as "cross"
	Multi
	// Unknown is an unknown margin type but is not unset
	Unknown
)

Margin types

func StringToMarginType

func StringToMarginType(m string) (Type, error)

StringToMarginType converts a string to a margin type doesn't error, just returns unknown if the string is not recognised

func (Type) String

func (t Type) String() string

String returns the string representation of the margin type in lowercase the absence of a lower func should hopefully highlight that String is lower

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(d []byte) error

UnmarshalJSON converts json into margin type

func (Type) Upper

func (t Type) Upper() string

Upper returns the upper case string representation of the margin type

func (Type) Valid

func (t Type) Valid() bool

Valid returns whether the margin type is valid

Jump to

Keyboard shortcuts

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