types

package
v0.0.0-...-5ae7496 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const OHLCVChannel = "ohlcv"
View Source
const OrderChannel = "orders"
View Source
const OrderbookChannel = "order_book"
View Source
const TradeChannel = "trades"

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID            bson.ObjectId            `json:"-" bson:"_id"`
	Address       string                   `json:"address" bson:"address"`
	TokenBalances map[string]*TokenBalance `json:"tokenBalances" bson:"tokenBalances"`
	IsBlocked     bool                     `json:"isBlocked" bson:"isBlocked"`
	CreatedAt     time.Time                `json:"createdAt" bson:"createdAt"`
	UpdatedAt     time.Time                `json:"updatedAt" bson:"updatedAt"`
}

Account corresponds to a single Obyte address. It contains a list of token balances for that address

func (*Account) GetBSON

func (a *Account) GetBSON() (interface{}, error)

GetBSON implements bson.Getter

func (*Account) MarshalJSON

func (a *Account) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshal interface

func (*Account) SetBSON

func (a *Account) SetBSON(raw bson.Raw) error

SetBSON implemenets bson.Setter

func (*Account) UnmarshalJSON

func (a *Account) UnmarshalJSON(b []byte) error

func (Account) Validate

func (a Account) Validate() error

Validate enforces the account model

type AccountBSONUpdate

type AccountBSONUpdate struct {
	*Account
}

func (*AccountBSONUpdate) GetBSON

func (a *AccountBSONUpdate) GetBSON() (interface{}, error)

type AccountRecord

type AccountRecord struct {
	ID            bson.ObjectId                 `json:"id" bson:"_id"`
	Address       string                        `json:"address" bson:"address"`
	TokenBalances map[string]TokenBalanceRecord `json:"tokenBalances" bson:"tokenBalances"`
	IsBlocked     bool                          `json:"isBlocked" bson:"isBlocked"`
	CreatedAt     time.Time                     `json:"createdAt" bson:"createdAt"`
	UpdatedAt     time.Time                     `json:"updatedAt" bson:"updatedAt"`
}

AccountRecord corresponds to what is stored in the DB.

type EngineResponse

type EngineResponse struct {
	Status            string    `json:"fillStatus,omitempty"`
	Order             *Order    `json:"order,omitempty"`
	Matches           *Matches  `json:"matches,omitempty"`
	RecoveredOrders   *[]*Order `json:"recoveredOrders,omitempty"`
	InvalidatedOrders *[]*Order `json:"invalidatedOrders,omitempty"`
	CancelledTrades   *[]*Trade `json:"cancelledTrades,omitempty"`
}

func (*EngineResponse) AppendMatch

func (r *EngineResponse) AppendMatch(mo *Order, t *Trade)

func (*EngineResponse) AppendMatches

func (r *EngineResponse) AppendMatches(mo []*Order, t []*Trade)

type ExchangeData

type ExchangeData struct {
	PairData             []*PairAPIData `json:"pairData"`
	TotalOrders          int            `json:"totalOrders"`
	TotalTrades          int            `json:"totalTrades"`
	TotalSellOrders      int            `json:"totalSellOrders"`
	TotalBuyOrders       int            `json:"totalBuyOrders"`
	TotalBuyOrderAmount  float64        `json:"totalBuyAmount"`
	TotalSellOrderAmount float64        `json:"totalSellAmount"`
	TotalVolume          float64        `json:"totalVolume"`
	TotalOrderAmount     float64        `json:"totalOrderAmount"`
	MostTradedToken      string         `json:"mostTradedToken"`
	MostTradedPair       string         `json:"mostTradedPair"`
	TradeSuccessRatio    float64        `json:"tradeSuccessRatio"`
}

type ExchangeLogError

type ExchangeLogError struct {
	ErrorId        uint8
	MakerOrderHash string
	TakerOrderHash string
}

type ExchangeStats

type ExchangeStats struct {
	TotalOrders          int     `json:"totalOrders"`
	TotalTrades          int     `json:"totalTrades"`
	TotalSellOrders      int     `json:"totalSellOrders"`
	TotalBuyOrders       int     `json:"totalBuyOrders"`
	TotalBuyOrderAmount  float64 `json:"totalBuyAmount"`
	TotalSellOrderAmount float64 `json:"totalSellAmount"`
	TotalVolume          float64 `json:"totalVolume"`
	TotalOrderAmount     float64 `json:"totalOrderAmount"`
	MostTradedToken      string  `json:"mostTradedToken"`
	MostTradedPair       string  `json:"mostTradedPair"`
	TradeSuccessRatio    float64 `json:"tradeSuccessRatio"`
}

