func (e *TradingEngine) RegisterNewPair(p TokenPair, done chan<- bool) error {
	if _, ok := e.quoteTokens[p.QuoteToken.Address]; !ok {
		return errors.New("Quote token is not registered")
	}

	id := p.ComputeID()
	if _, ok := e.pairs[id]; ok {
		return errors.New("Token Pair is already registered")
	}

	p.ID = id
	actions := make(chan *Action)
	logger := make([]*Action, 0)

	ob := new(OrderBook)
	ob.bid = 0
	ob.ask = MAX_PRICE
	ob.actions = actions
	ob.logger = logger
	ob.orderIndex = make(map[Hash]*Order)

	go func() {
		for {
			action := <-actions
			ob.logger = append(ob.logger, action)
			if action.actionType == AT_DONE {
				done <- true
				return
			}
		}
	}()

	for i := range ob.prices {
		ob.prices[i] = new(PricePoint)
	}

	e.pairs[id] = p
	e.orderbooks[p] = ob

	// fmt.Printf("\nRegistered new pair %v\n\n", p.String())
	return nil
}
// RegisterNewPair registers a new token pair on the engine
// To be valid, the quote token of the new token pair needs to be registered in the quote tokens of the engine
RegisterNewPair registers a new token pair on the engine
To be valid, the quote token of the new token pair needs to be registered in the quote tokens of the engine
// RegisterNewPair registers a new token pair on the engine // To be valid the quote token of the new token pair needs to be registered in the quote tokens of the engine
func (e *TradingEngine) RegisterNewPair(p TokenPair, done chan<- bool) error {
	if _, ok := e.quoteTokens[p.QuoteToken.Address]; !ok {
		return errors.New("Quote token is not registered")
	}
	id := p.ComputeID()
	if _, ok := e.pairs[id]; ok {
		return errors.New("Token Pair is already registered")
	}
	p.ID = id
	actions := make(chan *Action)
	logger := make([]*Action, 0)
	ob := new(OrderBook)
	ob.bid = 0
	ob.ask = MAX_PRICE
	ob.actions = actions
	ob.logger = logger
	ob.orderIndex = make(map[Hash]*Order)
	go func() {
		for {
			action := <-actions
			ob.logger = append(ob.logger, action)
			if action.actionType == AT_DONE {
				done <- true
				return
			}
		}
	}()
	for i := range ob.prices {
		ob.prices[i] = new(PricePoint)
	}
	e.pairs[id] = p
	e.orderbooks[p] = ob
	return nil
}
func ( e * TradingEngine ) RegisterNewPair ( p TokenPair , done chan <- bool ) error { if _ , ok := e . quoteTokens [ p . QuoteToken . Address ] ; ! ok { return errors . New ( " " ) } id := p . ComputeID ( ) if _ , ok := e . pairs [ id ] ; ok { return errors . New ( " " ) } p . ID = id actions := make ( chan * Action ) logger := make ( [ ] * Action , 0 ) ob := new ( OrderBook ) ob . bid = 0 ob . ask = MAX_PRICE ob . actions = actions ob . logger = logger ob . orderIndex = make ( map [ Hash ] * Order ) go func ( ) { for { action := <- actions ob . logger = append ( ob . logger , action ) if action . actionType == AT_DONE { done <- true return } } } ( ) for i := range ob . prices { ob . prices [ i ] = new ( PricePoint ) } e . pairs [ id ] = p e . orderbooks [ p ] = ob return nil }
RegisterNewPair registers a new token pair on the engine
To be valid, the quote token of the new token pair needs to be registered in the quote tokens of the engine
RegisterNewPair registers a new token pair on the engine To be valid the quote token of the new token pair needs to be registered in the quote tokens of the engine
// fmt.Printf("\nRegistered new pair %v\n\n", p.String())