How to use Matches method of types Package

Best Ginkgo code snippet using types.Matches

order.go

Source:order.go Github

copy

Full Screen

...283// The request signature message also signals the client to sign trades.284func (s *OrderService) handleEngineOrderMatched(res *types.EngineResponse) {285 o := res.Order //res.Order is the "taker" order286 taker := o.UserAddress287 matches := *res.Matches288 orders := []*types.Order{o}289 validMatches := types.Matches{TakerOrder: o}290 invalidMatches := types.Matches{TakerOrder: o}291 //res.Matches is an array of (order, trade) pairs where each order is an "maker" order that is being matched292 for i, _ := range matches.Trades {293 err := s.validator.ValidateBalance(matches.MakerOrders[i])294 if err != nil {295 logger.Error(err)296 invalidMatches.AppendMatch(matches.MakerOrders[i], matches.Trades[i])297 } else {298 validMatches.AppendMatch(matches.MakerOrders[i], matches.Trades[i])299 orders = append(orders, matches.MakerOrders[i])300 }301 }302 // if there are any invalid matches, the maker orders are at cause (since maker orders have been validated in the303 // newOrder() function. We remove the maker orders from the orderbook)304 if invalidMatches.Length() > 0 {305 err := s.broker.PublishInvalidateMakerOrdersMessage(invalidMatches)306 if err != nil {307 logger.Error(err)308 }309 }310 if validMatches.Length() > 0 {311 err := s.tradeDao.Create(validMatches.Trades...)312 if err != nil {313 logger.Error(err)314 ws.SendOrderMessage("ERROR", taker, err)315 return316 }317 err = s.broker.PublishTrades(&validMatches)318 if err != nil {319 logger.Error(err)320 ws.SendOrderMessage("ERROR", taker, err)321 return322 }323 ws.SendOrderMessage("ORDER_MATCHED", taker, types.OrderMatchedPayload{&matches})324 }325 // we only update the orderbook with the current set of orders if there are no invalid matches.326 // If there are invalid matches, the corresponding maker orders will be removed and the taker order327 // amount filled will be updated as a result, and therefore does not represent the current state of the orderbook328 if invalidMatches.Length() == 0 {329 s.broadcastOrderBookUpdate(orders)330 s.broadcastRawOrderBookUpdate(orders)331 }332}333func (s *OrderService) handleOrderCancelled(res *types.EngineResponse) {334 o := res.Order335 // Save notification336 notifications, err := s.notificationDao.Create(&types.Notification{337 Recipient: o.UserAddress,338 Message: fmt.Sprintf("ORDER_CANCELLED - Order Hash: %s", o.Hash.Hex()),339 Type: types.TypeLog,340 Status: types.StatusUnread,341 })342 if err != nil {343 logger.Error(err)344 }345 ws.SendOrderMessage("ORDER_CANCELLED", o.UserAddress, o)346 ws.SendNotificationMessage("ORDER_CANCELLED", o.UserAddress, notifications)347 s.broadcastOrderBookUpdate([]*types.Order{res.Order})348 s.broadcastRawOrderBookUpdate([]*types.Order{res.Order})349}350func (s *OrderService) handleOrdersInvalidated(res *types.EngineResponse) error {351 orders := res.InvalidatedOrders352 trades := res.CancelledTrades353 for _, o := range *orders {354 ws.SendOrderMessage("ORDER_INVALIDATED", o.UserAddress, o)355 }356 if orders != nil && len(*orders) != 0 {357 s.broadcastOrderBookUpdate(*orders)358 }359 if orders != nil && len(*orders) != 0 {360 s.broadcastRawOrderBookUpdate(*orders)361 }362 if trades != nil && len(*trades) != 0 {363 s.broadcastTradeUpdate(*trades)364 }365 return nil366}367// handleEngineError returns an websocket error message to the client and recovers orders on the368func (s *OrderService) handleEngineError(res *types.EngineResponse) {369 o := res.Order370 ws.SendOrderMessage("ERROR", o.UserAddress, nil)371}372// handleEngineUnknownMessage returns a websocket messsage in case the engine resonse is not recognized373func (s *OrderService) handleEngineUnknownMessage(res *types.EngineResponse) {374 log.Print("Receiving unknown engine message")375 utils.PrintJSON(res)376}377func (s *OrderService) HandleOperatorMessages(msg *types.OperatorMessage) error {378 switch msg.MessageType {379 case types.TRADE_ERROR:380 s.handleOperatorTradeError(msg)381 case types.TRADE_TX_PENDING:382 s.handleOperatorTradeTxPending(msg)383 case types.TRADE_TX_SUCCESS:384 s.handleOperatorTradeTxSuccess(msg)385 case types.TRADE_TX_ERROR:386 s.handleOperatorTradeTxError(msg)387 case types.TRADE_INVALID:388 s.handleOperatorTradeInvalid(msg)389 default:390 s.handleOperatorUnknownMessage(msg)391 }392 return nil393}394func (s *OrderService) handleOperatorTradeTxPending(msg *types.OperatorMessage) {395 matches := msg.Matches396 trades := matches.Trades397 orders := matches.MakerOrders398 taker := trades[0].Taker399 ws.SendOrderMessage("ORDER_PENDING", taker, types.OrderPendingPayload{matches})400 for _, o := range orders {401 maker := o.UserAddress402 ws.SendOrderMessage("ORDER_PENDING", maker, types.OrderPendingPayload{matches})403 }404 s.broadcastTradeUpdate(trades)405}406// handleOperatorTradeSuccess handles successfull trade messages from the orderbook. It updates407// the trade status in the database and408func (s *OrderService) handleOperatorTradeTxSuccess(msg *types.OperatorMessage) {409 matches := msg.Matches410 hashes := []common.Hash{}411 trades := matches.Trades412 for _, t := range trades {413 hashes = append(hashes, t.Hash)414 }415 if len(hashes) == 0 {416 return417 }418 trades, err := s.tradeDao.UpdateTradeStatuses(types.SUCCESS, hashes...)419 if err != nil {420 logger.Error(err)421 }422 // Send ORDER_SUCCESS message to order takers423 taker := trades[0].Taker424 ws.SendOrderMessage("ORDER_SUCCESS", taker, types.OrderSuccessPayload{matches})425 // Send ORDER_SUCCESS message to order makers426 for i, _ := range trades {427 match := matches.NthMatch(i)428 maker := match.MakerOrders[0].UserAddress429 ws.SendOrderMessage("ORDER_SUCCESS", maker, types.OrderSuccessPayload{match})430 }431 s.broadcastTradeUpdate(trades)432}433// handleOperatorTradeTxError handles cases where a blockchain transaction is reverted434func (s *OrderService) handleOperatorTradeTxError(msg *types.OperatorMessage) {435 matches := msg.Matches436 trades := matches.Trades437 orders := matches.MakerOrders438 errType := msg.ErrorType439 if errType != "" {440 logger.Error("")441 }442 for _, t := range trades {443 err := s.tradeDao.UpdateTradeStatus(t.Hash, "ERROR")444 if err != nil {445 logger.Error(err)446 }447 t.Status = "ERROR"448 }449 taker := trades[0].Taker450 ws.SendOrderMessage("ORDER_ERROR", taker, matches)451 for _, o := range orders {452 maker := o.UserAddress453 ws.SendOrderMessage("ORDER_ERROR", maker, o)454 }455 s.broadcastTradeUpdate(trades)456}457// handleOperatorTradeError handles error messages from the operator (case where the blockchain tx was made458// but ended up failing. It updates the trade status in the db.459// orderbook.460func (s *OrderService) handleOperatorTradeError(msg *types.OperatorMessage) {461 matches := msg.Matches462 trades := matches.Trades463 orders := matches.MakerOrders464 errType := msg.ErrorType465 if errType != "" {466 logger.Error("")467 }468 for _, t := range trades {469 err := s.tradeDao.UpdateTradeStatus(t.Hash, "ERROR")470 if err != nil {471 logger.Error(err)472 }473 t.Status = "ERROR"474 }475 taker := trades[0].Taker476 ws.SendOrderMessage("ORDER_ERROR", taker, matches)477 for _, o := range orders {478 maker := o.UserAddress479 ws.SendOrderMessage("ORDER_ERROR", maker, o)480 }481 s.broadcastTradeUpdate(trades)482}483// handleOperatorTradeInvalid handles the case where one of the two orders is invalid484// which can be the case for example if one of the account addresses does suddendly485// not have enough tokens to satisfy the order. Ultimately, the goal would be to486// reinclude the non-invalid orders in the orderbook487func (s *OrderService) handleOperatorTradeInvalid(msg *types.OperatorMessage) {488 matches := msg.Matches489 trades := matches.Trades490 orders := matches.MakerOrders491 errType := msg.ErrorType492 if errType != "" {493 logger.Error("")494 }495 for _, t := range trades {496 err := s.tradeDao.UpdateTradeStatus(t.Hash, "ERROR")497 if err != nil {498 logger.Error(err)499 }500 t.Status = "ERROR"501 }502 taker := trades[0].Taker...

