model

package
v0.0.0-...-832224e Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const InternalCalculationsPrecision = 15

InternalCalculationsPrecision is the precision to be used for internal calculations in a function

View Source
const InvertPrecision = 11

InvertPrecision is the precision of the number after it is inverted this is only 11 becuase if we keep it larger such as 15 then inversions are inaccurate for larger numbers such as inverting 0.00002

Variables

View Source
var CcxtAssetConverter = Display

CcxtAssetConverter is the asset converter for the CCXT exchange interface

View Source
var Display = displayAssetConverter{}

Display is a basic string-mapping converter for display purposes

View Source
var KrakenAssetConverter = makeAssetConverter(map[Asset]string{
	XLM:  "XXLM",
	BTC:  "XXBT",
	USD:  "ZUSD",
	ETH:  "XETH",
	LTC:  "XLTC",
	REP:  "XREP",
	ADA:  "ADA",
	BCH:  "BCH",
	DASH: "DASH",
	EOS:  "EOS",
	GNO:  "GNO",
	FEE:  "KFEE",
	QTUM: "QTUM",
	USDT: "USDT",
	DAO:  "XDAO",
	ETC:  "XETC",
	ICN:  "XICN",
	MLN:  "XMLN",
	NMC:  "XNMC",
	XDG:  "XXDG",
	XMR:  "XXMR",
	XRP:  "XXRP",
	XVN:  "XXVN",
	ZEC:  "XZEC",
	CAD:  "ZCAD",
	EUR:  "ZEUR",
	GBP:  "ZGBP",
	JPY:  "ZJPY",
	KRW:  "ZKRW",
})

KrakenAssetConverter is the asset converter for the Kraken exchange

View Source
var KrakenAssetConverterOpenOrders = makeAssetConverter(map[Asset]string{
	XLM:  "XLM",
	BTC:  "XBT",
	USD:  "USD",
	USDT: "USDT",
	REP:  "REP",
	ETH:  "ETH",
})

KrakenAssetConverterOpenOrders is the asset converter for the Kraken exchange's GetOpenOrders API

View Source
var NumberConstants = struct {
	Zero *Number
	One  *Number
}{
	Zero: NumberFromFloat(0.0, 16),
	One:  NumberFromFloat(1.0, 16),
}

NumberConstants holds some useful constants

Functions

func IsBotKey

func IsBotKey(key string) bool

IsBotKey checks whether a given string is a BotKey

func SplitDataKey

func SplitDataKey(key string) (string, string)

SplitDataKey splits the data key on the account into the hash and part

func TradingPairs2Strings

func TradingPairs2Strings(c AssetConverterInterface, delim string, pairs []TradingPair) (map[TradingPair]string, error)

TradingPairs2Strings converts the trading pairs to an array of strings

func TradingPairs2Strings2

func TradingPairs2Strings2(c AssetConverterInterface, delim string, pairs []*TradingPair) (map[TradingPair]string, error)

TradingPairs2Strings2 converts the trading pairs to an array of strings

Types

type Asset

type Asset string

Asset is typed and enlists the allowed assets that are understood by the bot

const (
	XLM     Asset = "XLM"
	BTC     Asset = "BTC"
	USD     Asset = "USD"
	ETH     Asset = "ETH"
	LTC     Asset = "LTC"
	REP     Asset = "REP"
	ADA     Asset = "ADA"
	BCH     Asset = "BCH"
	DASH    Asset = "DASH"
	EOS     Asset = "EOS"
	GNO     Asset = "GNO"
	GRIN    Asset = "GRIN"
	FEE     Asset = "FEE"
	QTUM    Asset = "QTUM"
	USDT    Asset = "USDT"
	TUSD    Asset = "TUSD"
	USDC    Asset = "USDC"
	USDS    Asset = "USDS"
	PAX     Asset = "PAX"
	BUSD    Asset = "BUSD"
	DAI     Asset = "DAI"
	DAO     Asset = "DAO"
	ETC     Asset = "ETC"
	ICN     Asset = "ICN"
	MLN     Asset = "MLN"
	NMC     Asset = "NMC"
	XDG     Asset = "XDG"
	XMR     Asset = "XMR"
	XRP     Asset = "XRP"
	XVN     Asset = "XVN"
	ZEC     Asset = "ZEC"
	CAD     Asset = "CAD"
	EUR     Asset = "EUR"
	GBP     Asset = "GBP"
	JPY     Asset = "JPY"
	KRW     Asset = "KRW"
	OMG     Asset = "OMG"
	MANA    Asset = "MANA"
	BULL    Asset = "BULL"
	ETHBULL Asset = "ETHBULL"
)

this is the list of assets understood by the bot. This string can be converted by the specific exchange adapter as is needed by the exchange's API

func FromHorizonAsset

func FromHorizonAsset(hAsset hProtocol.Asset) Asset