type Matches

type Matches struct {
	MakerOrders []*Order `json:"makerOrders"`
	TakerOrder  *Order   `json:"takerOrder"`
	Trades      []*Trade `json:"trades"`
}

func NewMatches

func NewMatches(makerOrders []*Order, takerOrder *Order, trades []*Trade) *Matches

func (*Matches) AppendMatch

func (m *Matches) AppendMatch(mo *Order, t *Trade)

func (*Matches) Length

func (m *Matches) Length() int

func (*Matches) NthMatch

func (m *Matches) NthMatch(i int) *Matches

func (*Matches) PairCode

func (m *Matches) PairCode() (string, error)

func (*Matches) String

func (m *Matches) String() string

func (*Matches) Taker

func (m *Matches) Taker() string

func (*Matches) TakerOrderHash

func (m *Matches) TakerOrderHash() string

func (*Matches) TradeAmounts

func (m *Matches) TradeAmounts() []int64

func (*Matches) Validate

func (m *Matches) Validate() error

type NewOrderPayload

type NewOrderPayload struct {
	PairName         string  `json:"pairName"`
	MatcherAddress   string  `json:"matcherAddress"`
	AffiliateAddress string  `json:"affiliateAddress"`
	UserAddress      string  `json:"userAddress"`
	BaseToken        string  `json:"baseToken"`
	QuoteToken       string  `json:"quoteToken"`
	Side             string  `json:"side"`
	Amount           int64   `json:"amount"`
	Price            float64 `json:"price"`
	Hash             string  `json:"hash"`
}

NewOrderPayload is the struct in which the order request sent by the user is populated

func (*NewOrderPayload) EncodedSide

func (p *NewOrderPayload) EncodedSide() int64

func (NewOrderPayload) MarshalJSON

func (p NewOrderPayload) MarshalJSON() ([]byte, error)

func (*NewOrderPayload) ToOrder

func (p *NewOrderPayload) ToOrder() (o *Order, err error)

ToOrder converts the NewOrderPayload to Order

func (*NewOrderPayload) UnmarshalJSON

func (p *NewOrderPayload) UnmarshalJSON(b []byte) error

func (NewOrderPayload) Validate

func (p NewOrderPayload) Validate() error

Validate validates the NewOrderPayload fields.

type OHLCVParams

type OHLCVParams struct {
	Pair     []PairAssets `json:"pair"`
	From     int64        `json:"from"`
	To       int64        `json:"to"`
	Duration int64        `json:"duration"`
	Units    string       `json:"units"`
}

type OperatorMessage

type OperatorMessage struct {
	MessageType string
	Matches     *Matches
	ErrorType   string
}

func (*OperatorMessage) String

func (m *OperatorMessage) String() string

type Order

type Order struct {
	ID                  bson.ObjectId          `json:"id" bson:"_id"`
	UserAddress         string                 `json:"userAddress" bson:"userAddress"`
	MatcherAddress      string                 `json:"matcherAddress" bson:"matcherAddress"`
	AffiliateAddress    string                 `json:"affiliateAddress" bson:"affiliateAddress"`
	BaseToken           string                 `json:"baseToken" bson:"baseToken"`
	QuoteToken          string                 `json:"quoteToken" bson:"quoteToken"`
	Status              string                 `json:"status" bson:"status"`
	Side                string                 `json:"side" bson:"side"`
	Hash                string                 `json:"hash" bson:"hash"`
	Price               float64                `json:"price" bson:"price"`
	Amount              int64                  `json:"amount" bson:"amount"`
	FilledAmount        int64                  `json:"filledAmount" bson:"filledAmount"`
	RemainingSellAmount int64                  `json:"remainingSellAmount" bson:"remainingSellAmount"`
	PairName            string                 `json:"pairName" bson:"pairName"`
	OriginalOrder       map[string]interface{} `json:"originalOrder" bson:"originalOrder"`
	CreatedAt           time.Time              `json:"createdAt" bson:"createdAt"`
	UpdatedAt           time.Time              `json:"updatedAt" bson:"updatedAt"`
}

