types

package
v0.0.0-...-8768773 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	ID        bson.ObjectId           `json:"id" bson:"_id"`
	Address   string                  `json:"address" bson:"address"`
	Tokens    map[string]TokenBalance `json:"tokens" bson:"tokens"`
	CreatedAt time.Time               `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time               `json:"updatedAt" bson:"updatedAt"`
}

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

func NewBalance

func NewBalance(address string) (w *Balance, err error)

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

type Event

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

func (*Event) String

func (e *Event) String() string

type EventType

type EventType string

type Image

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

type Order

type Order struct {
	ID               bson.ObjectId `json:"id" bson:"_id" redis:"_id"`
	BuyToken         string        `json:"buyToken" bson:"buyToken" redis:"buyToken"`
	SellToken        string        `json:"sellToken" bson:"sellToken" redis:"sellToken"`
	BuyTokenAddress  string        `json:"buyTokenAddress" bson:"buyTokenAddress" redis:"buyTokenAddress"`
	SellTokenAddress string        `json:"sellTokenAddress" bson:"sellTokenAddress" redis:"sellTokenAddress"`
	FilledAmount     int64         `json:"filledAmount" bson:"filledAmount" redis:"filledAmount"`
	Amount           int64         `json:"amount" bson:"amount" redis:"amount"`
	Price            int64         `json:"price" bson:"price" redis:"price"`
	Fee              int64         `json:"fee" bson:"fee" redis:"fee"`
	Type             OrderType     `json:"type" bson:"type" redis:"type"`
	AmountBuy        int64         `json:"amountBuy" bson:"amountBuy" redis:"amountBuy"`
	AmountSell       int64         `json:"amountSell" bson:"amountSell" redis:"amountSell"`
	ExchangeAddress  string        `json:"exchangeAddress" bson:"exchangeAddress" redis:"exchangeAddress"`
	Status           OrderStatus   `json:"status" bson:"status" redis:"status"`
	Signature        *Signature    `json:"signature,omitempty" bson:"signature" redis:"signature"`
	PairID           bson.ObjectId `json:"pairID" bson:"pairID" redis:"pairID"`
	PairName         string        `json:"pairName" bson:"pairName" redis:"pairName"`
	Hash             string        `json:"hash" bson:"hash" redis:"hash"`
	UserAddress      string        `json:"userAddress" bson:"userAddress" redis:"userAddress"`
	OrderBook        *OrderSubDoc  `json:"orderBook" bson:"orderBook"`

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

func (*Order) GetKVPrefix

func (o *Order) GetKVPrefix() string

func (*Order) GetOBKeys

func (o *Order) GetOBKeys() (ss, list string)

func (*Order) GetOBMatchKey

func (o *Order) GetOBMatchKey() (ss string)

type OrderRequest

type OrderRequest struct {
	Type   int     `json:"type" bson:"type"`
	Amount float64 `json:"amount"`
	Price  float64 `json:"price"`
	Fee    float64 `json:"fee"`
	// Signature        string  `json:"signature"`
	PairID      string `json:"pairID"`
	PairName    string `json:"pairName"`
	UserAddress string `json:"userAddress"`
}

func (*OrderRequest) ToOrder

func (m *OrderRequest) ToOrder() (order *Order, err error)

ToOrder converts the OrderRequest to Order

func (OrderRequest) Validate

func (m OrderRequest) Validate() error

Validate validates the OrderRequest fields.

type OrderStatus

type OrderStatus int
const (
	NEW OrderStatus = iota
	OPEN
	MATCHED
	SUBMITTED
	PARTIAL_FILLED
	FILLED
	CANCELLED
	PENDING
	INVALID_ORDER
	ERROR
)

func (*OrderStatus) MarshalJSON

func (orderStatus *OrderStatus) MarshalJSON() ([]byte, error)

func (*OrderStatus) UnmarshalJSON

func (orderStatus *OrderStatus) UnmarshalJSON(data []byte) error

type OrderSubDoc

type OrderSubDoc struct {
	Amount    int64      `json:"amount" bson:"amount"`
	Signature *Signature `json:"signature,omitempty" bson:"signature" redis:"signature"`
}

type OrderType

type OrderType int
const (
	BUY OrderType
	SELL
)

func (*OrderType) MarshalJSON

func (orderType *OrderType) MarshalJSON() ([]byte, error)

func (*OrderType) UnmarshalJSON

func (orderType *OrderType) UnmarshalJSON(data []byte) error

type Pair

type Pair struct {
	ID               bson.ObjectId `json:"id" bson:"_id"`
	Name             string        `json:"name" bson:"name"`
	BuyToken         bson.ObjectId `json:"buyToken" bson:"buyToken"`
	BuyTokenSymbol   string        `json:"buyTokenSymbol" bson:"buyTokenSymbol"`
	BuyTokenAddress  string        `json:"buyTokenAddress" bson:"buyTokenAddress"`
	SellToken        bson.ObjectId `json:"sellToken" bson:"sellToken"`
	SellTokenAddress string        `json:"sellTokenAddress" bson:"sellTokenAddress"`
	SellTokenSymbol  string        `json:"sellTokenSymbol" bson:"sellTokenSymbol"`

	MakerFee float64 `json:"makerFee" bson:"makerFee"`
	TakerFee float64 `json:"takerFee" bson:"takerFee"`

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

func (*Pair) GetOrderBookKeys

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

func (Pair) Validate

func (t Pair) Validate() error

type Signature

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

asdfasdf

func NewSignature

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

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

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

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 Token

type Token struct {
	ID              bson.ObjectId `json:"id" 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"`
	Decimal         int           `json:"decimal" bson:"decimal"`
	Active          bool          `json:"active" bson:"active"`

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