FromHorizonAsset is a factory method

type AssetConverter

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

AssetConverter converts to and from the asset type, it is specific to an exchange

func (AssetConverter) FromString

func (c AssetConverter) FromString(s string) (Asset, error)

FromString converts from a string to an asset

func (AssetConverter) MustFromString

func (c AssetConverter) MustFromString(s string) Asset

MustFromString converts from a string to an asset, failing on errors

func (AssetConverter) ToString

func (c AssetConverter) ToString(a Asset) (string, error)

ToString converts an asset to a string

type AssetConverterInterface

type AssetConverterInterface interface {
	ToString(a Asset) (string, error)
	FromString(s string) (Asset, error)
	MustFromString(s string) Asset
}

AssetConverterInterface is the interface which allows the creation of asset converters with logic instead of static bindings

type AssetDisplayFn

type AssetDisplayFn func(Asset) (string, error)

AssetDisplayFn is a convenient way to encapsulate the logic to display an Asset

func MakePassthroughAssetDisplayFn

func MakePassthroughAssetDisplayFn() AssetDisplayFn

MakePassthroughAssetDisplayFn is a factory method for a commonly used AssetDisplayFn

func MakeSdexMappedAssetDisplayFn

func MakeSdexMappedAssetDisplayFn(sdexAssetMap map[Asset]hProtocol.Asset) AssetDisplayFn

MakeSdexMappedAssetDisplayFn is a factory method for a commonly used AssetDisplayFn

type BotKey

type BotKey struct {
	AssetBaseCode    string
	AssetBaseIssuer  string
	AssetQuoteCode   string
	AssetQuoteIssuer string
	// contains filtered or unexported fields
}

BotKey is a unique key to identify a bot

func MakeSortedBotKey

func MakeSortedBotKey(assetA hProtocol.Asset, assetB hProtocol.Asset) *BotKey

MakeSortedBotKey makes a BotKey by sorting the passed in assets

func (*BotKey) FullKey

func (b *BotKey) FullKey(part int) string

FullKey returns the full key to be used in the manageData operation

func (*BotKey) Hash

func (b *BotKey) Hash() string

Hash returns the hash of the underlying key

func (*BotKey) HashWithPrefix

func (b *BotKey) HashWithPrefix() string

HashWithPrefix returns the hash prefixed with "b/"

func (*BotKey) Key

func (b *BotKey) Key() string

Key returns the unique key string for this BotKey

func (BotKey) String

func (b BotKey) String() string

String impl

type CancelOrderResult

type CancelOrderResult int8

CancelOrderResult is the result of a CancelOrder call

const (
	CancelResultCancelSuccessful CancelOrderResult = 0
	CancelResultPending          CancelOrderResult = 1
	CancelResultFailed           CancelOrderResult = 2
)

These are the available types

func (CancelOrderResult) String

func (r CancelOrderResult) String() string

String is the stringer function

type Number

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

Number abstraction

func InvertNumber

func InvertNumber(n *Number) *Number

InvertNumber inverts a number, returns nil if the original number is nil, preserves precision

func MustNumberFromString

func MustNumberFromString(s string, precision int8) *Number

MustNumberFromString panics when there's an error

func NumberByCappingPrecision

func NumberByCappingPrecision(n *Number, precision int8) *Number

NumberByCappingPrecision returns a number with a precision that is at max the passed in precision

func NumberFromFloat

func NumberFromFloat(f float64, precision int8) *Number

NumberFromFloat makes a Number from a float by rounding up

func NumberFromFloatRoundTruncate

func NumberFromFloatRoundTruncate(f float64, precision int8) *Number

NumberFromFloatRoundTruncate makes a Number from a float by truncating beyond the specified precision

func NumberFromString

func NumberFromString(s string, precision int8) (*Number, error)

NumberFromString makes a Number from a string, by calling NumberFromFloat

func (Number) Abs

func (n Number) Abs() *Number

Abs returns the absolute of the number

func (Number) Add

func (n Number) Add(n2 Number) *Number

Add returns a new Number after adding the passed in Number

func (Number) AsFloat

func (n Number) AsFloat() float64

AsFloat gives a float64 representation

func (Number) AsRatio

func (n Number) AsRatio() (int32, int32, error)

AsRatio returns an integer numerator and denominator

func (Number) AsString

func (n Number) AsString() string

AsString gives a string representation

func (Number) Divide

func (n Number) Divide(n2 Number) *Number

Divide returns a new Number after dividing by the passed in Number by rounding up based on the smaller precision

func (Number) DivideRoundTruncate

func (n Number) DivideRoundTruncate(n2 Number) *Number

DivideRoundTruncate returns a new Number after dividing by the passed in Number by truncating based on the smaller precision

func (Number) EqualsPrecisionNormalized

func (n Number) EqualsPrecisionNormalized(n2 Number, epsilon float64) bool

