From b4025d59b98899819234c0b117608cac3a0420ff Mon Sep 17 00:00:00 2001 From: robcxyz Date: Wed, 1 Nov 2023 17:43:57 +0800 Subject: [PATCH] fix: add supplies endpoint vs stats --- src/api/api.go | 1 + src/api/docs/docs.go | 109 ++++++++++++++++++++++++++++++++++++++ src/api/docs/swagger.json | 109 ++++++++++++++++++++++++++++++++++++++ src/api/docs/swagger.yaml | 73 +++++++++++++++++++++++++ src/api/rest/supplies.go | 81 ++++++++++++++++++++++++++++ 5 files changed, 373 insertions(+) create mode 100644 src/api/rest/supplies.go diff --git a/src/api/api.go b/src/api/api.go index 94a4d13..1155222 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -62,6 +62,7 @@ func Start() *fiber.App { rest.LogsAddHandlers(app) rest.AddressesAddHandlers(app) rest.StatsAddHandlers(app) + rest.SuppliesAddHandlers(app) ws.WebsocketsAddHandlers(app) go app.Listen(":" + config.Config.APIPort) diff --git a/src/api/docs/docs.go b/src/api/docs/docs.go index 95f940d..3c33d21 100644 --- a/src/api/docs/docs.go +++ b/src/api/docs/docs.go @@ -616,6 +616,115 @@ const docTemplate_swagger = `{ } } }, + "/api/v1/supplies": { + "get": { + "description": "get json with a summary of stats", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/circulating-supply": { + "get": { + "description": "get circulating supply (total supply - burn wallet balance)", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/market-cap": { + "get": { + "description": "get mkt cap (Coin Gecko Price * circulating supply)", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/total-supply": { + "get": { + "description": "get total supply", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/transactions": { "get": { "description": "get historical transactions", diff --git a/src/api/docs/swagger.json b/src/api/docs/swagger.json index 970ca66..f06a36c 100644 --- a/src/api/docs/swagger.json +++ b/src/api/docs/swagger.json @@ -607,6 +607,115 @@ } } }, + "/api/v1/supplies": { + "get": { + "description": "get json with a summary of stats", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/circulating-supply": { + "get": { + "description": "get circulating supply (total supply - burn wallet balance)", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/market-cap": { + "get": { + "description": "get mkt cap (Coin Gecko Price * circulating supply)", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/api/v1/supplies/total-supply": { + "get": { + "description": "get total supply", + "consumes": [ + "*/*" + ], + "tags": [ + "Supplies" + ], + "summary": "Get Supplies", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "number" + } + }, + "422": { + "description": "Unprocessable Entity", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/api/v1/transactions": { "get": { "description": "get historical transactions", diff --git a/src/api/docs/swagger.yaml b/src/api/docs/swagger.yaml index 343e045..5c6d388 100644 --- a/src/api/docs/swagger.yaml +++ b/src/api/docs/swagger.yaml @@ -733,6 +733,79 @@ paths: summary: Get Stats tags: - Stats + /api/v1/supplies: + get: + consumes: + - '*/*' + description: get json with a summary of stats + responses: + "200": + description: OK + schema: + additionalProperties: true + type: object + "422": + description: Unprocessable Entity + schema: + additionalProperties: true + type: object + summary: Get Supplies + tags: + - Supplies + /api/v1/supplies/circulating-supply: + get: + consumes: + - '*/*' + description: get circulating supply (total supply - burn wallet balance) + responses: + "200": + description: OK + schema: + type: number + "422": + description: Unprocessable Entity + schema: + additionalProperties: true + type: object + summary: Get Supplies + tags: + - Supplies + /api/v1/supplies/market-cap: + get: + consumes: + - '*/*' + description: get mkt cap (Coin Gecko Price * circulating supply) + responses: + "200": + description: OK + schema: + type: number + "422": + description: Unprocessable Entity + schema: + additionalProperties: true + type: object + summary: Get Supplies + tags: + - Supplies + /api/v1/supplies/total-supply: + get: + consumes: + - '*/*' + description: get total supply + responses: + "200": + description: OK + schema: + type: number + "422": + description: Unprocessable Entity + schema: + additionalProperties: true + type: object + summary: Get Supplies + tags: + - Supplies /api/v1/transactions: get: consumes: diff --git a/src/api/rest/supplies.go b/src/api/rest/supplies.go new file mode 100644 index 0000000..b383413 --- /dev/null +++ b/src/api/rest/supplies.go @@ -0,0 +1,81 @@ +package rest + +import ( + "encoding/json" + "github.com/gofiber/fiber/v2" + "github.com/sudoblockio/icon-go-api/config" + "strconv" +) + +func SuppliesAddHandlers(app *fiber.App) { + prefix := config.Config.RestPrefix + "/supplies" + + app.Get(prefix+"/", handlerGetSupplies) + app.Get(prefix+"/circulating-supply", handlerGetSuppliesCirculatingSupply) + app.Get(prefix+"/total-supply", handlerGetSuppliesTotalSupply) + app.Get(prefix+"/market-cap", handlerGetSuppliesMarketCap) +} + +// Supplies +// @Summary Get Supplies +// @Description get json with a summary of stats +// @Tags Supplies +// @BasePath /api/v1 +// @Accept */* +// @Router /api/v1/supplies [get] +// @Success 200 {object} map[string]interface{} +// @Failure 422 {object} map[string]interface{} +func handlerGetSupplies(c *fiber.Ctx) error { + UpdateCirculatingSupply() + UpdateMarketCap() + + stats := map[string]interface{}{ + "circulating-supply": CirculatingSupply, + "market-cap": MarketCap, + } + body, _ := json.Marshal(stats) + + return c.SendString(string(body)) +} + +// Circulating Supply +// @Summary Get Supplies +// @Description get circulating supply (total supply - burn wallet balance) +// @Tags Supplies +// @BasePath /api/v1 +// @Accept */* +// @Router /api/v1/supplies/circulating-supply [get] +// @Success 200 {object} float64 +// @Failure 422 {object} map[string]interface{} +func handlerGetSuppliesCirculatingSupply(c *fiber.Ctx) error { + UpdateCirculatingSupply() + return c.SendString(strconv.FormatFloat(CirculatingSupply, 'f', -1, 64)) +} + +// Total Supply +// @Summary Get Supplies +// @Description get total supply +// @Tags Supplies +// @BasePath /api/v1 +// @Accept */* +// @Router /api/v1/supplies/total-supply [get] +// @Success 200 {object} float64 +// @Failure 422 {object} map[string]interface{} +func handlerGetSuppliesTotalSupply(c *fiber.Ctx) error { + UpdateCirculatingSupply() + return c.SendString(strconv.FormatFloat(TotalSupply, 'f', -1, 64)) +} + +// Market Cap +// @Summary Get Supplies +// @Description get mkt cap (Coin Gecko Price * circulating supply) +// @Tags Supplies +// @BasePath /api/v1 +// @Accept */* +// @Router /api/v1/supplies/market-cap [get] +// @Success 200 {object} float64 +// @Failure 422 {object} map[string]interface{} +func handlerGetSuppliesMarketCap(c *fiber.Ctx) error { + UpdateMarketCap() + return c.SendString(strconv.FormatFloat(MarketCap, 'f', -1, 64)) +}