-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtime.go
22 lines (19 loc) · 915 Bytes
/
time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package exchangerate
import (
"time"
)
// todo: add tests, but generally well tested in server tests since that's where most of this originated
// todo: does this belong in an exchange-specific package?
// GetLatestExchangeRateTime gets the latest time for fetching an exchange rate.
// By synchronizing on a time, we can eliminate the amount of perceived volatility
// over short time spans.
func GetLatestExchangeRateTime() time.Time {
// Standardize to concrete 15 minute intervals to reduce perceived volatility.
// Notably, don't fall exactly on the 15 minute interval, so we remove 1 second.
// The way our postgres DB query is setup, the start of UTC day is unlikely to
// generate results.
secondsIn15Minutes := int64(15 * time.Minute / time.Second)
queryTimeUnix := time.Now().Unix()
queryTimeUnix = queryTimeUnix - (queryTimeUnix % secondsIn15Minutes) - 1
return time.Unix(queryTimeUnix, 0)
}