-
Notifications
You must be signed in to change notification settings - Fork 0
/
trade_aggregation.go
52 lines (49 loc) · 1.25 KB
/
trade_aggregation.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package resourceadapter
import (
"context"
"github.com/shantanu-hashcash/go/amount"
"github.com/shantanu-hashcash/go/price"
protocol "github.com/shantanu-hashcash/go/protocols/aurora"
"github.com/shantanu-hashcash/go/services/aurora/internal/db2/history"
)
// PopulateTradeAggregation fills out the details of a trade aggregation using a row from the trade aggregations
// table.
func PopulateTradeAggregation(
ctx context.Context,
dest *protocol.TradeAggregation,
row history.TradeAggregation,
) error {
var err error
dest.Timestamp = row.Timestamp
dest.TradeCount = row.TradeCount
dest.BaseVolume, err = amount.IntStringToAmount(row.BaseVolume)
if err != nil {
return err
}
dest.CounterVolume, err = amount.IntStringToAmount(row.CounterVolume)
if err != nil {
return err
}
dest.Average = price.StringFromFloat64(row.Average)
dest.HighR = protocol.TradePrice{
N: row.HighN,
D: row.HighD,
}
dest.High = dest.HighR.String()
dest.LowR = protocol.TradePrice{
N: row.LowN,
D: row.LowD,
}
dest.Low = dest.LowR.String()
dest.OpenR = protocol.TradePrice{
N: row.OpenN,
D: row.OpenD,
}
dest.Open = dest.OpenR.String()
dest.CloseR = protocol.TradePrice{
N: row.CloseN,
D: row.CloseD,
}
dest.Close = dest.CloseR.String()
return nil
}