Full Screen

Full Screen

orderbook_test.go

Source:orderbook_test.go Github

copy

Full Screen

...67 exp1.Status = "OPEN"68 expected := &types.EngineResponse{69 Status: "ORDER_ADDED",70 Order: &exp1,71 Matches: nil,72 }73 res, err := ob.sellOrder(&o1)74 if err != nil {75 t.Error("Error in sell order: ", err)76 }77 testutils.CompareEngineResponse(t, expected, res)78}79func TestBuyOrder(t *testing.T) {80 _, ob, _, _, _, _, _, _, factory1, _ := setupTest()81 o1, _ := factory1.NewBuyOrder(1e3, 1e8, 0)82 exp1 := o183 exp1.Status = "OPEN"84 expected := &types.EngineResponse{85 Status: "ORDER_ADDED",86 Order: &exp1,87 Matches: nil,88 }89 res, err := ob.buyOrder(&o1)90 if err != nil {91 t.Error("Error in buy order: ", err)92 }93 testutils.CompareEngineResponse(t, expected, res)94}95func TestFillOrder1(t *testing.T) {96 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()97 o1, _ := factory1.NewSellOrder(1e3, 1e8)98 o2, _ := factory2.NewBuyOrder(1e3, 1e8)99 expt1 := types.NewTrade(&o1, &o2, units.Ethers(1e8), big.NewInt(1e3))100 expo1 := o1101 expo1.Status = "OPEN"102 expectedSellOrderResponse := &types.EngineResponse{Status: "ORDER_ADDED", Order: &expo1}103 expo2 := o2104 expo2.Status = "FILLED"105 expo2.FilledAmount = units.Ethers(1e8)106 expo3 := o1107 expo3.Status = "FILLED"108 expo3.FilledAmount = units.Ethers(1e8)109 expectedMatches := types.NewMatches(110 []*types.Order{&expo3},111 &expo2,112 []*types.Trade{expt1},113 )114 expectedBuyOrderResponse := &types.EngineResponse{115 Status: "ORDER_FILLED",116 Order: &expo2,117 Matches: expectedMatches,118 }119 sellOrderResponse, err := ob.sellOrder(&o1)120 if err != nil {121 t.Errorf("Error when calling sell order")122 }123 buyOrderResponse, err := ob.buyOrder(&o2)124 if err != nil {125 t.Errorf("Error when calling buy order")126 }127 testutils.CompareEngineResponse(t, expectedBuyOrderResponse, buyOrderResponse)128 testutils.CompareEngineResponse(t, expectedSellOrderResponse, sellOrderResponse)129}130func TestFillOrder2(t *testing.T) {131 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()132 o1, _ := factory1.NewBuyOrder(1e3, 1e8)133 o2, _ := factory2.NewSellOrder(1e3, 1e8)134 expt1 := types.NewTrade(&o1, &o2, units.Ethers(1e8), big.NewInt(1e3))135 expo1 := o1136 expo1.Status = "OPEN"137 expectedBuyOrderResponse := &types.EngineResponse{138 Status: "ORDER_ADDED",139 Order: &expo1,140 }141 expo2 := o2142 expo2.Status = "FILLED"143 expo2.FilledAmount = utils.Ethers(1e8)144 expo3 := o1145 expo3.Status = "FILLED"146 expo3.FilledAmount = utils.Ethers(1e8)147 expectedMatches := types.NewMatches(148 []*types.Order{&expo3},149 &expo2,150 []*types.Trade{expt1},151 )152 expectedSellOrderResponse := &types.EngineResponse{153 Status: "ORDER_FILLED",154 Order: &expo2,155 Matches: expectedMatches,156 }157 res1, err := ob.buyOrder(&o1)158 if err != nil {159 t.Error("Error when sending buy order")160 }161 res2, err := ob.sellOrder(&o2)162 if err != nil {163 t.Error("Error when sending sell order")164 }165 testutils.CompareEngineResponse(t, expectedBuyOrderResponse, res1)166 testutils.CompareEngineResponse(t, expectedSellOrderResponse, res2)167}168func TestMultiMatchOrder1(t *testing.T) {169 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()170 so1, _ := factory1.NewSellOrder(1e3+1, 1e8)171 so2, _ := factory1.NewSellOrder(1e3+2, 1e8)172 so3, _ := factory1.NewSellOrder(1e3+3, 1e8)173 bo1, _ := factory2.NewBuyOrder(1e3+4, 3e8)174 ob.sellOrder(&so1)175 ob.sellOrder(&so2)176 ob.sellOrder(&so3)177 expso1 := so1178 expso1.Status = "FILLED"179 expso1.FilledAmount = utils.Ethers(1e8)180 expso2 := so2181 expso2.Status = "FILLED"182 expso2.FilledAmount = utils.Ethers(1e8)183 expso3 := so3184 expso3.Status = "FILLED"185 expso3.FilledAmount = utils.Ethers(1e8)186 expbo1 := bo1187 expbo1.Status = "FILLED"188 expbo1.FilledAmount = utils.Ethers(3e8)189 expt1 := types.NewTrade(&so1, &bo1, utils.Ethers(1e8), big.NewInt(1e3+4))190 expt2 := types.NewTrade(&so2, &bo1, utils.Ethers(1e8), big.NewInt(1e3+4))191 expt3 := types.NewTrade(&so3, &bo1, utils.Ethers(1e8), big.NewInt(1e3+4))192 expectedMatches := types.NewMatches(193 []*types.Order{&expso1, &expso2, &expso3},194 &bo1,195 []*types.Trade{expt1, expt2, expt3},196 )197 expectedResponse := &types.EngineResponse{198 Status: "ORDER_FILLED",199 Order: &bo1,200 Matches: expectedMatches,201 }202 response, err := ob.buyOrder(&bo1)203 if err != nil {204 t.Errorf("Error in sellOrder: %s", err)205 }206 testutils.CompareEngineResponse(t, expectedResponse, response)207}208func TestMultiMatchOrder2(t *testing.T) {209 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()210 bo1, _ := factory1.NewBuyOrder(1e3+1, 1e8)211 bo2, _ := factory1.NewBuyOrder(1e3+2, 1e8)212 bo3, _ := factory1.NewBuyOrder(1e3+3, 1e8)213 so1, _ := factory2.NewSellOrder(1e3, 3e8)214 expbo1 := bo1215 expbo1.Status = "FILLED"216 expbo1.FilledAmount = units.Ethers(1e8)217 expbo2 := bo2218 expbo2.Status = "FILLED"219 expbo2.FilledAmount = units.Ethers(1e8)220 expbo3 := bo3221 expbo3.Status = "FILLED"222 expbo3.FilledAmount = units.Ethers(1e8)223 expso1 := so1224 expso1.Status = "FILLED"225 expso1.FilledAmount = utils.Ethers(3e8)226 ob.buyOrder(&bo1)227 ob.buyOrder(&bo2)228 ob.buyOrder(&bo3)229 expt1 := types.NewTrade(&bo1, &so1, units.Ethers(1e8), big.NewInt(1e3))230 expt2 := types.NewTrade(&bo2, &so1, units.Ethers(1e8), big.NewInt(1e3))231 expt3 := types.NewTrade(&bo3, &so1, units.Ethers(1e8), big.NewInt(1e3))232 expectedMatches := types.NewMatches(233 []*types.Order{&expbo3, &expbo2, &expbo1},234 &so1,235 []*types.Trade{expt3, expt2, expt1},236 )237 expectedResponse := &types.EngineResponse{238 Status: "ORDER_FILLED",239 Order: &so1,240 Matches: expectedMatches,241 }242 res, err := ob.sellOrder(&so1)243 if err != nil {244 t.Errorf("Error in sell order: %s", err)245 }246 testutils.CompareMatches(t, expectedResponse.Matches, res.Matches)247}248func TestPartialMatchOrder1(t *testing.T) {249 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()250 so1, _ := factory1.NewSellOrder(1e3+1, 1e8)251 so2, _ := factory1.NewSellOrder(1e3+2, 1e8)252 so3, _ := factory1.NewSellOrder(1e3+3, 1e8)253 so4, _ := factory1.NewSellOrder(1e3+4, 2e8)254 bo1, _ := factory2.NewBuyOrder(1e3+5, 4e8)255 expso1 := so1256 expso1.FilledAmount = units.Ethers(1e8)257 expso1.Status = "FILLED"258 expso2 := so2259 expso2.FilledAmount = units.Ethers(1e8)260 expso2.Status = "FILLED"261 expso3 := so3262 expso3.FilledAmount = units.Ethers(1e8)263 expso3.Status = "FILLED"264 expso4 := so4265 expso4.FilledAmount = units.Ethers(1e8)266 expso4.Status = "PARTIAL_FILLED"267 expbo1 := bo1268 expbo1.FilledAmount = units.Ethers(4e8)269 expbo1.Status = "FILLED"270 expt1 := types.NewTrade(&so1, &bo1, units.Ethers(1e8), big.NewInt(1e3+5))271 expt2 := types.NewTrade(&so2, &bo1, units.Ethers(1e8), big.NewInt(1e3+5))272 expt3 := types.NewTrade(&so3, &bo1, units.Ethers(1e8), big.NewInt(1e3+5))273 expt4 := types.NewTrade(&so4, &bo1, units.Ethers(1e8), big.NewInt(1e3+5))274 ob.sellOrder(&so1)275 ob.sellOrder(&so2)276 ob.sellOrder(&so3)277 ob.sellOrder(&so4)278 res, err := ob.buyOrder(&bo1)279 if err != nil {280 t.Errorf("Error when buying order")281 }282 expectedMatches := types.NewMatches(283 []*types.Order{&expso1, &expso2, &expso3, &expso4},284 &bo1,285 []*types.Trade{expt1, expt2, expt3, expt4},286 )287 expectedResponse := &types.EngineResponse{288 Status: "ORDER_FILLED",289 Order: &expbo1,290 Matches: expectedMatches,291 }292 testutils.CompareEngineResponse(t, expectedResponse, res)293}294func TestPartialMatchOrder2(t *testing.T) {295 _, ob, _, _, _, _, _, _, factory1, factory2 := setupTest()296 bo1, _ := factory1.NewBuyOrder(1e3+5, 1e8)297 bo2, _ := factory1.NewBuyOrder(1e3+4, 1e8)298 bo3, _ := factory1.NewBuyOrder(1e3+3, 1e8)299 bo4, _ := factory1.NewBuyOrder(1e3+2, 2e8)300 so1, _ := factory2.NewSellOrder(1e3+1, 4e8)301 expbo1 := bo1302 expbo1.FilledAmount = utils.Ethers(1e8)303 expbo1.Status = "FILLED"304 expbo2 := bo2305 expbo2.FilledAmount = utils.Ethers(1e8)306 expbo2.Status = "FILLED"307 expbo3 := bo3308 expbo3.FilledAmount = utils.Ethers(1e8)309 expbo3.Status = "FILLED"310 expbo4 := bo4311 expbo4.FilledAmount = utils.Ethers(1e8)312 expbo4.Status = "PARTIAL_FILLED"313 expso1 := so1314 expso1.FilledAmount = utils.Ethers(4e8)315 expso1.Status = "FILLED"316 expt1 := types.NewTrade(&bo1, &so1, utils.Ethers(1e8), big.NewInt(1e3+1))317 expt2 := types.NewTrade(&bo2, &so1, utils.Ethers(1e8), big.NewInt(1e3+1))318 expt3 := types.NewTrade(&bo3, &so1, utils.Ethers(1e8), big.NewInt(1e3+1))319 expt4 := types.NewTrade(&bo4, &so1, utils.Ethers(1e8), big.NewInt(1e3+1))320 ob.buyOrder(&bo1)321 ob.buyOrder(&bo2)322 ob.buyOrder(&bo3)323 ob.buyOrder(&bo4)324 res, err := ob.sellOrder(&so1)325 if err != nil {326 t.Errorf("Error when buying order")327 }328 expectedMatches := types.NewMatches(329 []*types.Order{&expbo1, &expbo2, &expbo3, &expbo4},330 &so1,331 []*types.Trade{expt1, expt2, expt3, expt4},332 )333 expectedResponse := &types.EngineResponse{334 Status: "ORDER_FILLED",335 Order: &expso1,336 Matches: expectedMatches,337 }338 testutils.CompareEngineResponse(t, expectedResponse, res)339}...

