common

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: Apache-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

View Source
const (
	EventNewOrder           = "EVENT/NEW_ORDER"
	EventCancelOrder        = "EVENT/EVENT_CANCEL_ORDER"
	EventRestartEngine      = "EVENT/EVENT_RESTART"
	EventConfirmTransaction = "EVENT/EVENT_CONFIRM_TRANSACTION"
)
View Source
const AccountChannelPrefix = "TraderAddress"
View Source
const HYDRO_ENGINE_EVENTS_QUEUE_KEY = "HYDRO_ENGINE_EVENTS_QUEUE_KEY"
View Source
const HYDRO_WATCHER_BLOCK_NUMBER_CACHE_KEY = "HYDRO_WATCHER_BLOCK_NUMBER_CACHE_KEY"

cache key

View Source
const HYDRO_WEBSOCKET_MESSAGES_QUEUE_KEY = "HYDRO_WEBSOCKET_MESSAGES_QUEUE_KEY"

queue key

View Source
const MarketChannelPrefix = "Market"
View Source
const ORDER_CANCELED = "canceled"

order status

View Source
const ORDER_FULL_FILLED = "full_filled"
View Source
const ORDER_PARTIAL_FILLED = "partial_filled"
View Source
const ORDER_PENDING = "pending"
View Source
const STATUS_FAILED = "failed"
View Source
const STATUS_PENDING = "pending"
View Source
const STATUS_SUCCESSFUL = "successful"
View Source
const WsTypeLockedBalanceChange = "lockedBalanceChange"
View Source
const WsTypeNewMarketTrade = "newMarketTrade"
View Source
const WsTypeOrderChange = "orderChange"
View Source
const WsTypeTradeChange = "tradeChange"

Variables

View Source
var EXIT = errors.New("EXIT")
View Source
var KVStoreEmpty = errors.New("KVStoreEmpty")

Functions

func GetAccountChannelID

func GetAccountChannelID(address string) string

func GetMarketChannelID

func GetMarketChannelID(marketID string) string

func GetMarketOrderbookSnapshotV2Key

func GetMarketOrderbookSnapshotV2Key(marketID string) string

Types

type CancelOrderEvent

type CancelOrderEvent struct {
	Event
	ID    string `json:"id"`
	Price string `json:"price"`
	Side  string `json:"side"`
}

type ConfirmTransactionEvent

type ConfirmTransactionEvent struct {
	Event
	Hash      string `json:"hash"`
	Status    string `json:"status"`
	Timestamp uint64 `json:"timestamp"`
}

type Event

type Event struct {
	Type     string `json:"eventType"`
	MarketID string `json:"marketID"`
}

type IKVStore

type IKVStore interface {
	Set(key string, value string, expire time.Duration) error
	Get(key string) (string, error)
}

func InitKVStore

func InitKVStore(config interface{}) (store IKVStore, err error)

type IOrderBook

type IOrderBook interface {
	InsertOrder(*MemoryOrder)
	RemoveOrder(*MemoryOrder)
	ChangeOrder(*MemoryOrder, decimal.Decimal)

	UsePlugin(plugin OrderbookPlugin)

	SnapshotV2() *SnapshotV2
	CanMatch(*MemoryOrder) bool
	MatchOrder(*MemoryOrder, int) *MatchResult
	ExecuteMatch(*MemoryOrder, int) *MatchResult
}

type IQueue

type IQueue interface {
	Push([]byte) error

	// Pop should not block the current thread all the time.
	Pop() ([]byte, error)
}

Iqueue is an interface of common queue service You can use your favourite backend to handle messages.

func InitQueue

func InitQueue(config interface{}) (queue IQueue, err error)

type MatchItem

type MatchItem struct {
	MakerOrder    *MemoryOrder
	MatchedAmount decimal.Decimal
}

type MatchResult

type MatchResult struct {
	TakerOrder           *MemoryOrder
	MatchItems           []*MatchItem
	IsFullMatch          bool
	TakerOrderLeftAmount decimal.Decimal
	OrderBookActivities  []WebSocketMessage
}

func (*MatchResult) BaseTokenTotalMatchedAmt

func (matchRst *MatchResult) BaseTokenTotalMatchedAmt() decimal.Decimal

func (*MatchResult) QuoteTokenTotalMatchedAmt

func (matchRst *MatchResult) QuoteTokenTotalMatchedAmt() decimal.Decimal

type MemoryOrder

type MemoryOrder struct {
	ID       string          `json:"id"`
	MarketID string          `json:"marketID"`
	Price    decimal.Decimal `json:"price"`
	Amount   decimal.Decimal `json:"amount"`
	Side     string          `json:"side"`
	Type     string          `json:"type"`
	Trader   string          `json:"trader"`
}

func (*MemoryOrder) BaseTokenSymbol

func (order *MemoryOrder) BaseTokenSymbol() string

func (*MemoryOrder) QuoteTokenSymbol

func (order *MemoryOrder) QuoteTokenSymbol() string

type MockKVStore

type MockKVStore struct {
	mock.Mock
}

func (*MockKVStore) Get

func (m *MockKVStore) Get(key string) (string, error)

func (*MockKVStore) Set

func (m *MockKVStore) Set(key string, value string, expire time.Duration) error

type MockQueue

type MockQueue struct {
	mock.Mock
	Buffers [][]byte
}