EqualsPrecisionNormalized returns true if the two numbers are the same after comparing them at the same (lowest) precision level

func (Number) Multiply

func (n Number) Multiply(n2 Number) *Number

Multiply returns a new Number after multiplying with the passed in Number by rounding up based on the smaller precision

func (Number) MultiplyRoundTruncate

func (n Number) MultiplyRoundTruncate(n2 Number) *Number

MultiplyRoundTruncate returns a new Number after multiplying with the passed in Number by truncating based on the smaller precision

func (Number) Negate

func (n Number) Negate() *Number

Negate returns the negative value of the number

func (Number) Precision

func (n Number) Precision() int8

Precision gives the precision of the Number

func (Number) Scale

func (n Number) Scale(scaleFactor float64) *Number

Scale takes in a scalar with which to multiply the number using the same precision of the original number

func (Number) String

func (n Number) String() string

String is the Stringer interface impl.

func (Number) Subtract

func (n Number) Subtract(n2 Number) *Number

Subtract returns a new Number after subtracting out the passed in Number

type OpenOrder

type OpenOrder struct {
	Order
	ID             string
	StartTime      *Timestamp
	ExpireTime     *Timestamp
	VolumeExecuted *Number
}

OpenOrder represents an open order for a trading account

func (OpenOrder) String

func (o OpenOrder) String() string

String is the stringer function

type Order

type Order struct {
	Pair        *TradingPair
	OrderAction OrderAction
	OrderType   OrderType
	Price       *Number
	Volume      *Number
	Timestamp   *Timestamp
}

Order represents an order in the orderbook

func (Order) String

func (o Order) String() string

String is the stringer function

type OrderAction

type OrderAction bool

OrderAction is the action of buy / sell

const (
	OrderActionBuy  OrderAction = false
	OrderActionSell OrderAction = true
)

OrderActionBuy and OrderActionSell are the two actions

func OrderActionFromString

func OrderActionFromString(s string) OrderAction

OrderActionFromString is a convenience to convert from common strings to the corresponding OrderAction

func (OrderAction) IsBuy

func (a OrderAction) IsBuy() bool

IsBuy returns true for buy actions

func (OrderAction) IsSell

func (a OrderAction) IsSell() bool

IsSell returns true for sell actions

func (OrderAction) Reverse

func (a OrderAction) Reverse() OrderAction

Reverse returns the opposite action

func (OrderAction) String

func (a OrderAction) String() string

String is the stringer function

type OrderBook

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

OrderBook encapsulates the concept of an orderbook on a market

func MakeOrderBook

func MakeOrderBook(pair *TradingPair, asks []Order, bids []Order) *OrderBook

MakeOrderBook creates a new OrderBook from the asks and the bids

func (OrderBook) Asks

func (o OrderBook) Asks() []Order

Asks returns the asks in an orderbook

func (OrderBook) Bids

func (o OrderBook) Bids() []Order

Bids returns the bids in an orderbook

func (OrderBook) Pair

func (o OrderBook) Pair() *TradingPair

Pair returns trading pair

func (OrderBook) TopAsk

func (o OrderBook) TopAsk() *Order

TopAsk returns the best ask in an orderbook

func (OrderBook) TopBid

func (o OrderBook) TopBid() *Order

TopBid returns the best bid in an orderbook

type OrderConstraints

type OrderConstraints struct {
	PricePrecision  int8
	VolumePrecision int8
	MinBaseVolume   Number
	MinQuoteVolume  *Number
}

OrderConstraints describes constraints when placing orders on an excahnge

func MakeOrderConstraints

func MakeOrderConstraints(pricePrecision int8, volumePrecision int8, minBaseVolume float64) *OrderConstraints

MakeOrderConstraints is a factory method for OrderConstraints

func MakeOrderConstraintsFromOverride

func MakeOrderConstraintsFromOverride(override *OrderConstraintsOverride) *OrderConstraints

MakeOrderConstraintsFromOverride is a factory method to convert an OrderConstraintsOverride to an OrderConstraints

func MakeOrderConstraintsWithCost

func MakeOrderConstraintsWithCost(pricePrecision int8, volumePrecision int8, minBaseVolume float64, minQuoteVolume float64) *OrderConstraints

MakeOrderConstraintsWithCost is a factory method for OrderConstraints

func MakeOrderConstraintsWithOverride

func MakeOrderConstraintsWithOverride(oc OrderConstraints, override *OrderConstraintsOverride) *OrderConstraints

MakeOrderConstraintsWithOverride is a factory method for OrderConstraints, oc is not a pointer because we want a copy since we modify it

func (*OrderConstraints) String

func (o *OrderConstraints) String() string

OrderConstraints describes constraints when placing orders on an excahnge

type OrderConstraintsOverride

