Skip to content

Commit

Permalink
Update filledAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnguyennguyen committed Aug 5, 2019
1 parent 190a3dc commit b3cc5ae
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tomox/tomox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,15 @@ func (tomox *TomoX) SyncDataToSDKNode(txDataMatch *TxDataMatch, txHash common.Ha
if err := db.Put(EmptyKey(), tradeSDK, false); err != nil {
return fmt.Errorf("SDKNode: failed to store tradeSDK %s", err.Error())
}

filledAmount, ok := new(big.Int).SetString(trade["quantity"], 10)
if !ok {
return fmt.Errorf("failed to get tradedQuantity. QuantityString: %s", trade["quantity"])
}
// update order status of relating orders
if err := tomox.updateStatusOfMatchedOrder(trade["makerOrderHash"]); err != nil {
if err := tomox.updateStatusOfMatchedOrder(trade["makerOrderHash"], filledAmount); err != nil {
return err
}
if err := tomox.updateStatusOfMatchedOrder(trade["takerOrderHash"]); err != nil {
if err := tomox.updateStatusOfMatchedOrder(trade["takerOrderHash"],filledAmount); err != nil {
return err
}
}
Expand All @@ -1349,7 +1352,7 @@ func (tomox *TomoX) SyncDataToSDKNode(txDataMatch *TxDataMatch, txHash common.Ha
return nil
}

func (tomox *TomoX) updateStatusOfMatchedOrder(hashString string) error {
func (tomox *TomoX) updateStatusOfMatchedOrder(hashString string, filledAmount *big.Int) error {
db := tomox.GetDB()
orderHashBytes, err := hex.DecodeString(hashString)
if err != nil {
Expand All @@ -1361,6 +1364,9 @@ func (tomox *TomoX) updateStatusOfMatchedOrder(hashString string) error {
}
matchedOrder := val.(*OrderItem)
matchedOrder.Status = sdktypes.OrderStatusFilled
updatedFillAmount := new(big.Int)
updatedFillAmount.Add(matchedOrder.FilledAmount, filledAmount)
matchedOrder.FilledAmount = updatedFillAmount
if err = db.Put(matchedOrder.Hash.Bytes(), matchedOrder, false); err != nil {
return fmt.Errorf("SDKNode: failed to update matchedOrder to sdkNode %s", err.Error())
}
Expand Down

0 comments on commit b3cc5ae

Please sign in to comment.