func (*MockQueue) Pop

func (m *MockQueue) Pop() ([]byte, error)

func (*MockQueue) Push

func (m *MockQueue) Push(bts []byte) error

func (*MockQueue) ResetBuffer

func (m *MockQueue) ResetBuffer()

type NewOrderEvent

type NewOrderEvent struct {
	Event
	Order string `json:"order"`
}

type Orderbook

type Orderbook struct {
	Sequence uint64
	// contains filtered or unexported fields
}

Orderbook ...

func NewOrderbook

func NewOrderbook(market string) *Orderbook

NewOrderbook return a new book

func (*Orderbook) CanMatch

func (book *Orderbook) CanMatch(order *MemoryOrder) bool

func (*Orderbook) ChangeOrder

func (book *Orderbook) ChangeOrder(order *MemoryOrder, changeAmount decimal.Decimal) *OrderbookEvent

func (*Orderbook) ExecuteMatch

func (book *Orderbook) ExecuteMatch(takerOrder *MemoryOrder, marketAmountDecimals int) *MatchResult

func (*Orderbook) GetOrder

func (book *Orderbook) GetOrder(id string, side string, price decimal.Decimal) (*MemoryOrder, bool)

func (*Orderbook) InsertOrder

func (book *Orderbook) InsertOrder(order *MemoryOrder) *OrderbookEvent

func (*Orderbook) MatchOrder

func (book *Orderbook) MatchOrder(takerOrder *MemoryOrder, marketAmountDecimals int) *MatchResult

return matching orders in book will NOT modify the order book

amt is quoteCurrency when order is MarketID Buy Order all other amount is baseCurrencyAmt

func (*Orderbook) MaxBid

func (book *Orderbook) MaxBid() *decimal.Decimal

MaxBid ...

func (*Orderbook) MinAsk

func (book *Orderbook) MinAsk() *decimal.Decimal

MinAsk ...

func (*Orderbook) RemoveOrder

func (book *Orderbook) RemoveOrder(order *MemoryOrder) *OrderbookEvent

func (*Orderbook) RunPlugins

func (book *Orderbook) RunPlugins(event *OrderbookEvent)

func (*Orderbook) SnapshotV2

func (book *Orderbook) SnapshotV2() *SnapshotV2

func (*Orderbook) UsePlugin

func (book *Orderbook) UsePlugin(plugin OrderbookPlugin)

type OrderbookEvent

type OrderbookEvent struct {
	Side    string
	OrderID string
	Price   decimal.Decimal
	Amount  decimal.Decimal
}

type OrderbookPlugin

type OrderbookPlugin func(event *OrderbookEvent)

type RedisKVStore

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

func (RedisKVStore) Get

func (queue RedisKVStore) Get(key string) (string, error)

func (*RedisKVStore) Init

func (queue *RedisKVStore) Init(config *RedisKVStoreConfig) error

func (RedisKVStore) Set

func (queue RedisKVStore) Set(key, value string, expire time.Duration) error

type RedisKVStoreConfig

type RedisKVStoreConfig struct {
	Ctx    context.Context
	Client *redis.Client
}

type RedisQueue

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

func (*RedisQueue) Init

func (queue *RedisQueue) Init(config *RedisQueueConfig) error

func (*RedisQueue) Pop

func (queue *RedisQueue) Pop() ([]byte, error)

func (*RedisQueue) Push

func (queue *RedisQueue) Push(data []byte) error

type RedisQueueConfig

type RedisQueueConfig struct {
	Name   string
	Ctx    context.Context
	Client *redis.Client
}

type SnapshotV2

type SnapshotV2 struct {
	Sequence uint64      `json:"sequence"`
	Bids     [][2]string `json:"bids"`
	Asks     [][2]string `json:"asks"`
}

type WebSocketMessage

type WebSocketMessage struct {
	//MessageType string      `json:"message_type"`
	ChannelID string      `json:"channel_id"`
	Payload   interface{} `json:"payload"`
}

func MessagesForUpdateOrder added in v0.0.3

func MessagesForUpdateOrder(order *MemoryOrder) []WebSocketMessage

func OrderBookChangeMessage added in v0.0.3

func OrderBookChangeMessage(marketID string, sequence uint64, side string, price, amount decimal.Decimal) WebSocketMessage

type WebsocketLockedBalanceChangePayload

type WebsocketLockedBalanceChangePayload struct {
	Type    string          `json:"type"`
	Symbol  string          `json:"symbol"`
	Balance decimal.Decimal `json:"balance"`
}

type WebsocketMarketNewMarketTradePayload

type WebsocketMarketNewMarketTradePayload struct {
	Type  string      `json:"type"`
	Trade interface{} `json:"trade"`
}

type WebsocketMarketOrderChangePayload

type WebsocketMarketOrderChangePayload struct {
	Side     string `json:"side"`
	Sequence uint64 `json:"sequence"`
	Price    string `json:"price"`
	Amount   string `json:"amount"`
}

type WebsocketOrderChangePayload

type WebsocketOrderChangePayload struct {
	Type  string      `json:"type"`
	Order interface{} `json:"order"`
}

type WebsocketTradeChangePayload

type WebsocketTradeChangePayload struct {
	Type  string      `json:"type"`
	Trade interface{} `json:"trade"`
}

Jump to

Keyboard shortcuts

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