Order contains the data related to an order sent by the user

func (*Order) BaseTokenSymbol

func (o *Order) BaseTokenSymbol() string

func (*Order) BuyAmount

func (o *Order) BuyAmount(pairMultiplier int64) int64

func (*Order) BuyToken

func (o *Order) BuyToken() string

func (*Order) BuyTokenSymbol

func (o *Order) BuyTokenSymbol() string

func (*Order) EncodedSide

func (o *Order) EncodedSide() int64

TODO handle error case ?

func (*Order) GetBSON

func (o *Order) GetBSON() (interface{}, error)

func (*Order) MarshalJSON

func (o *Order) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshal interface

func (*Order) MatcherFeeRate

func (o *Order) MatcherFeeRate() float64

func (*Order) OriginalPrice

func (o *Order) OriginalPrice() float64

func (*Order) Pair

func (o *Order) Pair() (*Pair, error)

func (*Order) PairCode

func (o *Order) PairCode() (string, error)

func (*Order) Process

func (o *Order) Process(p *Pair) error

func (*Order) QuoteAmount

func (o *Order) QuoteAmount(p *Pair) int64

func (*Order) QuoteTokenSymbol

func (o *Order) QuoteTokenSymbol() string

func (*Order) RemainingAmount

func (o *Order) RemainingAmount() int64

func (*Order) RemainingQuoteAmount

func (o *Order) RemainingQuoteAmount() int64

func (*Order) RequiredSellAmount

func (o *Order) RequiredSellAmount(p *Pair) int64

func (*Order) SellAmount

func (o *Order) SellAmount(p *Pair) int64

SellAmount If order is a "BUY", then sellToken = quoteToken

func (*Order) SellToken

func (o *Order) SellToken() string

TODO handle error case

func (*Order) SellTokenSymbol

func (o *Order) SellTokenSymbol() string

func (*Order) SetBSON

func (o *Order) SetBSON(raw bson.Raw) error

func (*Order) String

func (o *Order) String() string

func (*Order) TotalRequiredSellAmount

func (o *Order) TotalRequiredSellAmount(p *Pair) int64

func (*Order) UnmarshalJSON

func (o *Order) UnmarshalJSON(b []byte) error

func (*Order) Validate

func (o *Order) Validate() error

TODO: Verify userAddress, baseToken, quoteToken, etc. conditions are working

type OrderBSONUpdate

type OrderBSONUpdate struct {
	*Order
}

func (OrderBSONUpdate) GetBSON

func (o OrderBSONUpdate) GetBSON() (interface{}, error)

type OrderCancel

type OrderCancel struct {
	OrderHash   string `json:"orderHash"`
	UserAddress string `json:"userAddress"`
}

OrderCancel is a group of params used for canceling an order previously sent to the matching engine. The OrderId and OrderHash must correspond to the same order. To be valid and be able to be processed by the matching engine, the OrderCancel must include a signature by the Maker of the order corresponding to the OrderHash.

func NewOrderCancel

func NewOrderCancel() *OrderCancel

NewOrderCancel returns a new empty OrderCancel object

func (*OrderCancel) MarshalJSON

func (oc *OrderCancel) MarshalJSON() ([]byte, error)

MarshalJSON returns the json encoded byte array representing the OrderCancel struct

func (*OrderCancel) String

func (oc *OrderCancel) String() string

func (*OrderCancel) UnmarshalJSON

func (oc *OrderCancel) UnmarshalJSON(b []byte) error

UnmarshalJSON creates an OrderCancel object from a json byte string

type OrderData

type OrderData struct {
	Pair        PairID  `json:"id,omitempty" bson:"_id"`
	OrderVolume int64   `json:"orderVolume,omitempty" bson:"orderVolume"`
	OrderCount  int64   `json:"orderCount,omitempty" bson:"orderCount"`
	BestPrice   float64 `json:"bestPrice,omitempty" bson:"bestPrice"`
}

func (*OrderData) AssetCode

func (o *OrderData) AssetCode() string

func (*OrderData) ConvertedVolume

func (o *OrderData) ConvertedVolume(p *Pair, exchangeRate float64) float64

func (*OrderData) GetBSON

func (o *OrderData) GetBSON() (interface{}, error)

func (*OrderData) MarshalJSON

