Skip to content

Commit

Permalink
get multiple data feed by symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed Jul 15, 2024
1 parent 04ecbbf commit 49fc55b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions node/pkg/dal/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,34 @@ func getLatestFeed(c *fiber.Ctx) error {

return c.JSON(*result)
}

func getLatestMultipleFeeds(c *fiber.Ctx) error {
symbols := c.Params("symbols")

if symbols == "" {
return errors.New("invalid symbol: empty symbol")
}

symbols_slice := strings.Split(symbols, ",")
result_slice := make([]*dalcommon.OutgoingSubmissionData, len(symbols_slice))

for _, symbol := range symbols_slice {
if !strings.Contains(symbol, "-") {
return errors.New("symbol should be in {BASE}-{QUOTE} format")
}

if !strings.Contains(symbol, "test") {
symbol = strings.ToUpper(symbol)
}

result, err := ApiController.Collector.GetLatestData(symbol)

if err != nil {
return err
}

result_slice = append(result_slice, result)
}

return c.JSON(result_slice)
}
1 change: 1 addition & 0 deletions node/pkg/dal/api/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ func Routes(router fiber.Router) {
api.Get("/symbols", getSymbols)
api.Get("/latest-data-feeds/all", getLatestFeeds)
api.Get("/latest-data-feeds/:symbol", getLatestFeed)
api.Get("/latest-multiple-data-feeds/:symbols", getLatestMultipleFeeds)
api.Get("/ws", websocket.New(ApiController.handleWebsocket))
}

0 comments on commit 49fc55b

Please sign in to comment.