forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_book_summary.go
48 lines (40 loc) · 944 Bytes
/
order_book_summary.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
package resourceadapter
import (
"context"
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/xdr"
. "github.com/stellar/go/protocols/horizon"
)
func PopulateOrderBookSummary(
ctx context.Context,
dest *OrderBookSummary,
selling xdr.Asset,
buying xdr.Asset,
row core.OrderBookSummary,
) error {
err := PopulateAsset(ctx, &dest.Selling, selling)
if err != nil {
return err
}
err = PopulateAsset(ctx, &dest.Buying, buying)
if err != nil {
return err
}
populatePriceLevels(&dest.Bids, row.Bids())
populatePriceLevels(&dest.Asks, row.Asks())
return nil
}
func populatePriceLevels(destp *[]PriceLevel, rows []core.OrderBookSummaryPriceLevel) {
*destp = make([]PriceLevel, len(rows))
dest := *destp
for i, row := range rows {
dest[i] = PriceLevel{
Price: row.PriceAsString(),
Amount: row.AmountAsString(),
PriceR: Price{
N: row.Pricen,
D: row.Priced,
},
}
}
}