func (o *OrderData) MarshalJSON() ([]byte, error)

func (*OrderData) SetBSON

func (o *OrderData) SetBSON(raw bson.Raw) error

func (*OrderData) UnmarshalJSON

func (o *OrderData) UnmarshalJSON(b []byte) error

UnmarshalJSON creates a trade object from a json byte string

type OrderMatchedPayload

type OrderMatchedPayload struct {
	Matches *Matches `json:"matches"`
}

type OrderPendingPayload

type OrderPendingPayload struct {
	Matches *Matches `json:"matches"`
}

type OrderRecord

type OrderRecord struct {
	ID                  bson.ObjectId `json:"id" bson:"_id"`
	UserAddress         string        `json:"userAddress" bson:"userAddress"`
	MatcherAddress      string        `json:"matcherAddress" bson:"matcherAddress"`
	AffiliateAddress    string        `json:"affiliateAddress" bson:"affiliateAddress"`
	BaseToken           string        `json:"baseToken" bson:"baseToken"`
	QuoteToken          string        `json:"quoteToken" bson:"quoteToken"`
	Status              string        `json:"status" bson:"status"`
	Side                string        `json:"side" bson:"side"`
	Hash                string        `json:"hash" bson:"hash"`
	Price               float64       `json:"price" bson:"price"`
	Amount              int64         `json:"amount" bson:"amount"`
	FilledAmount        int64         `json:"filledAmount" bson:"filledAmount"`
	RemainingSellAmount int64         `json:"remainingSellAmount" bson:"remainingSellAmount"`

	OriginalOrder map[string]interface{} `json:"originalOrder" bson:"originalOrder"`

	PairName  string    `json:"pairName" bson:"pairName"`
	CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}

OrderRecord is the object that will be saved in the database

type OrderSuccessPayload

type OrderSuccessPayload struct {
	Matches *Matches `json:"matches"`
}

type Pair

type Pair struct {
	ID                 bson.ObjectId `json:"-" bson:"_id"`
	BaseTokenSymbol    string        `json:"baseTokenSymbol,omitempty" bson:"baseTokenSymbol"`
	BaseAsset          string        `json:"baseAsset,omitempty" bson:"baseAsset"`
	BaseTokenDecimals  int           `json:"baseTokenDecimals,omitempty" bson:"baseTokenDecimals"`
	QuoteTokenSymbol   string        `json:"quoteTokenSymbol,omitempty" bson:"quoteTokenSymbol"`
	QuoteAsset         string        `json:"quoteAsset,omitempty" bson:"quoteAsset"`
	QuoteTokenDecimals int           `json:"quoteTokenDecimals,omitempty" bson:"quoteTokenDecimals"`
	Listed             bool          `json:"listed,omitempty" bson:"listed"`
	Active             bool          `json:"active,omitempty" bson:"active"`
	Rank               int           `json:"rank,omitempty" bson:"rank"`
	CreatedAt          time.Time     `json:"-" bson:"createdAt"`
	UpdatedAt          time.Time     `json:"-" bson:"updatedAt"`
}

Pair struct is used to model the pair data in the system and DB

func (*Pair) AssetCode

func (p *Pair) AssetCode() string

func (*Pair) BaseTokenMultiplier

func (p *Pair) BaseTokenMultiplier() int64

func (*Pair) Code

func (p *Pair) Code() string

func (*Pair) GetBSON

func (p *Pair) GetBSON() (interface{}, error)

func (*Pair) GetKVPrefix

func (p *Pair) GetKVPrefix() string

func (*Pair) GetOrderBookKeys

func (p *Pair) GetOrderBookKeys() (sell, buy string)

GetOrderBookKeys

func (*Pair) MarshalJSON

func (p *Pair) MarshalJSON() ([]byte, error)

func (*Pair) MinQuoteAmount

func (p *Pair) MinQuoteAmount() int64

func (*Pair) Name

func (p *Pair) Name() string

func (*Pair) PairMultiplier

func (p *Pair) PairMultiplier() int64

func (*Pair) ParseAmount

func (p *Pair) ParseAmount(a int64) float64

func (*Pair) ParsePrice

func (p *Pair) ParsePrice(pp float64) float64

func (*Pair) QuoteTokenMultiplier

func (p *Pair) QuoteTokenMultiplier() int64

func (*Pair) SetBSON

