Documentation ¶
Index ¶
- Constants
- Variables
- func GetAccountChannelID(address string) string
- func GetMarketChannelID(marketID string) string
- func GetMarketOrderbookSnapshotV2Key(marketID string) string
- func TakerOrderShouldBeRemoved(taker *MemoryOrder) bool
- type CancelOrderEvent
- type ConfirmTransactionEvent
- type Event
- type IKVStore
- type IOrderBook
- type IQueue
- type MatchItem
- type MatchResult
- func (matchResult *MatchResult) BaseTokenTotalMatchedAmtWithoutCanceledMatch() decimal.Decimal
- func (matchResult MatchResult) ExistMatchToBeExecuted() bool
- func (matchResult *MatchResult) MakerTradeFeeInQuoteToken() (sum decimal.Decimal)
- func (matchResult *MatchResult) QuoteTokenTotalMatchedAmt() decimal.Decimal
- func (matchResult *MatchResult) SumOfGasOfMakerOrders() decimal.Decimal
- func (matchResult *MatchResult) TakerTradeFeeInQuoteToken() decimal.Decimal
- 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 ¶
func TakerOrderShouldBeRemoved ¶ added in v0.0.32
func TakerOrderShouldBeRemoved(taker *MemoryOrder) bool
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 MakerOrderIsDone bool MatchedAmount decimal.Decimal MatchShouldBeCanceled bool }
type MatchResult ¶
type MatchResult struct { TakerOrder *MemoryOrder TakerOrderIsDone bool MatchItems []*MatchItem TakerOrderLeftAmount decimal.Decimal OrderBookActivities []WebSocketMessage }
func (*MatchResult) BaseTokenTotalMatchedAmtWithoutCanceledMatch ¶ added in v0.0.32
func (matchResult *MatchResult) BaseTokenTotalMatchedAmtWithoutCanceledMatch() decimal.Decimal
func (MatchResult) ExistMatchToBeExecuted ¶ added in v0.0.32
func (matchResult MatchResult) ExistMatchToBeExecuted() bool
func (*MatchResult) MakerTradeFeeInQuoteToken ¶ added in v0.0.32
func (matchResult *MatchResult) MakerTradeFeeInQuoteToken() (sum decimal.Decimal)
func (*MatchResult) QuoteTokenTotalMatchedAmt ¶
func (matchResult *MatchResult) QuoteTokenTotalMatchedAmt() decimal.Decimal
func (*MatchResult) SumOfGasOfMakerOrders ¶ added in v0.0.32
func (matchResult *MatchResult) SumOfGasOfMakerOrders() decimal.Decimal
func (*MatchResult) TakerTradeFeeInQuoteToken ¶ added in v0.0.32
func (matchResult *MatchResult) TakerTradeFeeInQuoteToken() 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"` GasFeeAmount decimal.Decimal `json:"gasFeeAmount"` MakerFeeRate decimal.Decimal `json:"makerFeeRate"` TakerFeeRate decimal.Decimal `json:"takerFeeRate"` }
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.