Full Screen

Full Screen

operator.go

Source:operator.go Github

copy

Full Screen

...4 "log"5 "github.com/streadway/amqp"6 "github.com/tomochain/tomoxsdk/types"7)8func (c *Connection) ConsumeQueuedTrades(ch *amqp.Channel, q *amqp.Queue, fn func(*types.Matches, uint64) error) error {9 go func() {10 msgs, err := ch.Consume(11 q.Name, // queue12 "", // consumer13 false, // auto-ack14 false, // exclusive15 false, // no-local16 false, // no-wait17 nil, // args18 )19 if err != nil {20 logger.Fatal("Failed to register a consumer:", err)21 }22 forever := make(chan bool)23 go func() {24 for d := range msgs {25 m := &types.Matches{}26 err := json.Unmarshal(d.Body, &m)27 if err != nil {28 logger.Error(err)29 continue30 }31 logger.Info("Receiving pending trade")32 err = m.Validate()33 if err != nil {34 logger.Error(err)35 d.Nack(false, false)36 } else {37 err = fn(m, d.DeliveryTag)38 if err != nil {39 logger.Error(err)40 d.Nack(false, false)41 } else {42 d.Ack(false)43 }44 }45 }46 }()47 <-forever48 }()49 return nil50}51func (c *Connection) SubscribeOperator(fn func(*types.OperatorMessage) error) error {52 ch := c.GetChannel("OPERATOR_SUB")53 q := c.GetQueue(ch, "TX_MESSAGES")54 go func() {55 msgs, err := ch.Consume(56 q.Name,57 "",58 true,59 false,60 false,61 false,62 nil,63 )64 if err != nil {65 log.Fatal("Failed to register a consumer", err)66 }67 forever := make(chan bool)68 go func() {69 for m := range msgs {70 om := &types.OperatorMessage{}71 err := json.Unmarshal(m.Body, &om)72 if err != nil {73 logger.Error(err)74 continue75 }76 go fn(om)77 }78 }()79 <-forever80 }()81 return nil82}83func (c *Connection) CloseOperatorChannel() error {84 if channels["OPERATOR_SUB"] != nil {85 ch := c.GetChannel("OPERATOR_SUB")86 err := ch.Close()87 if err != nil {88 logger.Error(err)89 }90 channels["OPERATOR_SUB"] = nil91 }92 return nil93}94func (c *Connection) UnsubscribeOperator() error {95 ch := c.GetChannel("OPERATOR_SUB")96 q := c.GetQueue(ch, "TX_MESSAGES")97 err := ch.Cancel(q.Name, false)98 if err != nil {99 logger.Error(err)100 return err101 }102 return nil103}104func (c *Connection) PurgeOperatorQueue() error {105 ch := c.GetChannel("OPERATOR_SUB")106 _, err := ch.QueuePurge("TX_MESSAGES", false)107 if err != nil {108 logger.Error(err)109 return err110 }111 return nil112}113func (c *Connection) PublishTradeSentMessage(matches *types.Matches) error {114 ch := c.GetChannel("OPERATOR_PUB")115 q := c.GetQueue(ch, "TX_MESSAGES")116 msg := &types.OperatorMessage{117 MessageType: types.TRADE_TX_PENDING,118 Matches: matches,119 }120 bytes, err := json.Marshal(msg)121 if err != nil {122 logger.Error(err)123 return err124 }125 err = c.Publish(ch, q, bytes)126 if err != nil {127 logger.Error(err)128 return err129 }130 logger.Info("PUBLISHED TRADE SENT MESSAGE")131 return nil132}133// PublishTradeCancelMessage publishes a message when a trade is cancelled134func (c *Connection) PublishTradeCancelMessage(matches *types.Matches) error {135 ch := c.GetChannel("OPERATOR_PUB")136 q := c.GetQueue(ch, "TX_MESSAGES")137 msg := &types.OperatorMessage{138 MessageType: types.TRADES_CANCELLED,139 Matches: matches,140 }141 bytes, err := json.Marshal(msg)142 if err != nil {143 logger.Infof("Failed to marshal %s: %s", msg.MessageType, err)144 }145 err = c.Publish(ch, q, bytes)146 if err != nil {147 logger.Error(err)148 return err149 }150 logger.Info("PUBLISH TRADE CANCEL MESSAGE")151 return nil152}153// PublishTradeSuccessMessage publishes a message when a trade transaction is successful154func (c *Connection) PublishTradeSuccessMessage(matches *types.Matches) error {155 ch := c.GetChannel("OPERATOR_PUB")156 q := c.GetQueue(ch, "TX_MESSAGES")157 msg := &types.OperatorMessage{158 MessageType: types.TRADE_TX_SUCCESS,159 Matches: matches,160 }161 bytes, err := json.Marshal(msg)162 if err != nil {163 logger.Error(err)164 }165 err = c.Publish(ch, q, bytes)166 if err != nil {167 logger.Error(err)168 return err169 }170 return nil171}172func (c *Connection) PublishErrorMessage(matches *types.Matches, errType string) error {173 ch := c.GetChannel("OPERATOR_PUB")174 q := c.GetQueue(ch, "TX_MESSAGES")175 msg := &types.OperatorMessage{176 MessageType: types.TRADE_ERROR,177 Matches: matches,178 ErrorType: errType,179 }180 bytes, err := json.Marshal(msg)181 if err != nil {182 logger.Infof("Failed to marshal %s: %s", msg.MessageType, err)183 }184 err = c.Publish(ch, q, bytes)185 if err != nil {186 logger.Error(err)187 return err188 }189 logger.Info("PUBLISHED TRADE ERROR MESSAGE. Error Type: %v", errType)190 return nil191}192// PublishTxErrorMessage publishes a messages when a trade execution fails193func (c *Connection) PublishTxErrorMessage(matches *types.Matches, errType string) error {194 ch := c.GetChannel("OPERATOR_PUB")195 q := c.GetQueue(ch, "TX_MESSAGES")196 msg := &types.OperatorMessage{197 MessageType: types.TRADE_TX_ERROR,198 Matches: matches,199 ErrorType: errType,200 }201 bytes, err := json.Marshal(msg)202 if err != nil {203 logger.Infof("Failed to marshal %s: %s", msg.MessageType, err)204 }205 err = c.Publish(ch, q, bytes)206 if err != nil {207 logger.Error(err)208 return err209 }210 logger.Info("PUBLISHED TRADE ERROR MESSAGE. Error Type: %v", errType)211 return nil212}213func (c *Connection) PublishTradeInvalidMessage(matches *types.Matches) error {214 ch := c.GetChannel("OPERATOR_PUB")215 q := c.GetQueue(ch, "TX_MESSAGES")216 msg := &types.OperatorMessage{217 MessageType: types.TRADE_INVALID,218 Matches: matches,219 }220 bytes, err := json.Marshal(msg)221 if err != nil {222 logger.Error(err)223 }224 err = c.Publish(ch, q, bytes)225 if err != nil {226 logger.Error(err)227 return err228 }229 logger.Info("PUBLISHED TRADE INVALID MESSAGE")230 return nil231}...

Full Screen

Full Screen

Matches

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Original string: ", text)4 fmt.Println("Pattern: ", pattern)5 r, _ := regexp.Compile(pattern)6 fmt.Println("Matches: ", r.Matches(text))7}8How to use FindAllStringSubmatchIndex() in Go?9How to use FindAllStringSubmatch() in Go?10How to use FindAllStringIndex() in Go?11How to use FindAllString() in Go?12How to use FindAllIndex() in Go?13How to use FindAll() in Go?14How to use ReplaceAllLiteralString() in Go?15How to use ReplaceAllLiteral() in Go?16How to use ReplaceAllStringFunc() in Go?17How to use ReplaceAllString() in Go?18How to use ReplaceAll() in Go?19How to use FindStringIndex() in Go?20How to use FindString() in Go?21How to use FindIndex() in Go?22How to use Find() in Go?23How to use Split() in Go?24How to use Compile() in Go?25How to use MatchString() in Go?26How to use Match() in Go?27How to use MustCompile() in Go?28How to use QuoteMeta() in Go?29How to use CompilePOSIX() in Go?30How to use CompilePOSIX() in Go?

Full Screen

Full Screen

Matches

Using AI Code Generation

copy

Full Screen

1import "regexp"2import "fmt"3func main() {4re := regexp.MustCompile("p([a-z]+)ch")5fmt.Println(re.MatchString("peach"))6re1 := regexp.MustCompile("[0-9]+")7for _, test := range []string{"123", "peach"} {8if re1.MatchString(test) {9fmt.Println(test, "matches")10} else {11fmt.Println(test, "does not match")12}13}14fmt.Println(re.FindString("peach punch"))15fmt.Println(re.FindStringIndex("peach punch"))16fmt.Println(re.FindStringSubmatch("peach punch"))17fmt.Println(re.FindStringSubmatchIndex("peach punch"))18fmt.Println(re.FindAllString("peach punch pinch", -1))19fmt.Println(re.FindAllStringSubmatchIndex(20fmt.Println(re.FindAllString("peach punch pinch", 2))21fmt.Println(re.Match([]byte("peach")))

Full Screen

Full Screen

Matches

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 re := regexp.MustCompile("a(x*)b")4}5import (6func main() {7 re := regexp.MustCompile("a(x*)b")8}9import (10func main() {11 re := regexp.MustCompile("a(x*)b")

Full Screen

Full Screen

Matches

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var pattern = regexp.MustCompile(`(?m)(^\w+)(.*)(\.$)`)4 var matches = pattern.FindAllString(text, -1)5 for _, match := range matches {6 fmt.Println(match)7 }8 fmt.Println("Number of matches:", len(matches))9}10import (11func main() {12 var pattern = regexp.MustCompile(`(?m)(^\w+)(.*)(\.$)`)13 var match = pattern.FindString(text)14 fmt.Println(match)15}16import (17func main() {18 var pattern = regexp.MustCompile(`(?m)(^\w+)(.*)(\.$)`)19 var match = pattern.FindStringIndex(text)20 fmt.Println(match)21}22import (23func main() {24 var pattern = regexp.MustCompile(`(?m)(^\w+)(.*)(\.$)`)25 var match = pattern.FindStringSubmatch(text)26 fmt.Println(match)27}

Full Screen

Full Screen

Matches

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 re := regexp.MustCompile("[a-b]")4 str := []string{"a", "b", "c", "d", "e"}5 for _, v := range str {6 fmt.Println(re.FindString(v))7 }8}9import (10func main() {11 re := regexp.MustCompile("[a-b]")12 str := []string{"a", "b", "c", "d", "e"}13 for _, v := range str {14 fmt.Println(re.FindString(v))15 }16}17import (18func main() {19 re := regexp.MustCompile("[a-b]")20 str := []string{"a", "b", "c", "d", "e"}21 for _, v := range str {22 fmt.Println(re.FindString(v))23 }24}25import (26func main() {27 re := regexp.MustCompile("[a-b]")28 str := []string{"a", "b", "c", "d", "e"}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful