-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
65 lines (59 loc) · 2.26 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"os"
"strings"
"time"
framework "github.com/hyplabs/dfinity-oracle-framework"
"github.com/hyplabs/dfinity-oracle-framework/models"
)
func generateEndpoints(coinName string) []models.Endpoint {
coinMarketCapAPIKey := os.Getenv("COINMARKETCAP_API_KEY")
lowercaseCoinName := strings.ToLower(coinName)
return []models.Endpoint{
{
Endpoint: "https://api.coingecko.com/api/v3/simple/price?" + lowercaseCoinName + "&vs_currencies=usd",
JSONPaths: map[string]string{
"usd_per_token": "$." + lowercaseCoinName + ".usd",
},
},
{
Endpoint: "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?slug=" + lowercaseCoinName + "&CMC_PRO_API_KEY=" + coinMarketCapAPIKey,
JSONPaths: map[string]string{
"usd_per_token": "$.data..quote.USD.price",
},
},
}
}
func main() {
config := models.Config{
CanisterName: "crypto_oracle",
UpdateInterval: 5 * time.Second,
}
engine := models.Engine{
Metadata: []models.MappingMetadata{
{Key: "Bitcoin", Endpoints: generateEndpoints("Bitcoin")},
{Key: "Ethereum", Endpoints: generateEndpoints("Ethereum")},
{Key: "Cardano", Endpoints: generateEndpoints("Cardano")},
{Key: "Polkadot", Endpoints: generateEndpoints("Polkadot")},
{Key: "Uniswap", Endpoints: generateEndpoints("Uniswap")},
{Key: "Litecoin", Endpoints: generateEndpoints("Litecoin")},
{Key: "Chainlink", Endpoints: generateEndpoints("Chainlink")},
{Key: "Stellar", Endpoints: generateEndpoints("Stellar")},
{Key: "Filecoin", Endpoints: generateEndpoints("Filecoin")},
{Key: "TRON", Endpoints: generateEndpoints("TRON")},
{Key: "Dogecoin", Endpoints: generateEndpoints("Dogecoin")},
{Key: "Solana", Endpoints: generateEndpoints("Solana")},
{Key: "EOS", Endpoints: generateEndpoints("EOS")},
{Key: "Monero", Endpoints: generateEndpoints("Monero")},
{Key: "Terra", Endpoints: generateEndpoints("Terra")},
{Key: "IOTA", Endpoints: generateEndpoints("IOTA")},
{Key: "Cosmos", Endpoints: generateEndpoints("Cosmos")},
{Key: "Algorand", Endpoints: generateEndpoints("Algorand")},
{Key: "Tezos", Endpoints: generateEndpoints("Tezos")},
{Key: "Avalanche", Endpoints: generateEndpoints("Avalanche")},
},
}
oracle := framework.NewOracle(&config, &engine)
oracle.Bootstrap()
oracle.Run()
}