diff --git a/triggers/daml/MatchingEngine.daml b/triggers/daml/MatchingEngine.daml index 9a74dd33..ba05d56e 100644 --- a/triggers/daml/MatchingEngine.daml +++ b/triggers/daml/MatchingEngine.daml @@ -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 () @@ -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 @@ -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 diff --git a/triggers/daml/Utils.daml b/triggers/daml/Utils.daml index c25efb67..acae54cf 100644 --- a/triggers/daml/Utils.daml +++ b/triggers/daml/Utils.daml @@ -1,5 +1,7 @@ module Utils where +import DA.Time +import DA.Date import Daml.Trigger type ContractPair a = (ContractId a, a) @@ -7,3 +9,7 @@ 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 +