Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
c7e0ba4
Add COTI ERC20 (#346)
Iamdeadlyz Jan 23, 2021
b374fd8
add_ERC20_WISE (#349)
zachzwei Jan 23, 2021
4636567
Remove request limit (#345)
vikmeup Jan 24, 2021
53376f0
Fix unstable tickers_test.go (#350)
hewigovens Jan 25, 2021
802460f
add_BEP20_ETHb (#352)
zachzwei Jan 26, 2021
2eaab35
add_BEP20_HELMET (#353)
zachzwei Jan 26, 2021
8f7a6b8
add_BEP20_EGLD (#354)
zachzwei Jan 26, 2021
82894c6
add_BEP20_MirrorAssets (#355)
zachzwei Jan 26, 2021
3143417
Bump gorm.io/gorm from 1.20.11 to 1.20.12 (#357)
dependabot-preview[bot] Jan 28, 2021
25e63df
Bump gorm.io/driver/postgres from 1.0.6 to 1.0.7 (#356)
dependabot-preview[bot] Feb 1, 2021
8c175f7
add_BEP20_KEBAB (#361)
zachzwei Feb 1, 2021
353cc1f
Bump gorm.io/driver/postgres from 1.0.7 to 1.0.8 (#360)
dependabot-preview[bot] Feb 2, 2021
c35d2a5
Remove imroc/req (#359)
hewigovens Feb 3, 2021
62689ae
add_ERC20+BEP20_HGET (#363)
zachzwei Feb 3, 2021
b65095b
Consolidate usage of description into one field in coin info (#364)
vikmeup Feb 3, 2021
8f18d95
Bump github.com/trustwallet/golibs from 0.1.0 to 0.1.1 (#362)
dependabot-preview[bot] Feb 3, 2021
4ab82d6
Optimize codebase (#358)
madcake Feb 4, 2021
61fec65
Revert "Optimize codebase (#358)" (#365)
madcake Feb 4, 2021
d4ebd63
Add Dogecoin BEP20 pricing (#368)
Iamdeadlyz Feb 7, 2021
dfd081b
Bump github.com/alicebob/miniredis/v2 from 2.13.3 to 2.14.2 (#367)
dependabot-preview[bot] Feb 7, 2021
c737ca6
add_BEP20_SFP (#370)
zachzwei Feb 8, 2021
6eb3b9e
Add Elrond (ERC20) pricing (#371)
Iamdeadlyz Feb 9, 2021
97f110a
add_BEP20_YVS (#372)
zachzwei Feb 9, 2021
32bf337
Removed Elrond [ERD] (ERC20) (#373)
Iamdeadlyz Feb 11, 2021
2e611f8
Add AAVE (BEP2 and BEP20) pricing (#374)
Iamdeadlyz Feb 12, 2021
f252daf
Optimize codebase (#366)
madcake Feb 13, 2021
9fe9a88
add_BEP20_AUTO (#377)
zachzwei Feb 14, 2021
124adff
add_BEP20_Binance-Pegged (#379)
zachzwei Feb 17, 2021
ccac837
add_ERC20_CWS (#380)
zachzwei Feb 17, 2021
aa4b501
Remove binance dex (#375)
madcake Feb 17, 2021
7fa030a
Add BHC BEP20 pricing (#385)
Iamdeadlyz Feb 21, 2021
bd2618f
Add token Newscrypto (#387)
madcake Feb 23, 2021
d50255f
Clean codebase (#378)
madcake Feb 25, 2021
89b31ca
Revert "Clean codebase (#378)" (#392)
madcake Feb 25, 2021
4ba23dd
Add MATIC BEP2 pricing (#391)
Iamdeadlyz Feb 25, 2021
5436e52
Add SPAZ BEP20 pricing (#390)
Iamdeadlyz Feb 25, 2021
15991ac
Bump github.com/sirupsen/logrus from 1.7.0 to 1.8.0 (#383)
dependabot-preview[bot] Feb 25, 2021
abdbb29
Bump github.com/alicebob/miniredis/v2 from 2.14.2 to 2.14.3 (#384)
dependabot-preview[bot] Feb 25, 2021
55ec95f
Bump github.com/trustwallet/golibs from 0.1.1 to 0.1.5 (#386)
dependabot-preview[bot] Feb 25, 2021
b8307b0
add_BEP20_1INCH (#394)
zachzwei Feb 25, 2021
6a925cc
add_ERC20_UNIFI (#395)
zachzwei Feb 26, 2021
f077c0b
Add BEP: ETH-1C9 map pricing
vikmeup Feb 28, 2021
63b03b9
Add BEP: USDT-6D8 map pricing
vikmeup Feb 28, 2021
3a50420
Clean code tickers (#393)
madcake Mar 1, 2021
ae3ae0d
Fix default currency (#396)
madcake Mar 1, 2021
c41d0d0
Add DITTO (BEP20) pricing (#398)
Iamdeadlyz Mar 1, 2021
91c3318
add_BEP20_DODO (#399)
zachzwei Mar 1, 2021
5575182
add_BEP2_XRP+BKBT (#400)
zachzwei Mar 1, 2021
94ea339
Update DNA (ERC20) pricing (#401)
Iamdeadlyz Mar 2, 2021
06d702e
add_BEP20_RAMP (#402)
zachzwei Mar 3, 2021
8488705
add_BEP20_SUSHI (#403)
zachzwei Mar 4, 2021
4cbacf7
Add BEP2 (UNI)
vikmeup Mar 6, 2021
f265ed3
add_BEP2_AWC (#405)
zachzwei Mar 6, 2021
0bc8c64
Add Jetfuel Finance (FUEL) BEP20 pricing (#406)
Iamdeadlyz Mar 7, 2021
4fe5bc8
add_BEP2_SUSHI (#407)
zachzwei Mar 7, 2021
cb70d32
add_BEP2-BEP20_COCOS (#408)
zachzwei Mar 7, 2021
6d9cbdc
add_BEP2_SXP (#409)
zachzwei Mar 7, 2021
06329a5
Add LTO (ERC20) price mapping
vikmeup Mar 8, 2021
4e56b7f
Add Shadows (DOWS) ERC20 pricing (#410)
Iamdeadlyz Mar 9, 2021
324dd1e
add_ERC20_POLK (#411)
zachzwei Mar 9, 2021
847b9f5
Add Spartan Protocol Token (SPARTA) BEP20 pricing (#412)
Iamdeadlyz Mar 10, 2021
df3af6a
Add FCL (ERC20) price information
vikmeup Mar 11, 2021
ca2a120
Add Paid V2 (ERC20) coin pricing
vikmeup Mar 11, 2021
f81ea90
Add fiat rates endpoint (#416)
madcake Mar 11, 2021
95eca6b
edit_ERC20_PAID (#417)
zachzwei Mar 11, 2021
1fa2a2d
Change api route /fiat_rates => /v1/fiat_rates
vikmeup Mar 11, 2021
89ca4d6
Update Verasity (VRA) ERC20 pricing (#418)
Iamdeadlyz Mar 12, 2021
7572196
Add DOS Network (DOS) BEP2 and BEP20 pricing (#419)
Iamdeadlyz Mar 14, 2021
340ca3e
add_ERC20_IYF (#420)
zachzwei Mar 15, 2021
4c7794f
add_BEP2_IRIS (#421)
zachzwei Mar 15, 2021
0f20076
add_BEP2_missing_price_3/16 (#422)
zachzwei Mar 16, 2021
e2b877b
add_ERC20_BEP20_missing (#423)
zachzwei Mar 16, 2021
f283cb6
Remove bad code (#424)
madcake Mar 16, 2021
261df02
Add BEP(DEFI-FA5) mapping
vikmeup Mar 17, 2021
426c0d8
Add CAKE-435 BEP2 pricing (#426)
Iamdeadlyz Mar 18, 2021
7f060e3
Add BOLT-4C6 BEP2 pricing (#427)
Iamdeadlyz Mar 18, 2021
61e52f3
add_BEP20_TFF
zachzwei Mar 19, 2021
f943245
Update Tellor (TRB) ERC20 pricing (#428)
Iamdeadlyz Mar 20, 2021
b813f2a
add_BEP2_BTTB
zachzwei Mar 20, 2021
9e3c779
add_BEP20_KGO
zachzwei Mar 21, 2021
26faeb6
add_BEP20_WATCH
zachzwei Mar 21, 2021
6b4b765
Update Bitcoin Standard Hashrate Token (BTCST) BEP20 pricing (#429)
Iamdeadlyz Mar 21, 2021
239bea9
Add Ecomi (OMI) GO20 pricing (#430)
Iamdeadlyz Mar 22, 2021
6c39118
add_BEP20_SAFEMOON
zachzwei Mar 23, 2021
a9a276e
add_ERC20_PKF
zachzwei Mar 23, 2021
9b605e7
[Rates] Store only fixer rates + some fixed crypto rates #191 (#431)
vikmeup Mar 24, 2021
b85980e
Add MATIC (BEP20) (#432)
Iamdeadlyz Mar 24, 2021
4f0124b
Remove database requests (#425)
madcake Mar 25, 2021
7d69408
Revert "Remove database requests (#425)" (#433)
madcake Mar 25, 2021
98b8162
add_BEP2_MVL
zachzwei Mar 25, 2021
df75cf6
add_BEP20_LINA
zachzwei Mar 26, 2021
93a1114
Add support for CoinGecko Pro API (#434)
vikmeup Mar 26, 2021
23d2f03
Add Safemars (SAFEMARS) BEP20 (#437)
Iamdeadlyz Apr 1, 2021
4ccb23d
Add MITX BEP2 pricing (#438)
Iamdeadlyz Apr 3, 2021
c704c11
Add Red Pulse Phoenix Binance (PHB-2DF) BEP2 (#441)
Iamdeadlyz Apr 11, 2021
1349f65
add_BEP20_YETH
zachzwei Apr 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/watchmarket.exe
/bin/*
*-bin
__debug_bin

### APP ###
*.csv
Expand Down
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ func SetupTickersAPI(engine *gin.Engine, tickers controllers.TickersController,

func SetupRatesAPI(engine *gin.Engine, rates controllers.RatesController) {
engine.GET("/v1/market/rate", endpoint.GetRate(rates))
engine.GET("/v1/fiat_rates", endpoint.GetFiatRates(rates))
}
26 changes: 11 additions & 15 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func TestSetupTickersAPI(t *testing.T) {
Price: watchmarket.Price{
Change24h: 2,
Currency: "",
Provider: "coinmarketcap",
Provider: watchmarket.CoinMarketCap,
Value: 1,
},
},
},
}
wantedTickersV2 := controllers.TickerResponseV2{
Currency: "USD",
Tickers: []controllers.TickerPrice{{Change24h: 2, Provider: "coinmarketcap", Price: 1, ID: "c60_ta"}},
Tickers: []controllers.TickerPrice{{Change24h: 2, Provider: watchmarket.CoinMarketCap, Price: 1, ID: "c60_ta"}},
}

SetupTickersAPI(e, getTickersMock(wantedTickers, wantedTickersV2, nil), time.Minute)
Expand All @@ -72,7 +72,7 @@ func TestSetupTickersAPI(t *testing.T) {

cr1 := controllers.TickerRequest{
Currency: "USD",
Assets: []controllers.Coin{{Coin: 60, TokenId: "a"}},
Assets: []controllers.Asset{{CoinId: 60, TokenId: "a"}},
}

rawcr1, err := json.Marshal(&cr1)
Expand All @@ -87,7 +87,7 @@ func TestSetupTickersAPI(t *testing.T) {
assert.Equal(t, "a", givenV1Resp.Tickers[0].TokenId)
assert.Equal(t, float64(1), givenV1Resp.Tickers[0].Price.Value)
assert.Equal(t, float64(2), givenV1Resp.Tickers[0].Price.Change24h)
assert.Equal(t, "coinmarketcap", givenV1Resp.Tickers[0].Price.Provider)
assert.Equal(t, watchmarket.CoinMarketCap, givenV1Resp.Tickers[0].Price.Provider)

givenV2Resp := controllers.TickerResponseV2{}

Expand All @@ -107,7 +107,7 @@ func TestSetupTickersAPI(t *testing.T) {
assert.Equal(t, "c60_ta", givenV2Resp.Tickers[0].ID)
assert.Equal(t, float64(1), givenV2Resp.Tickers[0].Price)
assert.Equal(t, float64(2), givenV2Resp.Tickers[0].Change24h)
assert.Equal(t, "coinmarketcap", givenV2Resp.Tickers[0].Provider)
assert.Equal(t, watchmarket.CoinMarketCap, givenV2Resp.Tickers[0].Provider)

resp3, err := http.Get(server.URL + "/v2/market/ticker/c60_ta")
assert.Nil(t, err)
Expand All @@ -123,7 +123,7 @@ func TestSetupTickersAPI(t *testing.T) {
assert.Equal(t, "c60_ta", givenV2Resp2.Tickers[0].ID)
assert.Equal(t, float64(1), givenV2Resp2.Tickers[0].Price)
assert.Equal(t, float64(2), givenV2Resp2.Tickers[0].Change24h)
assert.Equal(t, "coinmarketcap", givenV2Resp2.Tickers[0].Provider)
assert.Equal(t, watchmarket.CoinMarketCap, givenV2Resp2.Tickers[0].Provider)

resp4, err := http.Get(server.URL + "/v2/market/tickers/c60_ta")
assert.Nil(t, err)
Expand All @@ -139,15 +139,15 @@ func TestSetupTickersAPI(t *testing.T) {
assert.Equal(t, "c60_ta", givenV2Resp3.Tickers[0].ID)
assert.Equal(t, float64(1), givenV2Resp3.Tickers[0].Price)
assert.Equal(t, float64(2), givenV2Resp3.Tickers[0].Change24h)
assert.Equal(t, "coinmarketcap", givenV2Resp3.Tickers[0].Provider)
assert.Equal(t, watchmarket.CoinMarketCap, givenV2Resp3.Tickers[0].Provider)
}

func TestSetupChartsAPI(t *testing.T) {
e := setupEngine()
server := httptest.NewServer(e)
defer server.Close()
wantedCharts := watchmarket.Chart{
Provider: "coinmarketcap",
Provider: watchmarket.CoinMarketCap,
Prices: []watchmarket.ChartPrice{{Price: 10, Date: 10}},
}
SetupChartsAPI(e, getChartsMock(wantedCharts, nil), time.Minute)
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestSetupInfoAPI(t *testing.T) {
server := httptest.NewServer(e)
defer server.Close()
wantedInfo := controllers.InfoResponse{
Provider: "coinmarketcap",
Provider: watchmarket.CoinMarketCap,
Info: &watchmarket.Info{
Name: "a",
Website: "b",
Expand Down Expand Up @@ -309,12 +309,8 @@ func (c infoControllerMock) HandleInfoRequest(dr controllers.DetailsRequest) (co
return c.wantedInfo, c.wantedError
}

func (c tickersControllerMock) HandleTickersRequestV2(tr controllers.TickerRequestV2) (controllers.TickerResponseV2, error) {
return c.wantedTickersV2, c.wantedError
}

func (c tickersControllerMock) HandleTickersRequest(tr controllers.TickerRequest) (controllers.TickerResponse, error) {
return c.wantedTickersV1, c.wantedError
func (c tickersControllerMock) HandleTickersRequest(tr controllers.TickerRequest) (watchmarket.Tickers, error) {
return c.wantedTickersV1.Tickers, c.wantedError
}

func setupEngine() *gin.Engine {
Expand Down
44 changes: 28 additions & 16 deletions api/endpoint/charts.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package endpoint

import (
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"github.com/trustwallet/golibs/asset"
"github.com/trustwallet/watchmarket/pkg/watchmarket"
"github.com/trustwallet/golibs/coin"
"github.com/trustwallet/watchmarket/services/controllers"
"net/http"
)

// @Summary Get charts data for a specific coin
Expand All @@ -25,12 +23,20 @@ import (
// @Router /v1/market/charts [get]
func GetChartsHandler(controller controllers.ChartsController) func(c *gin.Context) {
return func(c *gin.Context) {
coinId, err := controllers.GetCoinId(c.Query("coin"))
if err != nil {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}
request := controllers.ChartRequest{
CoinQuery: c.Query("coin"),
Token: c.Query("token"),
Currency: c.DefaultQuery("currency", watchmarket.DefaultCurrency),
TimeStartRaw: c.Query("time_start"),
MaxItems: c.Query("max_items"),
Asset: controllers.Asset{
CoinId: coinId,
TokenId: c.Query("token"),
},
Currency: controllers.GetCurrency(c.Query("currency")),
TimeStart: controllers.GetTimeStart(c.Query("time_start")),
MaxItems: controllers.GetMaxItems(c.Query("max_items")),
}

response, err := controller.HandleChartsRequest(request)
Expand Down Expand Up @@ -58,19 +64,25 @@ func GetChartsHandler(controller controllers.ChartsController) func(c *gin.Conte
// @Router /v2/market/charts/{id} [get]
func GetChartsHandlerV2(controller controllers.ChartsController) func(c *gin.Context) {
return func(c *gin.Context) {
coin, token, err := asset.ParseID(c.Param("id"))
coinId, tokenId, err := asset.ParseID(c.Param("id"))
if err != nil {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}

if _, ok := coin.Coins[coinId]; !ok {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}
request := controllers.ChartRequest{
CoinQuery: strconv.Itoa(int(coin)),
Token: token,
Currency: c.DefaultQuery("currency", watchmarket.DefaultCurrency),
TimeStartRaw: c.Query("time_start"),
MaxItems: c.Query("max_items"),
Asset: controllers.Asset{
CoinId: coinId,
TokenId: tokenId,
},
Currency: controllers.GetCurrency(c.Query("currency")),
TimeStart: controllers.GetTimeStart(c.Query("time_start")),
MaxItems: controllers.GetMaxItems(c.Query("max_items")),
}

response, err := controller.HandleChartsRequest(request)
Expand Down
35 changes: 24 additions & 11 deletions api/endpoint/info.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package endpoint

import (
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"github.com/trustwallet/golibs/asset"
"github.com/trustwallet/golibs/coin"
"github.com/trustwallet/watchmarket/pkg/watchmarket"
"github.com/trustwallet/watchmarket/services/controllers"
"net/http"
)

// @Summary Get charts coin assets data for a specific coin
Expand All @@ -23,10 +22,18 @@ import (
// @Router /v1/market/info [get]
func GetCoinInfoHandler(controller controllers.InfoController) func(c *gin.Context) {
return func(c *gin.Context) {
coinId, err := controllers.GetCoinId(c.Query("coin"))
if err != nil {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}
request := controllers.DetailsRequest{
CoinQuery: c.Query("coin"),
Token: c.Query("token"),
Currency: c.DefaultQuery("currency", watchmarket.DefaultCurrency),
Asset: controllers.Asset{
CoinId: coinId,
TokenId: c.Query("token"),
},
Currency: controllers.GetCurrency(c.Query("currency")),
}
response, err := controller.HandleInfoRequest(request)
if err != nil {
Expand All @@ -51,17 +58,23 @@ func GetCoinInfoHandler(controller controllers.InfoController) func(c *gin.Conte
// @Router /v2/market/info/{id} [get]
func GetCoinInfoHandlerV2(controller controllers.InfoController) func(c *gin.Context) {
return func(c *gin.Context) {
coin, token, err := asset.ParseID(c.Param("id"))
coinId, token, err := asset.ParseID(c.Param("id"))
if err != nil {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}

if _, ok := coin.Coins[coinId]; !ok {
code, response := createErrorResponseAndStatusCode(err)
c.AbortWithStatusJSON(code, response)
return
}
request := controllers.DetailsRequest{
CoinQuery: strconv.Itoa(int(coin)),
Token: token,
Currency: c.DefaultQuery("currency", watchmarket.DefaultCurrency),
Asset: controllers.Asset{
CoinId: coinId,
TokenId: token,
},
Currency: c.DefaultQuery("currency", watchmarket.DefaultCurrency),
}
response, err := controller.HandleInfoRequest(request)
if err != nil {
Expand Down
21 changes: 20 additions & 1 deletion api/endpoint/rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Param amount query string false "Amount" default(100)
// @Success 200 {object} controllers.RateResponse
// @Router /v1/market/rate [get]
func GetRate(controller controllers.RatesController) func(c *gin.Context) {
func GetRate(controller controllers.RatesController) func(context *gin.Context) {
return func(c *gin.Context) {
from := c.DefaultQuery("from", watchmarket.DefaultCurrency)
to := c.Query("to")
Expand All @@ -42,3 +42,22 @@ func GetRate(controller controllers.RatesController) func(c *gin.Context) {
c.JSON(http.StatusOK, response)
}
}

// @Summary Get Fiat Rates
// @Description Get Fiat Rates
// @Accept json
// @Produce json
// @Tags Rates
// @Success 200 {object} controllers.FiatRates
// @Router /v1/fiat_rates [get]
func GetFiatRates(controller controllers.RatesController) func(context *gin.Context) {
return func(context *gin.Context) {
rates, err := controller.GetFiatRates()
if err != nil {
code, response := createErrorResponseAndStatusCode(err)
context.AbortWithStatusJSON(code, response)
return
}
context.JSON(http.StatusOK, rates)
}
}
Loading