Documentation ¶
Index ¶
- Constants
- Variables
- func GetAccountChannelID(address string) string
- func GetMarketChannelID(marketID string) string
- func GetMarketOrderbookSnapshotV2Key(marketID string) string
- type CancelOrderEvent
- type ConfirmTransactionEvent
- type Event
- type IKVStore
- type IOrderBook
- type IQueue
- type MatchItem
- type MatchResult
- type MemoryOrder
- type MockKVStore
- type MockQueue
- type NewOrderEvent
- type Orderbook
- func (book *Orderbook) CanMatch(order *MemoryOrder) bool
- func (book *Orderbook) ChangeOrder(order *MemoryOrder, changeAmount decimal.Decimal) *OrderbookEvent
- func (book *Orderbook) ExecuteMatch(takerOrder *MemoryOrder, marketAmountDecimals int) *MatchResult
- func (book *Orderbook) GetOrder(id string, side string, price decimal.Decimal) (*MemoryOrder, bool)
- func (book *Orderbook) InsertOrder(order *MemoryOrder) *OrderbookEvent
- func (book *Orderbook) MatchOrder(takerOrder *MemoryOrder, marketAmountDecimals int) *MatchResult
- func (book *Orderbook) MaxBid() *decimal.Decimal
- func (book *Orderbook) MinAsk() *decimal.Decimal
- func (book *Orderbook) RemoveOrder(order *MemoryOrder) *OrderbookEvent
- func (book *Orderbook) RunPlugins(event *OrderbookEvent)
- func (book *Orderbook) SnapshotV2() *SnapshotV2
- func (book *Orderbook) UsePlugin(plugin OrderbookPlugin)
- type OrderbookEvent
- type OrderbookPlugin
- type RedisKVStore
- type RedisKVStoreConfig
- type RedisQueue
- type RedisQueueConfig
- type SnapshotV2
- type WebSocketMessage
- type WebsocketLockedBalanceChangePayload
- type WebsocketMarketNewMarketTradePayload
- type WebsocketMarketOrderChangePayload
- type WebsocketOrderChangePayload
- type WebsocketTradeChangePayload
Constants ¶
View Source
const ( EventNewOrder = "EVENT/NEW_ORDER" EventCancelOrder = "EVENT/EVENT_CANCEL_ORDER" EventRestartEngine = "EVENT/EVENT_RESTART" EventConfirmTransaction = "EVENT/EVENT_CONFIRM_TRANSACTION" EventOpenMarket = "EVENT/EVENT_OPEN_MARKET" EventCloseMarket = "EVENT/EVENT_CLOSE_MARKET" )
engine event
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 GetMarketChannelID ¶
Types ¶
type CancelOrderEvent ¶
type ConfirmTransactionEvent ¶
type IKVStore ¶
type IKVStore interface { Set(key string, value string, expire time.Duration) error Get(key string) (string, error) }
func InitKVStore ¶
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.
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 MockQueue ¶
func (*MockQueue) ResetBuffer ¶
func (m *MockQueue) ResetBuffer()
type NewOrderEvent ¶
type Orderbook ¶
type Orderbook struct { Sequence uint64 // contains filtered or unexported fields }
Orderbook ...
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) 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) 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 OrderbookPlugin ¶
type OrderbookPlugin func(event *OrderbookEvent)
type RedisKVStore ¶
type RedisKVStore struct {
// contains filtered or unexported fields
}
func (*RedisKVStore) Init ¶
func (queue *RedisKVStore) Init(config *RedisKVStoreConfig) error
type RedisKVStoreConfig ¶
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 SnapshotV2 ¶
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
type WebsocketMarketNewMarketTradePayload ¶
type WebsocketMarketNewMarketTradePayload struct { Type string `json:"type"` Trade interface{} `json:"trade"` }
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"` }
Click to show internal directories.
Click to hide internal directories.