bbgo_origin/pkg/bbgo/server.go

79 lines
2.0 KiB
Go
Raw Normal View History

2021-01-22 16:50:23 +00:00
package bbgo
import (
"context"
"fmt"
"net/http"
2021-01-22 16:50:23 +00:00
"github.com/gin-gonic/gin"
)
func RunServer(ctx context.Context, userConfig *Config, environ *Environment) error {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "pong"})
2021-01-22 16:50:23 +00:00
})
r.GET("/sessions", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"sessions": userConfig.Sessions})
})
r.GET("/sessions/:session", func(c *gin.Context) {
sessionName := c.Param("session")
session, ok := environ.Session(sessionName)
if !ok {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("session %s not found", sessionName)})
return
}
c.JSON(http.StatusOK, gin.H{"session": session})
2021-01-22 16:50:23 +00:00
})
r.GET("/sessions/:session/trades", func(c *gin.Context) {
sessionName := c.Param("session")
session, ok := environ.Session(sessionName)
if !ok {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("session %s not found", sessionName)})
return
}
c.JSON(http.StatusOK, gin.H{"trades": session.Trades})
2021-01-22 16:50:23 +00:00
})
r.GET("/sessions/:session/open-orders", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"orders": []string{}})
2021-01-22 16:50:23 +00:00
})
r.GET("/sessions/:session/closed-orders", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/loaded-symbols", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/pnl", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/market/:symbol/closed-orders", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/market/:symbol/open-orders", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/market/:symbol/trades", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
r.GET("/sessions/:session/market/:symbol/pnl", func(c *gin.Context) {
c.JSON(200, gin.H{"message": "pong"})
})
return r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}