func (p *Pair) SetBSON(raw bson.Raw) error

func (*Pair) UnmarshalJSON

func (p *Pair) UnmarshalJSON(b []byte) error

func (Pair) Validate

func (p Pair) Validate() error

Validate function is used to verify if an instance of struct satisfies all the conditions for a valid instance

func (Pair) ValidateAssets

func (p Pair) ValidateAssets() error

type PairAPIData

type PairAPIData struct {
	Pair               PairID  `json:"pair" bson:"_id"`
	Open               float64 `json:"open" bson:"open"`
	High               float64 `json:"high" bson:"high"`
	Low                float64 `json:"low" bson:"low"`
	Close              float64 `json:"close" bson:"close"`
	Volume             float64 `json:"volume" bson:"volume"`
	QuoteVolume        float64 `json:"quoteVolume" bson:"quoteVolume"`
	Timestamp          int     `json:"timestamp" bson:"timestamp"`
	OrderVolume        float64 `json:"orderVolume" bson:"orderVolume"`
	OrderCount         int     `json:"orderCount" bson:"orderCount"`
	TradeCount         int     `json:"tradeCount" bson:"tradeCount"`
	AverageOrderAmount float64 `json:"averageOrderAmount" bson:"averageOrderAmount"`
	AverageTradeAmount float64 `json:"averageTradeAmount" bson:"averageTradeAmount"`
	AskPrice           float64 `json:"askPrice" bson:"askPrice"`
	BidPrice           float64 `json:"bidPrice" bson:"bidPrice"`
	Price              float64 `json:"price" bson:"price"`
	Rank               int     `json:"rank" bson:"rank"`
}

type PairAssets

type PairAssets struct {
	Name       string `json:"name" bson:"name"`
	BaseToken  string `json:"baseToken" bson:"baseToken"`
	QuoteToken string `json:"quoteToken" bson:"quoteToken"`
}

type PairAssetsRecord

type PairAssetsRecord struct {
	Name       string `json:"name" bson:"name"`
	BaseToken  string `json:"baseToken" bson:"baseToken"`
	QuoteToken string `json:"quoteToken" bson:"quoteToken"`
}

type PairData

type PairData struct {
	Pair               PairID  `json:"pair,omitempty" bson:"_id"`
	Close              float64 `json:"close,omitempty" bson:"close"`
	Count              int64   `json:"count,omitempty" bson:"count"`
	High               float64 `json:"high,omitempty" bson:"high"`
	Low                float64 `json:"low,omitempty" bson:"low"`
	Open               float64 `json:"open,omitempty" bson:"open"`
	Volume             int64   `json:"volume,omitempty" bson:"volume"`
	QuoteVolume        int64   `json:"quoteVolume,omitempty" bson:"quoteVolume"`
	Timestamp          int64   `json:"timestamp,omitempty" bson:"timestamp"`
	OrderVolume        int64   `json:"orderVolume,omitempty" bson:"orderVolume"`
	OrderCount         int64   `json:"orderCount,omitempty" bson:"orderCount"`
	AverageOrderAmount int64   `json:"averageOrderAmount" bson:"averageOrderAmount"`
	AverageTradeAmount int64   `json:"averageTradeAmount" bson:"averageTradeAmount"`
	AskPrice           float64 `json:"askPrice,omitempty" bson:"askPrice"`
	BidPrice           float64 `json:"bidPrice,omitempty" bson:"bidPrice"`
	Price              float64 `json:"price,omitempty" bson:"price"`
	Rank               int     `json:"rank,omitempty" bson:"rank"`
}

func (*PairData) AssetCode

func (p *PairData) AssetCode() string

func (*PairData) MarshalJSON

func (p *PairData) MarshalJSON() ([]byte, error)

func (*PairData) ToAPIData

func (p *PairData) ToAPIData(pair *Pair) *PairAPIData

func (*PairData) ToSimplifiedAPIData

func (p *PairData) ToSimplifiedAPIData(pair *Pair) *SimplifiedPairAPIData

ToAPIData converts detailed data into public PairAPIData that contains

type PairID

type PairID struct {
	PairName   string `json:"pairName" bson:"pairName"`
	BaseToken  string `json:"baseToken" bson:"baseToken"`
	QuoteToken string `json:"quoteToken" bson:"quoteToken"`
}

PairID is the subdocument for aggregate grouping for OHLCV data

