types

package
v0.0.0-...-73b05ea Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssetCodeETH  AssetCode = "ETH"
	AssetCodeBTC  AssetCode = "BTC"
	CreateOffer             = "CreateOffer"
	CreateAccount           = "CreateAccount"
	RemoveSigner            = "RemoveSigner"
)
View Source
const (
	PENDING = "PENDING"
	SUCCESS = "SUCCESS"
	FAILED  = "FAILED"
)
View Source
const (
	BUY         = "BUY"
	SELL        = "SELL"
	MarketOrder = "MO"
	LimitOrder  = "LO"
	StopOrder   = "SO"
)
View Source
const (
	SUBSCRIBE   SubscriptionEvent = "SUBSCRIBE"
	UNSUBSCRIBE SubscriptionEvent = "UNSUBSCRIBE"
	Fetch       SubscriptionEvent = "fetch"

	UPDATE        SubscriptionEvent = "UPDATE"
	ERROR         SubscriptionEvent = "ERROR"
	SUCCESS_EVENT SubscriptionEvent = "SUCCESS"
	INIT          SubscriptionEvent = "INIT"
	CANCEL        SubscriptionEvent = "CANCEL"

	ORDER_ADDED            = "ORDER_ADDED"
	ORDER_FILLED           = "ORDER_FILLED"
	ORDER_PARTIALLY_FILLED = "ORDER_PARTIALLY_FILLED"
	ORDER_CANCELLED        = "ORDER_CANCELLED"

	UPDATE_STATUS = "UPDATE"
	ERROR_STATUS  = "ERROR"
	FILLED        = "FILLED"
	CANCELLED     = "CANCELLED"

	TRADES_CANCELLED = "TRADES_CANCELLED"
	TRADE_ERROR      = "TRADE_ERROR"
	TRADE_TX_PENDING = "TRADE_TX_PENDING"
	TRADE_TX_SUCCESS = "TRADE_TX_SUCCESS"
	TRADE_TX_ERROR   = "TRADE_TX_ERROR"
	TRADE_INVALID    = "TRADE_INVALID"

	// channel
	TradeChannel     = "trades"
	OrderbookChannel = "orderbook"
	OrderChannel     = "orders"
	OHLCVChannel     = "ohlcv"
)

Enum members for SubscriptionEvent

Variables

This section is empty.

Functions

func DefaultTestBalance

func DefaultTestBalance() int64

DefaultTestBalance returns the default balance Only for testing/mock purpose

func DefaultTestLockedBalance

func DefaultTestLockedBalance() int64

DefaultTestBalance returns the default locked balance Only for testing/mock purpose

func DefaultTestPendingBalance

func DefaultTestPendingBalance() int64

DefaultTestBalance returns the default pending balance Only for testing/mock purpose

Types

type Account

