Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 7126a41

Browse files
Merge pull request #338 from digital-asset/0.1.x-fix-matching-timestamp
change matching engine timeMatched to match exberry timestamp
2 parents 86905ef + e3fc2fe commit 7126a41

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

triggers/daml/MatchingEngine.daml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ handleOrder party orders (orderCid, order) = do
125125
let fillQty = min passive.qty aggressive.qty
126126
fillPrice = passive.price
127127

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

130130
emitExerciseCmd aggressiveCid Order_Fill with
131131
fillQty, fillPrice
132132
counterOrderId = passive.orderId
133133
counterParty = passive.exchParticipant
134-
timeMatched = show time
134+
timeMatched = show nanoTimestamp
135135

136136
emitExerciseCmd passiveCid Order_Fill with
137137
fillQty, fillPrice
138138
counterOrderId = aggressive.orderId
139139
counterParty = aggressive.exchParticipant
140-
timeMatched = show time
140+
timeMatched = show nanoTimestamp
141141

142142
return ()
143143

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

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

197197
emitExerciseCmd aggressiveCid ClearedOrder_Fill with
198198
fillQty, fillPrice
@@ -210,7 +210,7 @@ handleClearedOrder party orders (orderCid, order) = do
210210
instrument = instrumentId
211211
exchange = party
212212
eventId = -1
213-
timeMatched = (show time)
213+
timeMatched = show nanoTimestamp
214214
pair = order.pair
215215
trackingNumber = -1
216216
buyer = buyer.exchParticipant

triggers/daml/Utils.daml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
module Utils where
22

3+
import DA.Time
4+
import DA.Date
35
import Daml.Trigger
46

57
type ContractPair a = (ContractId a, a)
68

79
-- |Helper function to exercise a choice
810
emitExerciseCmd : (Template t, Choice t c r) => ContractId t -> c -> TriggerA s CommandId
911
emitExerciseCmd cid c = emitCommands [exerciseCmd cid c] [toAnyContractId cid]
12+
13+
getUnixTimestamp : TriggerA s Int
14+
getUnixTimestamp = convertRelTimeToMicroseconds . (flip subTime) (time (date 1970 Jan 1) 0 0 0) <$> getTime
15+

0 commit comments

Comments
 (0)