type PairRecord

type PairRecord struct {
	ID bson.ObjectId `json:"id" bson:"_id"`

	BaseTokenSymbol    string    `json:"baseTokenSymbol" bson:"baseTokenSymbol"`
	BaseAsset          string    `json:"baseAsset" bson:"baseAsset"`
	BaseTokenDecimals  int       `json:"baseTokenDecimals" bson:"baseTokenDecimals"`
	QuoteTokenSymbol   string    `json:"quoteTokenSymbol" bson:"quoteTokenSymbol"`
	QuoteAsset         string    `json:"quoteAsset" bson:"quoteAsset"`
	QuoteTokenDecimals int       `json:"quoteTokenDecimals" bson:"quoteTokenDecimals"`
	Active             bool      `json:"active" bson:"active"`
	Listed             bool      `json:"listed" bson:"listed"`
	Rank               int       `json:"rank" bson:"rank"`
	CreatedAt          time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt          time.Time `json:"updatedAt" bson:"updatedAt"`
}

type PairStats

type PairStats []*PairAPIData

type Params

type Params struct {
	From     int64  `json:"from"`
	To       int64  `json:"to"`
	Duration int64  `json:"duration"`
	Units    string `json:"units"`
	PairID   string `json:"pair"`
}

Params is a sub document used to pass parameters in Subscription messages

type PendingTradeBatch

type PendingTradeBatch struct {
	Matches *Matches
}

type RawOrderBook

type RawOrderBook struct {
	PairName string   `json:"pairName"`
	Orders   []*Order `json:"orders"`
}

type SimplifiedPairAPIData

type SimplifiedPairAPIData struct {
	PairName           string  `json:"pairName"`
	LastPrice          float64 `json:"lastPrice"`
	TradeCount         int     `json:"tradeCount"`
	OrderCount         int     `json:"orderCount"`
	Volume             float64 `json:"volume"`
	QuoteVolume        float64 `json:"quoteVolume"`
	OrderVolume        float64 `json:"orderVolume"`
	AverageOrderAmount float64 `json:"averageOrderAmount"`
	AverageTradeAmount float64 `json:"averageTradeAmount"`
}

PairAPIData is a similar structure to PairData that contains human-readable data for a certain pair

type SubscriptionEvent

type SubscriptionEvent string

SubscriptionEvent is an enum signifies whether the incoming message is of type Subscribe or unsubscribe

const (
	SUBSCRIBE   SubscriptionEvent = "SUBSCRIBE"
	UNSUBSCRIBE SubscriptionEvent = "UNSUBSCRIBE"
	Fetch       SubscriptionEvent = "fetch"
)

Enum members for SubscriptionEvent

type SubscriptionPayload

type SubscriptionPayload struct {
	PairName   string `json:"pairName,omitempty"`
	QuoteToken string `json:"quoteToken,omitempty"`
	BaseToken  string `json:"baseToken,omitempty"`
	From       int64  `json:"from"`
	To         int64  `json:"to"`
	Duration   int64  `json:"duration"`
	Units      string `json:"units"`
}

type Tick

type Tick struct {
	Pair        PairID  `json:"id,omitempty" bson:"_id"`
	Close       float64 `json:"close,omitempty" bson:"close"`
	Count       int64   `json:"count,omitempty" bson:"count"`
	High        float64 `json:"high,omitempty" bson:"high"`
	Low         float64 `json:"low,omitempty" bson:"low"`
	Open        float64 `json:"open,omitempty" bson:"open"`
	Volume      int64   `json:"volume,omitempty" bson:"volume"`
	QuoteVolume int64   `json:"quoteVolume,omitempty" bson:"quoteVolume"`
	Timestamp   int64   `json:"timestamp,omitempty" bson:"timestamp"`
}

Tick is the format in which mongo aggregate pipeline returns data when queried for OHLCV data

func (*Tick) AssetCode

func (t *Tick) AssetCode() string

func (*Tick) AveragePrice

func (t *Tick) AveragePrice() float64

func (*Tick) ConvertedVolume

func (t *Tick) ConvertedVolume(p *Pair, exchangeRate float64) float64

RoundedVolume returns the value exchanged during this tick in the currency for which the 'exchangeRate' param was provided.

func (*Tick) GetBSON

func (t *Tick) GetBSON() (interface{}, error)