type Account struct {
	ID            bson.ObjectId                    `json:"-" bson:"_id"`
	Address       common.Address                   `json:"address" bson:"address"`
	TokenBalances map[common.Address]*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 Ethereum 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. big.Ints are encoded as strings

type AddressAssociation

type AddressAssociation struct {
	// Chain is the name of the payment origin chain
	Chain Chain `json:"chain"`
	// BIP-44
	AddressIndex       uint64         `json:"addressIndex"`
	Address            common.Address `json:"address"`
	AssociatedAddress  common.Address `json:"associatedAddress"`
	TomochainPublicKey common.Address `json:"tomochainPublicKey"`
	CreatedAt          time.Time      `json:"createdAt"`
}

type AddressAssociationRecord

type AddressAssociationRecord struct {
	ID                bson.ObjectId `json:"id" bson:"_id"`
	AddressIndex      uint64        `json:"addressIndex" bson:"addressIndex"`
	Chain             Chain         `json:"chain" bson:"chain"`
	Address           string        `json:"address" bson:"address"`
	Status            string        `json:"status" bson:"status"`
	AssociatedAddress string        `json:"associatedAddress" bson:"associatedAddress"`
	// this is the last transaction envelopes, should move to seperated collection
	// We also have it from blockchain transactions
	TxEnvelopes       []string  `json:"txEnvelopes" bson:"txEnvelopes"`
	PairName          string    `json:"pairName" bson:"pairName"`
	BaseTokenAddress  string    `json:"baseTokenAddress" bson:"baseTokenAddress"`
	QuoteTokenAddress string    `json:"quoteTokenAddress" bson:"quoteTokenAddress"`
	CreatedAt         time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt         time.Time `json:"updatedAt" bson:"updatedAt"`
}

AddressAssociationRecord is the object that will be saved in the database

func (*AddressAssociationRecord) GetJSON

type AddressAssociationWebsocketPayload

type AddressAssociationWebsocketPayload struct {
	Chain             Chain          `json:"chain"`
	AssociatedAddress common.Address `json:"associatedAddress"`
	PairAddresses     *PairAddresses `json:"pairAddresses"`
}

type AssetCode

type AssetCode string

type AssociationTransaction

type AssociationTransaction struct {
	Source          string   `json:"source"`
	Signature       []byte   `json:"signature"`
	Hash            []byte   `json:"hash"`
	TransactionType string   `json:"transactionType"`
	Params          []string `json:"params"`
}

func (*AssociationTransaction) ComputeHash

func (o *AssociationTransaction) ComputeHash() []byte

ComputeHash calculates the orderRequest hash

func (*AssociationTransaction) GetJSON

type AssociationTransactionResponse

type AssociationTransactionResponse struct {
	Source          string   `json:"source"`
	Signature       string   `json:"signature"`
	Hash            string   `json:"hash"`
	TransactionType string   `json:"transactionType"`
	Params          []string `json:"params"`
}

type Chain

type Chain string
const (
	ChainEthereum Chain = "ethereum"
	ChainBitcoin  Chain = "bitcoin"
)

func NewChain

func NewChain(str interface{}) Chain

func (*Chain) Bytes

func (s *Chain) Bytes() []byte

func (*Chain) Scan

func (s *Chain) Scan(src interface{}) error

Scan implements database/sql.Scanner interface

func (*Chain) String

func (s *Chain) String() string

type DepositTransaction

type DepositTransaction struct {
	Chain         Chain
	TransactionID string
	AssetCode     AssetCode
	PairName      string
	// CRITICAL REQUIREMENT: Amount in the base unit of currency.
	// For 10 satoshi this should be equal 0.0000001
	// For 1 BTC      this should be equal 1.0000000
	// For 1 Finney   this should be equal 0.0010000
	// For 1 ETH      this should be equal 1.0000000
	// Currently, the length of Amount string shouldn't be longer than 17 characters.
	Amount            string
	AssociatedAddress string
}

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 GenerateAddressResponse

type GenerateAddressResponse struct {
	ProtocolVersion int    `json:"protocolVersion"`
	Chain           string `json:"chain"`
	Address         string `json:"address"`
	Signer          string `json:"signer"`
}

type Image

type Image struct {
	URL  string                 `json:"url" bson:"url"`
	Meta map[string]interface{} `json:"meta" bson:"meta"`
}

Image is a sub document used to store data related to images

type KeyValue

type KeyValue struct {
	Key   string      `json:"key" bson"key"`
	Value interface{} `json:"value" bson "value"`
}

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() common.Address

func (*Matches) TakerOrderHash

func (m *Matches) TakerOrderHash() common.Hash

func (*Matches) TradeAmounts

func (m *Matches) TradeAmounts() []*big.Int

func (*Matches) Validate

func (m *Matches) Validate() error

type NativeCurrency

type NativeCurrency struct {
	Address  common.Address `json:"address" bson:"address"`
	Symbol   string         `json:"symbol" bson:"symbol"`
	Decimals int            `json:"decimals" bson:"decimals"`
}

func GetNativeCurrency

func GetNativeCurrency() NativeCurrency

type NewOrderPayload

type NewOrderPayload struct {
	PairName        string         `json:"pairName"`
	ExchangeAddress common.Address `json:"exchangeAddress"`
	UserAddress     common.Address `json:"userAddress"`
	BaseToken       common.Address `json:"baseToken"`
	QuoteToken      common.Address `json:"quoteToken"`
	Side            string         `json:"side"`
	Amount          *big.Int       `json:"amount"`
	PricePoint      *big.Int       `json:"pricepoint"`
	TakeFee         *big.Int       `json:"takeFee"`
	MakeFee         *big.Int       `json:"makeFee"`
	Nonce           *big.Int       `json:"nonce" bson:"nonce"`
	Signature       *Signature     `json:"signature"`
	Hash            common.Hash    `json:"hash"`
}

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

func (*NewOrderPayload) ComputeHash

func (p *NewOrderPayload) ComputeHash() common.Hash

ComputeHash calculates the orderRequest hash

func (*NewOrderPayload) EncodedSide

func (p *NewOrderPayload) EncodedSide() *big.Int

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.

func (*NewOrderPayload) VerifySignature

func (p *NewOrderPayload) VerifySignature() (bool, error)

VerifySignature checks that the orderRequest signature corresponds to the address in the userAddress field

type OHLCVParams

type OHLCVParams struct {
	Pair     []PairAddresses `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     common.Address `json:"userAddress" bson:"userAddress"`
	ExchangeAddress common.Address `json:"exchangeAddress" bson:"exchangeAddress"`
	BaseToken       common.Address `json:"baseToken" bson:"baseToken"`
	QuoteToken      common.Address `json:"quoteToken" bson:"quoteToken"`
	Status          string         `json:"status" bson:"status"`
	Side            string         `json:"side" bson:"side"`
	Type            string         `json:"type" bson:"type"`
	Hash            common.Hash    `json:"hash" bson:"hash"`
	Signature       *Signature     `json:"signature,omitempty" bson:"signature"`
	PricePoint      *big.Int       `json:"pricepoint" bson:"pricepoint"`
	Amount          *big.Int       `json:"amount" bson:"amount"`
	FilledAmount    *big.Int       `json:"filledAmount" bson:"filledAmount"`
	Nonce           *big.Int       `json:"nonce" bson:"nonce"`
	MakeFee         *big.Int       `json:"makeFee" bson:"makeFee"`
	TakeFee         *big.Int       `json:"takeFee" bson:"takeFee"`
	PairName        string         `json:"pairName" bson:"pairName"`
	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 *big.Int) *big.Int

func (*Order) BuyToken

func (o *Order) BuyToken() common.Address

func (*Order) BuyTokenSymbol

func (o *Order) BuyTokenSymbol() string

func (*Order) ComputeHash

func (o *Order) ComputeHash() common.Hash

ComputeHash calculates the orderRequest hash

func (*Order) EncodedSide

func (o *Order) EncodedSide() *big.Int

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) 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) *big.Int

func (*Order) QuoteTokenSymbol

func (o *Order) QuoteTokenSymbol() string

func (*Order) RemainingAmount

func (o *Order) RemainingAmount() *big.Int

func (*Order) RemainingSellAmount

func (o *Order) RemainingSellAmount(p *Pair) *big.Int

func (*Order) RequiredSellAmount

func (o *Order) RequiredSellAmount(p *Pair) *big.Int

func (*Order) SellAmount

func (o *Order) SellAmount(p *Pair) *big.Int

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

func (*Order) SellToken

func (o *Order) SellToken() common.Address

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) Sign

func (o *Order) Sign(w *Wallet) error

Sign first calculates the order hash, then computes a signature of this hash with the given wallet

func (*Order) String

func (o *Order) String() string

func (*Order) TotalRequiredSellAmount

func (o *Order) TotalRequiredSellAmount(p *Pair) *big.Int

func (*Order) UnmarshalJSON

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

UnmarshalJSON : write custom logic to unmarshal bytes to Order

func (*Order) Validate

func (o *Order) Validate() error

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

func (*Order) VerifySignature

func (o *Order) VerifySignature() (bool, error)

VerifySignature checks that the orderRequest signature corresponds to the address in the userAddress field

type OrderBSONUpdate

type OrderBSONUpdate struct {
	*Order
}

func (OrderBSONUpdate) GetBSON

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

type OrderBook

type OrderBook struct {
	PairName string              `json:"pairName"`
	Asks     []map[string]string `json:"asks"`
	Bids     []map[string]string `json:"bids"`
}

type OrderCancel

type OrderCancel struct {
	OrderHash common.Hash `json:"orderHash"`
	Hash      common.Hash `json:"hash"`
	Signature *Signature  `json:"signature"`
}

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) ComputeHash

func (oc *OrderCancel) ComputeHash() common.Hash

ComputeHash computes the hash of an order cancel message

func (*OrderCancel) GetSenderAddress

func (oc *OrderCancel) GetSenderAddress() (common.Address, error)

func (*OrderCancel) MarshalJSON

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

MarshalJSON returns the json encoded byte array representing the OrderCancel struct

func (*OrderCancel) Sign

func (oc *OrderCancel) Sign(w *Wallet) error

Sign first computes the order cancel hash, then signs and sets the signature

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

func (*OrderCancel) VerifySignature

func (oc *OrderCancel) VerifySignature(o *Order) (bool, error)

VerifySignature returns a true value if the OrderCancel object signature corresponds to the Maker of the given order

type OrderData

type OrderData struct {
	Pair        PairID   `json:"id,omitempty" bson:"_id"`
	OrderVolume *big.Int `json:"orderVolume,omitempty" bson:"orderVolume"`
	OrderCount  *big.Int `json:"orderCount,omitempty" bson:"orderCount"`
	BestPrice   *big.Int `json:"bestPrice,omitempty" bson:"bestPrice"`
}

func (*OrderData) AddressCode

func (o *OrderData) AddressCode() 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"`
	ExchangeAddress string           `json:"exchangeAddress" bson:"exchangeAddress"`
	BaseToken       string           `json:"baseToken" bson:"baseToken"`
	QuoteToken      string           `json:"quoteToken" bson:"quoteToken"`
	Status          string           `json:"status" bson:"status"`
	Side            string           `json:"side" bson:"side"`
	Type            string           `json:"type" bson:"type"`
	Hash            string           `json:"hash" bson:"hash"`
	PricePoint      string           `json:"pricepoint" bson:"pricepoint"`
	Amount          string           `json:"amount" bson:"amount"`
	FilledAmount    string           `json:"filledAmount" bson:"filledAmount"`
	Nonce           string           `json:"nonce" bson:"nonce"`
	MakeFee         string           `json:"makeFee" bson:"makeFee"`
	TakeFee         string           `json:"takeFee" bson:"takeFee"`
	Signature       *SignatureRecord `json:"signature,omitempty" bson:"signature"`

	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"`
	BaseTokenAddress   common.Address `json:"baseTokenAddress,omitempty" bson:"baseTokenAddress"`
	BaseTokenDecimals  int            `json:"baseTokenDecimals,omitempty" bson:"baseTokenDecimals"`
	QuoteTokenSymbol   string         `json:"quoteTokenSymbol,omitempty" bson:"quoteTokenSymbol"`
	QuoteTokenAddress  common.Address `json:"quoteTokenAddress,omitempty" bson:"quoteTokenAddress"`
	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"`
	MakeFee            *big.Int       `json:"makeFee,omitempty" bson:"makeFee"`
	TakeFee            *big.Int       `json:"takeFee,omitempty" bson:"takeFee"`
	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) AddressCode

func (p *Pair) AddressCode() string

func (*Pair) BaseTokenMultiplier

func (p *Pair) BaseTokenMultiplier() *big.Int

func (*Pair) Code

func (p *Pair) Code() string

func (*Pair) DecimalsMultiplier

func (p *Pair) DecimalsMultiplier() *big.Int

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 returns the orderbook price point keys for corresponding pair It is used to fetch the orderbook of a pair

func (*Pair) MarshalJSON

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

func (*Pair) MinQuoteAmount

func (p *Pair) MinQuoteAmount() *big.Int

func (*Pair) Name

func (p *Pair) Name() string

func (*Pair) PairMultiplier

func (p *Pair) PairMultiplier() *big.Int

func (*Pair) ParseAmount

func (p *Pair) ParseAmount(a *big.Int) float64

func (*Pair) ParsePricePoint

func (p *Pair) ParsePricePoint(pp *big.Int) float64

func (*Pair) PricepointMultiplier

func (p *Pair) PricepointMultiplier() *big.Int

func (*Pair) QuoteTokenMultiplier

func (p *Pair) QuoteTokenMultiplier() *big.Int

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) ValidateAddresses

