-
Notifications
You must be signed in to change notification settings - Fork 5
/
price_server.go
73 lines (66 loc) · 2.01 KB
/
price_server.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
66
67
68
69
70
71
72
73
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/terra-money/oracle-feeder-go/config"
"github.com/terra-money/oracle-feeder-go/internal/provider"
alliance_provider "github.com/terra-money/oracle-feeder-go/internal/provider/alliance"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Print("Error loading .env file:", err)
}
ctx := context.Background()
stopCh := make(chan struct{})
manager := provider.NewProviderManager(&config.DefaultPriceServerConfig, stopCh)
allianceProvider := alliance_provider.NewAllianceProvider(&config.AllianceDefaultConfig, manager)
r := gin.Default()
r.GET("/health", func(c *gin.Context) {
c.String(http.StatusOK, "OK")
})
r.GET("/latest", func(c *gin.Context) {
prices := manager.GetPrices(ctx)
c.JSON(http.StatusOK, prices)
})
r.GET("/alliance/protocol", func(c *gin.Context) {
allianceProtocolRes, err := allianceProvider.GetProtocolsInfo(ctx)
// allianceProtocolRes.UpdateChainsInfo.ChainsInfo.ProtocolsInfo[0].ChainId = "narwhal-1"
// allianceProtocolRes.UpdateChainsInfo.ChainsInfo.ProtocolsInfo[1].ChainId = "harpoon-4"
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, allianceProtocolRes)
})
r.GET("/alliance/rebalance", func(c *gin.Context) {
allianceRebalanceVals, err := allianceProvider.GetAllianceRedelegateReq(ctx)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, allianceRebalanceVals)
})
r.GET("/alliance/delegations", func(c *gin.Context) {
allianceDelegatios, err := allianceProvider.GetAllianceInitialDelegations(ctx)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, allianceDelegatios)
})
if os.Getenv("PRICE_SERVER_PORT") == "" {
os.Setenv("PORT", "8532") // use 8532 by default
} else {
os.Setenv("PORT", os.Getenv("PRICE_SERVER_PORT"))
}
err = r.Run()
if err != nil {
panic(err)
}
close(stopCh)
}