func (Token) Validate

func (t Token) Validate() error

type TokenBalance

type TokenBalance struct {
	TokenID      bson.ObjectId `json:"tokenId" bson:"tokenId"`
	Amount       int64         `json:"amount" bson:"amount"`
	LockedAmount int64         `json:"lockedAmount" bson:"lockedAmount"`
}

type Trade

type Trade struct {
	ID           bson.ObjectId `json:"id,omitempty" bson:"_id"`
	OrderHash    string        `json:"orderHash" bson:"orderHash"`
	Amount       int64         `json:"amount" bson:"amount"`
	Price        int64         `json:"price" bson:"price"`
	Type         OrderType     `json:"type" bson:"type"`
	TradeNonce   int64         `json:"tradeNonce" bson:"tradeNonce"`
	Taker        string        `json:"taker" bson:"taker"`
	Maker        string        `json:"maker" bson:"maker"`
	TakerOrderID bson.ObjectId `json:"takerOrderId" bson:"takerOrderId"`
	MakerOrderID bson.ObjectId `json:"makerOrderId" bson:"makerOrderId"`
	Signature    *Signature    `json:"signature" bson:"signature"`
	Hash         string        `json:"hash" bson:"hash"`
	PairName     string        `json:"pairName" bson:"pairName"`
	CreatedAt    time.Time     `json:"createdAt" bson:"createdAt" redis:"createdAt"`
	UpdatedAt    time.Time     `json:"updatedAt" bson:"updatedAt" redis:"updatedAt"`
}

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(o *Order, amount int64, price int64, taker string) *Trade

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

type UserAddress

type UserAddress struct {
	ID        bson.ObjectId `json:"id" bson:"_id"`
	Address   string        `json:"address" bson:"address"`
	IsBlocked bool          `json:"isBlocked" bson:"isBlocked"`
	CreatedAt time.Time     `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time     `json:"updatedAt" bson:"updatedAt"`
}

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

func (UserAddress) Validate

func (ua UserAddress) Validate() error

type WsMsg

type WsMsg struct {
	MsgType string        `json:"msgType"`
	OrderID bson.ObjectId `json:"orderId"`
	Data    interface{}   `json:"data"`
}

Jump to

Keyboard shortcuts

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