operator

package
v0.0.0-...-2c32341 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operator

type Operator struct {
	// AccountService     interfaces.AccountService
	WalletService     interfaces.WalletService
	TradeService      interfaces.TradeService
	OrderService      interfaces.OrderService
	EthereumProvider  interfaces.EthereumProvider
	Exchange          interfaces.Exchange
	TxQueues          []*TxQueue
	QueueAddressIndex map[common.Address]*TxQueue
	Broker            *rabbitmq.Connection
	// contains filtered or unexported fields
}

Operator manages the transaction queue that will eventually be sent to the exchange contract. The Operator Wallet must be equal to the account that initially deployed the exchange contract or an address with operator rights on the contract

func NewOperator

func NewOperator(
	walletService interfaces.WalletService,
	tradeService interfaces.TradeService,
	orderService interfaces.OrderService,
	provider interfaces.EthereumProvider,
	exchange interfaces.Exchange,
	conn *rabbitmq.Connection,
) (*Operator, error)

NewOperator creates a new operator struct. It creates an exchange contract instance from the provided address. The error and trade events are received in the ErrorChannel and TradeChannel. Upon receiving errors and trades in their respective channels, event payloads are sent to the associated order maker and taker sockets through the through the event channel on the Order and Trade struct. In addition, an error event cancels the trade in the trading engine and makes the order available again.

func (*Operator) FeeAccount

func (op *Operator) FeeAccount() (common.Address, error)

FeeAccount is the Ethereum towards the exchange trading fees are sent

func (*Operator) GetShortestQueue

func (op *Operator) GetShortestQueue() (*TxQueue, int, error)

GetShortestQueue

func (*Operator) GetTxSendOptions

func (op *Operator) GetTxSendOptions() (*bind.TransactOpts, error)

func (*Operator) HandleError

func (op *Operator) HandleError(m *types.Matches)

func (*Operator) HandleEvents

func (op *Operator) HandleEvents() error

Bug: In certain cases, the trade channel seems to be receiving additional unexpected trades. In the case TestSocketExecuteOrder (in file socket_test.go) is run on its own, everything is working correctly. However, in the case TestSocketExecuteOrder is run among other tests, some tradeLogs do not correspond to an order hash in the ordertrade mapping. I suspect this is because the event listener catches events from previous tests. It might be helpful to see how to listen to events from up to a certain block.

func (*Operator) HandleTrades

func (op *Operator) HandleTrades(msg *types.OperatorMessage) error

func (*Operator) HandleTxError

func (op *Operator) HandleTxError(m *types.Matches, id int)

func (*Operator) HandleTxSuccess

func (op *Operator) HandleTxSuccess(m *types.Matches, receipt *eth.Receipt)

func (*Operator) Operator

func (op *Operator) Operator(addr common.Address) (bool, error)

Operator returns true if the given address is an operator of the exchange and returns false otherwise

func (*Operator) PurgeQueues

func (op *Operator) PurgeQueues() error

func (*Operator) QueueTrade

func (op *Operator) QueueTrade(m *types.Matches) error

QueueTrade

type OperatorInterface

type OperatorInterface interface {
	QueueTrade(o *types.Order, t *types.Trade) error
	GetShortestQueue() (*TxQueue, int, error)
	FeeAccount() (common.Address, error)
	Operator(addr common.Address) (bool, error)
}

type TxQueue

type TxQueue struct {
	Name             string
	Wallet           *types.Wallet
	TradeService     interfaces.TradeService
	OrderService     interfaces.OrderService
	EthereumProvider interfaces.EthereumProvider
	Exchange         interfaces.Exchange
	Broker           *rabbitmq.Connection
}

func (*TxQueue) ExecuteTrade

func (txq *TxQueue) ExecuteTrade(m *types.Matches, tag uint64) error

ExecuteTrade send a trade execution order to the smart contract interface. After sending the trade message, the trade is updated on the database and is published to the operator subscribers (order service)

func (*TxQueue) GetChannel

func (txq *TxQueue) GetChannel() *amqp.Channel

func (*TxQueue) GetTxCallOptions

func (txq *TxQueue) GetTxCallOptions() *ethereum.CallMsg

func (*TxQueue) GetTxSendOptions

func (txq *TxQueue) GetTxSendOptions() *bind.TransactOpts

func (*TxQueue) HandleError

func (txq *TxQueue) HandleError(m *types.Matches) error

func (*TxQueue) HandleTradeInvalid

func (txq *TxQueue) HandleTradeInvalid(m *types.Matches) error

func (*TxQueue) HandleTxError

func (txq *TxQueue) HandleTxError(m *types.Matches) error

func (*TxQueue) HandleTxSuccess

func (txq *TxQueue) HandleTxSuccess(m *types.Matches, receipt *eth.Receipt) error

func (*TxQueue) Length

func (txq *TxQueue) Length() int

Length

func (*TxQueue) PublishPendingTrades

func (txq *TxQueue) PublishPendingTrades(m *types.Matches) error

func (*TxQueue) PurgePendingTrades

func (txq *TxQueue) PurgePendingTrades() error

Jump to

Keyboard shortcuts

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