forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriceFeed.go
More file actions
33 lines (27 loc) · 747 Bytes
/
Copy pathpriceFeed.go
File metadata and controls
33 lines (27 loc) · 747 Bytes
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
package api
import "log"
// PriceFeed allows you to fetch the price of a feed
type PriceFeed interface {
GetPrice() (float64, error)
}
// TODO this should be structured as a specific impl. of the PriceFeed interface
// FeedPair is the struct representing a price feed for a trading pair
type FeedPair struct {
FeedA PriceFeed
FeedB PriceFeed
}
// GetFeedPairPrice fetches the price by dividing FeedA by FeedB
func (p *FeedPair) GetFeedPairPrice() (float64, error) {
pA, err := p.FeedA.GetPrice()
if err != nil {
return 0, err
}
var pB float64
pB, err = p.FeedB.GetPrice()
if err != nil {
return 0, err
}
price := pA / pB
log.Printf("feedPair prices: feedA=%.8f, feedB=%.8f; price=%.8f\n", pA, pB, price)
return price, nil
}