From 58ddd2f7d9011da328ea42fc90df788777f4066e Mon Sep 17 00:00:00 2001 From: Tuna Date: Tue, 30 Jul 2019 13:57:46 +0700 Subject: [PATCH] add more log 2 --- tomox/orderbook.go | 38 +++++++++++++++++++------------------- tomox/orderlist.go | 6 +++--- tomox/ordertree.go | 8 ++++---- tomox/redblacktree.go | 12 ++++++++---- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/tomox/orderbook.go b/tomox/orderbook.go index 371775cab764..77478b70f4d9 100755 --- a/tomox/orderbook.go +++ b/tomox/orderbook.go @@ -253,26 +253,26 @@ func (orderBook *OrderBook) processLimitOrder(order *OrderItem, verbose bool, dr if side == Bid { minPrice := orderBook.Asks.MinPrice(dryrun) - log.Debug("Min price in asks tree", "price", minPrice.String(), "dryrun", dryrun) + log.Debug("Min price in asks tree", "price", minPrice.String()) for quantityToTrade.Cmp(zero) > 0 && orderBook.Asks.NotEmpty() && price.Cmp(minPrice) >= 0 { bestPriceAsks := orderBook.Asks.MinPriceList(dryrun) - log.Debug("Orderlist at min price", "orderlist", bestPriceAsks.Item, "dryrun", dryrun) + log.Debug("Orderlist at min price", "orderlist", bestPriceAsks.Item) quantityToTrade, newTrades, orderInBook, err = orderBook.processOrderList(Ask, bestPriceAsks, quantityToTrade, order, verbose, dryrun) if err != nil { return nil, nil, err } trades = append(trades, newTrades...) - log.Debug("New trade found", "newTrades", newTrades, "orderInBook", orderInBook, "quantityToTrade", quantityToTrade, "dryrun", dryrun) + log.Debug("New trade found", "newTrades", newTrades, "orderInBook", orderInBook, "quantityToTrade", quantityToTrade) minPrice = orderBook.Asks.MinPrice(dryrun) - log.Debug("New min price in asks tree", "price", minPrice.String(), "dryrun", dryrun) + log.Debug("New min price in asks tree", "price", minPrice.String()) } if quantityToTrade.Cmp(zero) > 0 { order.OrderID = orderBook.Item.NextOrderID order.Quantity = quantityToTrade - log.Debug("After matching, order (unmatched part) is now added to bids tree", "order", order, "dryrun", dryrun) + log.Debug("After matching, order (unmatched part) is now added to bids tree", "order", order) if err := orderBook.Bids.InsertOrder(order, dryrun); err != nil { - log.Error("Failed to insert order to bidTree", "pairName", order.PairName, "orderItem", order, "err", err, "dryrun", dryrun) + log.Error("Failed to insert order to bidTree", "pairName", order.PairName, "orderItem", order, "err", err) return nil, nil, err } orderInBook = order @@ -280,26 +280,26 @@ func (orderBook *OrderBook) processLimitOrder(order *OrderItem, verbose bool, dr } else { maxPrice := orderBook.Bids.MaxPrice(dryrun) - log.Debug("Max price in bids tree", "price", maxPrice.String(), "dryrun", dryrun) + log.Debug("Max price in bids tree", "price", maxPrice.String()) for quantityToTrade.Cmp(zero) > 0 && orderBook.Bids.NotEmpty() && price.Cmp(maxPrice) <= 0 { bestPriceBids := orderBook.Bids.MaxPriceList(dryrun) - log.Debug("Orderlist at max price", "orderlist", bestPriceBids.Item, "dryrun", dryrun) + log.Debug("Orderlist at max price", "orderlist", bestPriceBids.Item) quantityToTrade, newTrades, orderInBook, err = orderBook.processOrderList(Bid, bestPriceBids, quantityToTrade, order, verbose, dryrun) if err != nil { return nil, nil, err } trades = append(trades, newTrades...) - log.Debug("New trade found", "newTrades", newTrades, "orderInBook", orderInBook, "quantityToTrade", quantityToTrade, "dryrun", dryrun) + log.Debug("New trade found", "newTrades", newTrades, "orderInBook", orderInBook, "quantityToTrade", quantityToTrade) maxPrice = orderBook.Bids.MaxPrice(dryrun) - log.Debug("New max price in bids tree", "price", maxPrice.String(), "dryrun", dryrun) + log.Debug("New max price in bids tree", "price", maxPrice.String()) } if quantityToTrade.Cmp(zero) > 0 { order.OrderID = orderBook.Item.NextOrderID order.Quantity = quantityToTrade - log.Debug("After matching, order (unmatched part) is now back to asks tree", "order", order, "dryrun", dryrun) + log.Debug("After matching, order (unmatched part) is now back to asks tree", "order", order) if err := orderBook.Asks.InsertOrder(order, dryrun); err != nil { - log.Error("Failed to insert order to askTree", "pairName", order.PairName, "orderItem", order, "err", err, "dryrun", dryrun) + log.Error("Failed to insert order to askTree", "pairName", order.PairName, "orderItem", order, "err", err) return nil, nil, err } orderInBook = order @@ -344,7 +344,7 @@ func (orderBook *OrderBook) ProcessOrder(order *OrderItem, verbose bool, dryrun // processOrderList : process the order list func (orderBook *OrderBook) processOrderList(side string, orderList *OrderList, quantityStillToTrade *big.Int, order *OrderItem, verbose bool, dryrun bool) (*big.Int, []map[string]string, *OrderItem, error) { - log.Debug("Process matching between order and orderlist", "dryrun", dryrun) + log.Debug("Process matching between order and orderlist") quantityToTrade := CloneBigInt(quantityStillToTrade) var ( trades []map[string]string @@ -358,7 +358,7 @@ func (orderBook *OrderBook) processOrderList(side string, orderList *OrderList, if headOrder == nil { return nil, nil, nil, fmt.Errorf("headOrder is null") } - log.Debug("Get head order in the orderlist", "headOrder", headOrder.Item, "dryrun", dryrun) + log.Debug("Get head order in the orderlist", "headOrder", headOrder.Item) tradedPrice := CloneBigInt(headOrder.Item.Price) @@ -374,7 +374,7 @@ func (orderBook *OrderBook) processOrderList(side string, orderList *OrderList, if err := headOrder.UpdateQuantity(orderList, newBookQuantity, headOrder.Item.UpdatedAt, dryrun); err != nil { return nil, nil, nil, err } - log.Debug("Update quantity for head order", "headOrder", headOrder.Item, "dryrun", dryrun) + log.Debug("Update quantity for head order", "headOrder", headOrder.Item) quantityToTrade = Zero() orderInBook = headOrder.Item } else if IsEqual(quantityToTrade, headOrder.Item.Quantity) { @@ -383,12 +383,12 @@ func (orderBook *OrderBook) processOrderList(side string, orderList *OrderList, if err := orderBook.Bids.RemoveOrderFromOrderList(headOrder, orderList, dryrun); err != nil { return nil, nil, nil, err } - log.Debug("Removed headOrder from bids orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side, "dryrun", dryrun) + log.Debug("Removed headOrder from bids orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side) } else { if err := orderBook.Asks.RemoveOrderFromOrderList(headOrder, orderList, dryrun); err != nil { return nil, nil, nil, err } - log.Debug("Removed headOrder from asks orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side, "dryrun", dryrun) + log.Debug("Removed headOrder from asks orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side) } quantityToTrade = Zero() @@ -398,12 +398,12 @@ func (orderBook *OrderBook) processOrderList(side string, orderList *OrderList, if err := orderBook.Bids.RemoveOrderFromOrderList(headOrder, orderList, dryrun); err != nil { return nil, nil, nil, err } - log.Debug("Removed headOrder from bids orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side, "dryrun", dryrun) + log.Debug("Removed headOrder from bids orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side) } else { if err := orderBook.Asks.RemoveOrderFromOrderList(headOrder, orderList, dryrun); err != nil { return nil, nil, nil, err } - log.Debug("Removed headOrder from asks orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side, "dryrun", dryrun) + log.Debug("Removed headOrder from asks orderlist", "headOrder", headOrder.Item, "orderlist", orderList.Item, "side", side) } quantityToTrade = Sub(quantityToTrade, tradedQuantity) } diff --git a/tomox/orderlist.go b/tomox/orderlist.go index 0cb3e988d573..f7dbe10cdf55 100755 --- a/tomox/orderlist.go +++ b/tomox/orderlist.go @@ -88,7 +88,7 @@ func NewOrderListWithItem(item *OrderListItem, orderTree *OrderTree) *OrderList func (orderList *OrderList) GetOrder(key []byte, dryrun bool) *Order { // re-use method from orderbook, because orderlist has the same slot as orderbook storedKey := orderList.GetOrderIDFromKey(key) - log.Debug("Get order from key", "storedKey", storedKey) + log.Debug("Get order from key", "storedKey", hex.EncodeToString(storedKey)) return orderList.orderTree.orderBook.GetOrder(storedKey, key, dryrun) } @@ -263,9 +263,9 @@ func (orderList *OrderList) RemoveOrder(order *Order, dryrun bool) error { } nextOrder := orderList.GetOrder(order.Item.NextOrder, dryrun) - log.Debug("Orderlist remove order debug", "nextOrder", nextOrder.Item) + log.Debug("Orderlist remove order debug", "nextOrder", nextOrder) prevOrder := orderList.GetOrder(order.Item.PrevOrder, dryrun) - log.Debug("Orderlist remove order debug", "prevOrder", prevOrder.Item) + log.Debug("Orderlist remove order debug", "prevOrder", prevOrder) orderList.Item.Volume = Sub(orderList.Item.Volume, order.Item.Quantity) orderList.Item.Length-- diff --git a/tomox/ordertree.go b/tomox/ordertree.go index d4308b08a101..51302d3e0c4f 100755 --- a/tomox/ordertree.go +++ b/tomox/ordertree.go @@ -184,16 +184,16 @@ func (orderTree *OrderTree) Depth() uint64 { func (orderTree *OrderTree) RemovePrice(price *big.Int, dryrun bool) error { if orderTree.Depth() > 0 { priceKey := orderTree.getKeyFromPrice(price) - log.Debug("Remove price", "price", price.String(), "priceKey", hex.EncodeToString(priceKey), "dryrun", dryrun) + log.Debug("Remove price", "price", price.String(), "priceKey", hex.EncodeToString(priceKey)) orderListKey := GetOrderListCommonKey(priceKey) - log.Debug("Remove price", "price", price.String(), "orderListKey", hex.EncodeToString(orderListKey), "dryrun", dryrun) + log.Debug("Remove price", "price", price.String(), "orderListKey", hex.EncodeToString(orderListKey)) orderTree.PriceTree.Remove(orderListKey, dryrun) - log.Debug("Removed price from price tree", "price", price.String(), "orderListKey", hex.EncodeToString(orderListKey), "dryrun", dryrun) + log.Debug("Removed price from price tree", "price", price.String(), "orderListKey", hex.EncodeToString(orderListKey)) // should use batch to optimize the performance if err := orderTree.Save(dryrun); err != nil { return err } - log.Debug("Remove price - saved ordertree", "dryrun", dryrun) + log.Debug("Remove price - saved ordertree") } return nil } diff --git a/tomox/redblacktree.go b/tomox/redblacktree.go index 2cff30efb772..cd5e4468843b 100644 --- a/tomox/redblacktree.go +++ b/tomox/redblacktree.go @@ -158,7 +158,7 @@ func (tree *Tree) Remove(key []byte, dryrun bool) { if err != nil || node == nil { return } - log.Debug("Get node", "node", node, "dryrun", dryrun) + log.Debug("Get node", "node", node) var left, right *Node = nil, nil if !tree.IsEmptyKey(node.LeftKey()) { @@ -367,6 +367,7 @@ func output(tree *Tree, node *Node, prefix string, isTail bool, str *string, dry } func (tree *Tree) rotateLeft(node *Node, dryrun bool) { + log.Debug("Rotate left - before", "nodeRoot", hex.EncodeToString(tree.Root(dryrun).Value())) right := node.Right(tree, dryrun) tree.replaceNode(node, right, dryrun) node.RightKey(right.LeftKey()) @@ -379,9 +380,11 @@ func (tree *Tree) rotateLeft(node *Node, dryrun bool) { node.ParentKey(right.Key) tree.Save(node, dryrun) tree.Save(right, dryrun) + log.Debug("Rotate left - after", "nodeRoot", hex.EncodeToString(tree.Root(dryrun).Value())) } func (tree *Tree) rotateRight(node *Node, dryrun bool) { + log.Debug("Rotate right - before", "nodeRoot", hex.EncodeToString(tree.Root(dryrun).Value())) left := node.Left(tree, dryrun) tree.replaceNode(node, left, dryrun) node.LeftKey(left.RightKey()) @@ -394,10 +397,11 @@ func (tree *Tree) rotateRight(node *Node, dryrun bool) { node.ParentKey(left.Key) tree.Save(node, dryrun) tree.Save(left, dryrun) + log.Debug("Rotate right - after", "nodeRoot", hex.EncodeToString(tree.Root(dryrun).Value())) } func (tree *Tree) replaceNode(old *Node, new *Node, dryrun bool) { - log.Debug("Replace node", "old", old, "new", new, "dryrun", dryrun) + log.Debug("Replace node", "old", old, "new", new) // we do not change any byte of Key so we can copy the reference to save directly to db var newKey []byte @@ -513,7 +517,7 @@ func (tree *Tree) insertCase5(node *Node, dryrun bool) { } func (tree *Tree) Save(node *Node, dryrun bool) error { - log.Debug("Save node", "node", node, "dryrun", dryrun) + log.Debug("Save node", "node", node) return tree.db.Put(node.Key, node.Item, dryrun) } @@ -659,6 +663,6 @@ func nodeColor(node *Node) bool { } func (tree *Tree) deleteNode(node *Node, dryrun bool) { - log.Debug("Delete node", "node value", hex.EncodeToString(node.Value()), "dryrun", dryrun) + log.Debug("Delete node", "node value", hex.EncodeToString(node.Value())) tree.db.Delete(node.Key, dryrun) }