func (p Pair) ValidateAddresses() 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"`
	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 PairAddresses

type PairAddresses struct {
	Name       string         `json:"name" bson:"name"`
	BaseToken  common.Address `json:"baseToken" bson:"baseToken"`
	QuoteToken common.Address `json:"quoteToken" bson:"quoteToken"`
}

type PairAddressesRecord

type PairAddressesRecord 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              *big.Int `json:"close,omitempty" bson:"close"`
	Count              *big.Int `json:"count,omitempty" bson:"count"`
	High               *big.Int `json:"high,omitempty" bson:"high"`
	Low                *big.Int `json:"low,omitempty" bson:"low"`
	Open               *big.Int `json:"open,omitempty" bson:"open"`
	Volume             *big.Int `json:"volume,omitempty" bson:"volume"`
	Timestamp          int64    `json:"timestamp,omitempty" bson:"timestamp"`
	OrderVolume        *big.Int `json:"orderVolume,omitempty" bson:"orderVolume"`
	OrderCount         *big.Int `json:"orderCount,omitempty" bson:"orderCount"`
	AverageOrderAmount *big.Int `json:"averageOrderAmount" bson:"averageOrderAmount"`
	AverageTradeAmount *big.Int `json:"averageTradeAmount" bson:"averageTradeAmount"`
	AskPrice           *big.Int `json:"askPrice,omitempty" bson:"askPrice"`
	BidPrice           *big.Int `json:"bidPrice,omitempty" bson:"bidPrice"`
	Price              *big.Int `json:"price,omitempty" bson:"price"`
	Rank               int      `json"rank,omitempty" bson:"rank"`
}

func (*PairData) AddressCode

func (p *PairData) AddressCode() 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  common.Address `json:"baseToken" bson:"baseToken"`
	QuoteToken common.Address `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"`
	BaseTokenAddress   string    `json:"baseTokenAddress" bson:"baseTokenAddress"`
	BaseTokenDecimals  int       `json:"baseTokenDecimals" bson:"baseTokenDecimals"`
	QuoteTokenSymbol   string    `json:"quoteTokenSymbol" bson:"quoteTokenSymbol"`
	QuoteTokenAddress  string    `json:"quoteTokenAddress" bson:"quoteTokenAddress"`
	QuoteTokenDecimals int       `json:"quoteTokenDecimals" bson:"quoteTokenDecimals"`
	Active             bool      `json:"active" bson:"active"`
	Listed             bool      `json:"listed" bson:"listed"`
	MakeFee            string    `json:"makeFee" bson:"makeFee"`
	TakeFee            string    `json:"takeFee" bson:"takeFee"`
	Rank               int       `json:"rank" bson:"rank"`
	CreatedAt          time.Time `json:"createdAt" bson:"createdAt"`
	UpdatedAt          time.Time `json:"updatedAt" bson:"updatedAt"`
}

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 PriceBoardData

type PriceBoardData struct {
	Ticks          []*Tick `json:"ticks" bson:"ticks"`
	PriceUSD       string  `json:"usd" bson:"usd"`
	LastTradePrice string  `json:"last_trade_price" bson:"last_trade_price"`
}

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

type RawOrderBook

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

type Signature

type Signature struct {
	V byte
	R common.Hash
	S common.Hash
}

Signature struct

func NewSignature

func NewSignature(b []byte) (*Signature, error)

NewSignature function decodes []byte to Signature type

func Sign

func Sign(hash common.Hash, privKey *ecdsa.PrivateKey) (*Signature, error)

Sign calculates the EDCSA signature corresponding of a hashed message from a given private key

func SignHash

func SignHash(hash common.Hash, privKey *ecdsa.PrivateKey) (*Signature, error)

SignHash also calculates the EDCSA signature of a message but adds an "Ethereum Signed Message" prefix https://github.com/ethereum/EIPs/issues/191

func (*Signature) GetRecord

func (s *Signature) GetRecord() *SignatureRecord

func (*Signature) MarshalSignature

func (s *Signature) MarshalSignature() ([]byte, error)

MarshalSignature marshals the signature struct to []byte

func (*Signature) Verify

func (s *Signature) Verify(hash common.Hash) (common.Address, error)

Verify returns the address that corresponds to the given signature and signed message

type SignatureRecord

type SignatureRecord struct {
	V byte   `json:"V" bson:"V"`
	R string `json:"R" bson:"R"`
	S string `json:"S" bson:"S"`
}

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"`
	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