type OrderConstraintsOverride struct {
	PricePrecision  *int8
	VolumePrecision *int8
	MinBaseVolume   *Number
	MinQuoteVolume  **Number
}

OrderConstraintsOverride describes an override for an OrderConstraint

func MakeOrderConstraintsOverride

func MakeOrderConstraintsOverride(
	pricePrecision *int8,
	volumePrecision *int8,
	minBaseVolume *Number,
	minQuoteVolume **Number,
) *OrderConstraintsOverride

MakeOrderConstraintsOverride is a factory method

func MakeOrderConstraintsOverrideFromConstraints

func MakeOrderConstraintsOverrideFromConstraints(oc *OrderConstraints) *OrderConstraintsOverride

MakeOrderConstraintsOverrideFromConstraints is a factory method for OrderConstraintsOverride

func (*OrderConstraintsOverride) Augment

func (override *OrderConstraintsOverride) Augment(updates *OrderConstraintsOverride)

Augment only updates values if updates are non-nil

func (*OrderConstraintsOverride) IsComplete

func (override *OrderConstraintsOverride) IsComplete() bool

IsComplete returns true if the override contains all values

type OrderType

type OrderType int8

OrderType represents a type of an order, example market, limit, etc.

const (
	OrderTypeMarket OrderType = 0
	OrderTypeLimit  OrderType = 1
)

These are the available order types

func OrderTypeFromString

func OrderTypeFromString(s string) OrderType

OrderTypeFromString is a convenience to convert from common strings to the corresponding OrderType

func (OrderType) IsLimit

func (o OrderType) IsLimit() bool

IsLimit returns true for limit orders

func (OrderType) IsMarket

func (o OrderType) IsMarket() bool

IsMarket returns true for market orders

func (OrderType) String

func (o OrderType) String() string

String is the stringer function

type Rounding

type Rounding int

Rounding is a type that defines various approaching to rounding numbers

const (
	RoundUp Rounding = iota
	RoundTruncate
)

Rounding types

type Timestamp

type Timestamp int64

Timestamp is millis since epoch

func MakeTimestamp

func MakeTimestamp(ts int64) *Timestamp

MakeTimestamp creates a new Timestamp

func MakeTimestampFromTime

func MakeTimestampFromTime(t time.Time) *Timestamp

MakeTimestampFromTime creates a new Timestamp

func (*Timestamp) AsInt64

func (t *Timestamp) AsInt64() int64

AsInt64 is a convenience method

func (*Timestamp) String

func (t *Timestamp) String() string

type Trade

type Trade struct {
	Order
	TransactionID *TransactionID
	OrderID       string
	Cost          *Number
	Fee           *Number
}

Trade represents a trade on an exchange

func (Trade) String

func (t Trade) String() string

type TradesByTsID

type TradesByTsID []Trade

TradesByTsID implements sort.Interface for []Trade based on Timestamp and TransactionID

func (TradesByTsID) Len

func (t TradesByTsID) Len() int

func (TradesByTsID) Less

func (t TradesByTsID) Less(i int, j int) bool

func (TradesByTsID) Swap

func (t TradesByTsID) Swap(i int, j int)

type TradingPair

type TradingPair struct {
	// Base represents the asset that has a unit of 1 (implicit)
	Base Asset
	// Quote (or Counter) represents the asset that has its unit specified relative to the base asset
	Quote Asset
}

TradingPair lists an ordered pair that is understood by the bot and our exchange API. EUR/USD = 1.25; EUR is base, USD is Quote. EUR is more valuable in this example USD/EUR = 0.80; USD is base, EUR is Quote. EUR is more valuable in this example

func MakeTradingPair

func MakeTradingPair(base Asset, quote Asset) *TradingPair

MakeTradingPair is a factory method

func TradingPairFromString

func TradingPairFromString(codeSize int8, c AssetConverterInterface, p string) (*TradingPair, error)

TradingPairFromString makes a TradingPair out of a string

func TradingPairFromString2

func TradingPairFromString2(codeSize int8, converters []AssetConverterInterface, p string) (*TradingPair, error)

TradingPairFromString2 makes a TradingPair out of a string

func (TradingPair) String

func (p TradingPair) String() string

String is the stringer function

func (TradingPair) ToString

func (p TradingPair) ToString(c AssetConverterInterface, delim string) (string, error)

ToString converts the trading pair to a string using the passed in assetConverterInterface

type TransactionID

type TransactionID string

TransactionID is typed for the concept of a transaction ID of an order

func MakeTransactionID

func MakeTransactionID(s string) *TransactionID

MakeTransactionID is a factory method for convenience

func (*TransactionID) AsInt64

func (t *TransactionID) AsInt64() (int64, error)

AsInt64 converts to an integer

func (*TransactionID) String

func (t *TransactionID) String() string

String is the stringer function

Jump to

Keyboard shortcuts

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