func (*Tick) MarshalJSON

func (t *Tick) MarshalJSON() ([]byte, error)

MarshalJSON returns the json encoded byte array representing the trade struct

func (*Tick) SetBSON

func (t *Tick) SetBSON(raw bson.Raw) error

func (*Tick) UnmarshalJSON

func (t *Tick) UnmarshalJSON(b []byte) error

UnmarshalJSON creates a trade object from a json byte string

type Token

type Token struct {
	ID       bson.ObjectId `json:"-" bson:"_id"`
	Symbol   string        `json:"symbol" bson:"symbol"`
	Asset    string        `json:"asset" bson:"asset"`
	Decimals int           `json:"decimals" bson:"decimals"`
	Active   bool          `json:"active" bson:"active"`
	Listed   bool          `json:"listed" bson:"listed"`
	Quote    bool          `json:"quote" bson:"quote"`
	Rank     int           `json:"rank,omitempty" bson:"rank,omitempty"`

	CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}

Token struct is used to model the token data in the system and DB

func (*Token) GetBSON

func (t *Token) GetBSON() (interface{}, error)

GetBSON implements bson.Getter

func (*Token) MarshalJSON

func (t *Token) MarshalJSON() ([]byte, error)

func (*Token) SetBSON

func (t *Token) SetBSON(raw bson.Raw) error

SetBSON implemenets bson.Setter

func (*Token) UnmarshalJSON

func (t *Token) UnmarshalJSON(b []byte) error

func (Token) Validate

func (t Token) Validate() error

Validate function is used to verify if an instance of struct satisfies all the conditions for a valid instance

type TokenBalance

type TokenBalance struct {
	Asset          string `json:"asset" bson:"asset"`
	Symbol         string `json:"symbol" bson:"symbol"`
	Balance        int64  `json:"balance" bson:"balance"`
	PendingBalance int64  `json:"pendingBalance" bson:"pendingBalance"`
	LockedBalance  int64  `json:"lockedBalance" bson:"lockedBalance"`
}

TokenBalance holds the Balance and the Locked balance values for a single asset

type TokenBalanceRecord

type TokenBalanceRecord struct {
	Asset          string `json:"asset" bson:"asset"`
	Symbol         string `json:"symbol" bson:"symbol"`
	Balance        int64  `json:"balance" bson:"balance"`
	PendingBalance int64  `json:"pendingBalance" base:"pendingBalance"`
	LockedBalance  int64  `json:"lockedBalance" bson:"lockedBalance"`
}

TokenBalanceRecord corresponds to a TokenBalance struct that is stored in the DB.

type TokenRecord

type TokenRecord struct {
	ID       bson.ObjectId `json:"-" bson:"_id"`
	Symbol   string        `json:"symbol" bson:"symbol"`
	Asset    string        `json:"asset" bson:"asset"`
	Decimals int           `json:"decimals" bson:"decimals"`
	Active   bool          `json:"active" bson:"active"`
	Listed   bool          `json:"listed" bson:"listed"`
	Quote    bool          `json:"quote" bson:"quote"`
	Rank     int           `json:"rank,omitempty" bson:"rank,omitempty"`

	CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}

TokenRecord is the struct which is stored in db

type Trade

type Trade struct {
	ID                       bson.ObjectId `json:"id,omitempty" bson:"_id"`
	Taker                    string        `json:"taker" bson:"taker"`
	Maker                    string        `json:"maker" bson:"maker"`
	BaseToken                string        `json:"baseToken" bson:"baseToken"`
	QuoteToken               string        `json:"quoteToken" bson:"quoteToken"`
	MakerOrderHash           string        `json:"makerOrderHash" bson:"makerOrderHash"`
	TakerOrderHash           string        `json:"takerOrderHash" bson:"takerOrderHash"`
	Hash                     string        `json:"hash" bson:"hash"`
	TxHash                   string        `json:"txHash" bson:"txHash"`
	PairName                 string        `json:"pairName" bson:"pairName"`
	CreatedAt                time.Time     `json:"createdAt" bson:"createdAt"`
	UpdatedAt                time.Time     `json:"updatedAt" bson:"updatedAt"`
	Price                    float64       `json:"price" bson:"price"`
	Status                   string        `json:"status" bson:"status"`
	Amount                   int64         `json:"amount" bson:"amount"`
	QuoteAmount              int64         `json:"quoteAmount" bson:"quoteAmount"`
	RemainingTakerSellAmount int64         `json:"remainingTakerSellAmount" bson:"remainingTakerSellAmount"`
	RemainingMakerSellAmount int64         `json:"remainingMakerSellAmount" bson:"remainingMakerSellAmount"`
	MakerSide                string        `json:"makerSide" bson:"makerSide"`
}

