/
trade_aggregation.go
40 lines (37 loc) · 1.03 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
package resourceadapter
import (
"context"
"github.com/AnneNamuli/go-stellar/amount"
"github.com/AnneNamuli/go-stellar/price"
protocol "github.com/AnneNamuli/go-stellar/protocols/horizon"
"github.com/AnneNamuli/go-stellar/services/horizon/internal/db2/history"
)
// Populate fills out the details of a trade using a row from the history_trades
// 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.High = row.High.String()
dest.HighR = row.High
dest.Low = row.Low.String()
dest.LowR = row.Low
dest.Open = row.Open.String()
dest.OpenR = row.Open
dest.Close = row.Close.String()
dest.CloseR = row.Close
return nil
}