forked from pegnet/pegnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeg.go
38 lines (29 loc) · 903 Bytes
/
peg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) of parts are held by the various contributors (see the CLA)
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
package polling
import (
"math/rand"
"time"
"github.com/pegnet/pegnet/common"
)
const qlimit = 580 // Limit queries to once just shy of 10 minutes (600 seconds)
type PegAssets map[string]PegItem
func (p PegAssets) Clone(randomize float64) PegAssets {
np := make(PegAssets)
for _, asset := range common.AllAssets {
np[asset] = p[asset].Clone(randomize)
}
return np
}
type PegItem struct {
Value float64
WhenUnix int64 // unix timestamp
When time.Time
}
func (p PegItem) Clone(randomize float64) PegItem {
np := new(PegItem)
np.Value = p.Value + p.Value*(randomize/2*rand.Float64()) - p.Value*(randomize/2*rand.Float64())
np.Value = TruncateTo8(np.Value)
np.WhenUnix = p.WhenUnix
return *np
}