type SubscriptionPayload

type SubscriptionPayload struct {
	PairName   string         `json:"pairName,omitempty"`
	QuoteToken common.Address `json:"quoteToken,omitempty"`
	BaseToken  common.Address `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     *big.Int `json:"close,omitempty" bson:"close"`
	Count     *big.Int `json:"count,omitempty" bson:"count"`
	High      *big.Int `json:"high,omitempty" bson:"high"`
	Low       *big.Int `json:"low,omitempty" bson:"low"`
	Open      *big.Int `json:"open,omitempty" bson:"open"`
	Volume    *big.Int `json:"volume,omitempty" bson:"volume"`
	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) AddressCode

func (t *Tick) AddressCode() string

func (*Tick) AveragePrice

func (t *Tick) AveragePrice() *big.Int

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"`
	Name            string         `json:"name" bson:"name"`
	Symbol          string         `json:"symbol" bson:"symbol"`
	Address         common.Address `json:"address" bson:"address"`
	Image           Image          `json:"image" bson:"image"`
	ContractAddress common.Address `json:"contractAddress" bson:"contractAddress"`
	Decimals        int            `json:"decimals" bson:"decimals"`
	Active          bool           `json:"active" bson:"active"`
	Listed          bool           `json:"listed" bson:"listed"`
	Quote           bool           `json:"quote" bson:"quote"`
	MakeFee         *big.Int       `json:"makeFee,omitempty" bson:"makeFee,omitempty"`
	TakeFee         *big.Int       `json:"takeFee,omitempty" bson:"makeFee,omitempty"`
	USD             string         `json:"usd,omitempty" bson:"usd,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 {
	Address        common.Address `json:"address" bson:"address"`
	Symbol         string         `json:"symbol" bson:"symbol"`
	Balance        *big.Int       `json:"balance" bson:"balance"`
	PendingBalance *big.Int       `json:"pendingBalance" bson:"pendingBalance"`
	LockedBalance  *big.Int       `json:"lockedBalance" bson:"lockedBalance"`
}

TokenBalance holds the Balance and the Locked balance values for a single Ethereum token Balance and Locked Balance are stored as big.Int as they represent uint256 values

type TokenBalanceRecord

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

TokenBalanceRecord corresponds to a TokenBalance struct that is stored in the DB. big.Ints are encoded as strings

type TokenRecord

type TokenRecord struct {
	ID              bson.ObjectId `json:"-" bson:"_id"`
	Name            string        `json:"name" bson:"name"`
	Symbol          string        `json:"symbol" bson:"symbol"`
	Image           Image         `json:"image" bson:"image"`
	ContractAddress string        `json:"contractAddress" bson:"contractAddress"`
	Decimals        int           `json:"decimals" bson:"decimals"`
	Active          bool          `json:"active" bson:"active"`
	Quote           bool          `json:"quote" bson:"quote"`
	MakeFee         string        `json:"makeFee,omitempty" bson:"makeFee,omitempty"`
	TakeFee         string        `json:"takeFee,omitempty" bson:"takeFee,omitempty"`
	USD             string        `json:"usd,omitempty" bson:"usd,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          common.Address `json:"taker" bson:"taker"`
	Maker          common.Address `json:"maker" bson:"maker"`
	BaseToken      common.Address `json:"baseToken" bson:"baseToken"`
	QuoteToken     common.Address `json:"quoteToken" bson:"quoteToken"`
	MakerOrderHash common.Hash    `json:"makerOrderHash" bson:"makerOrderHash"`
	TakerOrderHash common.Hash    `json:"takerOrderHash" bson:"takerOrderHash"`
	Hash           common.Hash    `json:"hash" bson:"hash"`
	TxHash         common.Hash    `json:"txHash" bson:"txHash"`
	PairName       string         `json:"pairName" bson:"pairName"`
	CreatedAt      time.Time      `json:"createdAt" bson:"createdAt"`
	UpdatedAt      time.Time      `json:"updatedAt" bson:"updatedAt"`
	PricePoint     *big.Int       `json:"pricepoint" bson:"pricepoint"`
	Status         string         `json:"status" bson:"status"`
	Amount         *big.Int       `json:"amount" bson:"amount"`
}

