Skip to content

Commit

Permalink
Merge pull request #338 from digital-asset/0.1.x-fix-matching-timestamp
Browse files Browse the repository at this point in the history
change matching engine timeMatched to match exberry timestamp
  • Loading branch information
alexgraham-da committed May 19, 2021
2 parents 86905ef + e3fc2fe commit 7126a41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions triggers/daml/MatchingEngine.daml
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ handleOrder party orders (orderCid, order) = do
let fillQty = min passive.qty aggressive.qty
fillPrice = passive.price

time <- getTime
nanoTimestamp <- (1000 *) <$> getUnixTimestamp

emitExerciseCmd aggressiveCid Order_Fill with
fillQty, fillPrice
counterOrderId = passive.orderId
counterParty = passive.exchParticipant
timeMatched = show time
timeMatched = show nanoTimestamp

emitExerciseCmd passiveCid Order_Fill with
fillQty, fillPrice
counterOrderId = aggressive.orderId
counterParty = aggressive.exchParticipant
timeMatched = show time
timeMatched = show nanoTimestamp

return ()

Expand Down Expand Up @@ -192,7 +192,7 @@ handleClearedOrder party orders (orderCid, order) = do
let fillQty = min passive.qty aggressive.qty
fillPrice = passive.price

time <- getTime
nanoTimestamp <- (* 1000) <$> getUnixTimestamp

emitExerciseCmd aggressiveCid ClearedOrder_Fill with
fillQty, fillPrice
Expand All @@ -210,7 +210,7 @@ handleClearedOrder party orders (orderCid, order) = do
instrument = instrumentId
exchange = party
eventId = -1
timeMatched = (show time)
timeMatched = show nanoTimestamp
pair = order.pair
trackingNumber = -1
buyer = buyer.exchParticipant
Expand Down
6 changes: 6 additions & 0 deletions triggers/daml/Utils.daml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module Utils where

import DA.Time
import DA.Date
import Daml.Trigger

type ContractPair a = (ContractId a, a)

-- |Helper function to exercise a choice
emitExerciseCmd : (Template t, Choice t c r) => ContractId t -> c -> TriggerA s CommandId
emitExerciseCmd cid c = emitCommands [exerciseCmd cid c] [toAnyContractId cid]

getUnixTimestamp : TriggerA s Int
getUnixTimestamp = convertRelTimeToMicroseconds . (flip subTime) (time (date 1970 Jan 1) 0 0 0) <$> getTime

0 comments on commit 7126a41

Please sign in to comment.