Trade struct holds arguments corresponding to a "Taker Order"

func NewTrade

func NewTrade(mo *Order, to *Order, amount int64, price float64) *Trade

NewTrade returns a new unsigned trade corresponding to an Order, amount and taker address

func (*Trade) CalcQuoteAmount

func (t *Trade) CalcQuoteAmount() int64

func (*Trade) ComputeHash

func (t *Trade) ComputeHash() string

ComputeHash returns hashes the trade The OrderHash, Amount, and Taker attributes must be set before attempting to compute the trade hash

func (*Trade) GetBSON

func (t *Trade) GetBSON() (interface{}, error)

func (*Trade) MarshalJSON

func (t *Trade) MarshalJSON() ([]byte, error)

MarshalJSON returns the json encoded byte array representing the trade struct

func (*Trade) Pair

func (t *Trade) Pair() (*Pair, error)

func (*Trade) SetBSON

func (t *Trade) SetBSON(raw bson.Raw) error

func (*Trade) UnmarshalJSON

func (t *Trade) UnmarshalJSON(b []byte) error

UnmarshalJSON creates a trade object from a json byte string

func (*Trade) Validate

func (t *Trade) Validate() error

type TradeBSONUpdate

type TradeBSONUpdate struct {
	*Trade
}

func (TradeBSONUpdate) GetBSON

func (t TradeBSONUpdate) GetBSON() (interface{}, error)

type TradeRecord

type TradeRecord struct {
	ID                       bson.ObjectId `json:"id" bson:"_id"`
	Taker                    string        `json:"taker" bson:"taker"`
	Maker                    string        `json:"maker" bson:"maker"`
	BaseToken                string        `json:"baseToken" bson:"baseToken"`
	QuoteToken               string        `json:"quoteToken" bson:"quoteToken"`
	MakerOrderHash           string        `json:"makerOrderHash" bson:"makerOrderHash"`
	TakerOrderHash           string        `json:"takerOrderHash" bson:"takerOrderHash"`
	Hash                     string        `json:"hash" bson:"hash"`
	TxHash                   string        `json:"txHash" bson:"txHash"`
	PairName                 string        `json:"pairName" bson:"pairName"`
	CreatedAt                time.Time     `json:"createdAt" bson:"createdAt"`
	UpdatedAt                time.Time     `json:"updatedAt" bson:"updatedAt"`
	Price                    float64       `json:"price" bson:"price"`
	Amount                   int64         `json:"amount" bson:"amount"`
	QuoteAmount              int64         `json:"quoteAmount" bson:"quoteAmount"`
	RemainingTakerSellAmount int64         `json:"remainingTakerSellAmount" bson:"remainingTakerSellAmount"`
	RemainingMakerSellAmount int64         `json:"remainingMakerSellAmount" bson:"remainingMakerSellAmount"`
	Status                   string        `json:"status" bson:"status"`
	MakerSide                string        `json:"makerSide" bson:"makerSide"`
}

type WebsocketEvent

type WebsocketEvent struct {
	Type    string      `json:"type"`
	Hash    string      `json:"hash,omitempty"`
	Payload interface{} `json:"payload"`
}

func (*WebsocketEvent) String

func (ev *WebsocketEvent) String() string

type WebsocketMessage

type WebsocketMessage struct {
	Channel string         `json:"channel"`
	Event   WebsocketEvent `json:"event"`
}

func NewOrderAddedWebsocketMessage

func NewOrderAddedWebsocketMessage(o *Order, p *Pair, filled int64) *WebsocketMessage

func NewOrderCancelWebsocketMessage

func NewOrderCancelWebsocketMessage(oc *OrderCancel) *WebsocketMessage

func NewOrderWebsocketMessage

func NewOrderWebsocketMessage(o *Order) *WebsocketMessage

func (*WebsocketMessage) String

func (ev *WebsocketMessage) String() string

Jump to

Keyboard shortcuts

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