Trade struct holds arguments corresponding to a "Taker Order" To be valid an accept by the matching engine (and ultimately the exchange smart-contract), the trade signature must be made from the trader Maker account

func NewTrade

func NewTrade(mo *Order, to *Order, amount *big.Int, pricepoint *big.Int) *Trade

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

func (*Trade) ComputeHash

func (t *Trade) ComputeHash() common.Hash

ComputeHash returns hashes the trade The OrderHash, Amount, Taker and TradeNonce 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) QuoteAmount

func (t *Trade) QuoteAmount(p *Pair) *big.Int

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"`
	PricePoint     string        `json:"pricepoint" bson:"pricepoint"`
	Amount         string        `json:"amount" bson:"amount"`
	Status         string        `json:"status" bson:"status"`
}

type Wallet

type Wallet struct {
	ID         bson.ObjectId
	Address    common.Address
	PrivateKey *ecdsa.PrivateKey
	Admin      bool
	Operator   bool
}

Wallet holds both the address and the private key of an ethereum account

func NewWallet

func NewWallet() *Wallet

NewWallet returns a new wallet object corresponding to a random private key

func NewWalletFromPrivateKey

func NewWalletFromPrivateKey(key string) *Wallet

NewWalletFromPrivateKey returns a new wallet object corresponding to a given private key

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() string

GetAddress returns the wallet address

func (*Wallet) GetBSON

func (w *Wallet) GetBSON() (interface{}, error)

func (*Wallet) GetPrivateKey

func (w *Wallet) GetPrivateKey() string

GetPrivateKey returns the wallet private key

func (*Wallet) SetBSON

func (w *Wallet) SetBSON(raw bson.Raw) error

func (*Wallet) SignHash

func (w *Wallet) SignHash(h common.Hash) (*Signature, error)

SignHash signs a hashed message with a wallet private key and returns it as a Signature object

func (*Wallet) SignOrder

func (w *Wallet) SignOrder(o *Order) error

func (*Wallet) Validate

func (w *Wallet) Validate() error

type WalletRecord

type WalletRecord struct {
	ID         bson.ObjectId `json:"id,omitempty" bson:"_id"`
	Address    string        `json:"address" bson:"address"`
	PrivateKey string        `json:"privateKey" bson:"privateKey"`
	Admin      bool          `json:"admin" bson:"admin"`
	Operator   bool          `json:"operator" bson:"operator"`
}

type WebsocketEvent

type WebsocketEvent struct {
	Type    SubscriptionEvent `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