forked from stellar-deprecated/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
priceFeed.go
39 lines (35 loc) · 1.03 KB
/
priceFeed.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
package plugins
import (
"strings"
"github.com/lightyeario/kelp/api"
"github.com/lightyeario/kelp/model"
)
// MakePriceFeed makes a PriceFeed
func MakePriceFeed(feedType string, url string) api.PriceFeed {
switch feedType {
case "crypto":
return newCMCFeed(url)
case "fiat":
return newFiatFeed(url)
case "fixed":
return newFixedFeed(url)
case "exchange":
// [0] = exchangeType, [1] = base, [2] = quote
urlParts := strings.Split(url, "/")
exchange := MakeExchange(urlParts[0])
tradingPair := model.TradingPair{
Base: exchange.GetAssetConverter().MustFromString(urlParts[1]),
Quote: exchange.GetAssetConverter().MustFromString(urlParts[2]),
}
tradeAPI := api.TradeAPI(exchange)
return newExchangeFeed(&tradeAPI, &tradingPair)
}
return nil
}
// MakeFeedPair is the factory method that we expose
func MakeFeedPair(dataTypeA, dataFeedAUrl, dataTypeB, dataFeedBUrl string) *api.FeedPair {
return &api.FeedPair{
FeedA: MakePriceFeed(dataTypeA, dataFeedAUrl),
FeedB: MakePriceFeed(dataTypeB, dataFeedBUrl),
}
}