Skip to content

Commit

Permalink
Move binance clients to go-libs (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
unanoc authored Dec 10, 2021
1 parent 41a485d commit 67aacfe
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 112 deletions.
2 changes: 1 addition & 1 deletion configs/example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ app:

client_urls:
binance:
dex: https://dex.binance.org
explorer: https://explorer.binance.org
dex: https://dex-atlantic.binance.org/api

urls:
tw_assets_app: https://assets.trustwalletapp.com
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.17

require (
github.com/sirupsen/logrus v1.8.1
github.com/trustwallet/go-libs v0.2.19
github.com/trustwallet/go-primitives v0.0.16
github.com/trustwallet/go-libs v0.2.20
github.com/trustwallet/go-primitives v0.0.17
)

require (
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,10 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/trustwallet/go-libs v0.2.19 h1:GTdMWYGJpTiWy7XOitveeviQIUYazU4PVxnjUBruT3g=
github.com/trustwallet/go-libs v0.2.19/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc=
github.com/trustwallet/go-primitives v0.0.16-0.20211207135220-04b1926f0aa0 h1:Dd2L3iCptLdCQFt4bBH5wqrW50J7JqmEcP8aDHSZY0g=
github.com/trustwallet/go-primitives v0.0.16-0.20211207135220-04b1926f0aa0/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
github.com/trustwallet/go-primitives v0.0.16 h1:RoivfOFmMx8C4felrwWHuIWtWLm7Gd9Fj0mLIBZ8qEY=
github.com/trustwallet/go-primitives v0.0.16/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
github.com/trustwallet/go-libs v0.2.20 h1:pYstFNgsc7CVyVeYt5GHsMa0JNQHJVRvPQqMvXMpCtY=
github.com/trustwallet/go-libs v0.2.20/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc=
github.com/trustwallet/go-primitives v0.0.17 h1:1fBxZMKGCHdHtgdUzsqdFlD21+1GneIk/sxN6jxYBds=
github.com/trustwallet/go-primitives v0.0.17/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
34 changes: 0 additions & 34 deletions src/client/binance/dex/client.go

This file was deleted.

16 changes: 0 additions & 16 deletions src/client/binance/dex/model.go

This file was deleted.

26 changes: 0 additions & 26 deletions src/client/binance/explorer/client.go

This file was deleted.

15 changes: 0 additions & 15 deletions src/client/binance/explorer/model.go

This file was deleted.

2 changes: 1 addition & 1 deletion src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type (

ClientsURLs struct {
Binance struct {
Explorer string `mapstructure:"explorer"`
Dex string `mapstructure:"dex"`
Explorer string `mapstructure:"explorer"`
} `mapstructure:"binance"`
}

Expand Down
22 changes: 11 additions & 11 deletions src/core/updaters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/trustwallet/assets-go-libs/pkg"
"github.com/trustwallet/assets-go-libs/pkg/asset"
"github.com/trustwallet/assets-go-libs/pkg/validation/info"
"github.com/trustwallet/assets-go-libs/src/client/binance/dex"
"github.com/trustwallet/assets-go-libs/src/client/binance/explorer"
"github.com/trustwallet/assets-go-libs/src/config"
"github.com/trustwallet/go-libs/blockchain/binance"
"github.com/trustwallet/go-libs/blockchain/binance/explorer"
assetlib "github.com/trustwallet/go-primitives/asset"
"github.com/trustwallet/go-primitives/coin"
"github.com/trustwallet/go-primitives/numbers"
Expand All @@ -30,21 +30,21 @@ const (
)

func (s *Service) UpdateBinanceTokens() error {
explorerClient := explorer.NewClient(config.Default.ClientURLs.Binance.Explorer, nil)
explorerClient := explorer.InitClient(config.Default.ClientURLs.Binance.Explorer, nil)

bep2AssetList, err := explorerClient.GetBep2Assets(assetsPage, assetsRows)
bep2AssetList, err := explorerClient.FetchBep2Assets(assetsPage, assetsRows)
if err != nil {
return err
}

dexClient := dex.NewClient(config.Default.ClientURLs.Binance.Dex, nil)
dexClient := binance.InitClient(config.Default.ClientURLs.Binance.Dex, "", nil)

marketPairs, err := dexClient.GetMarketPairs(marketPairsLimit)
marketPairs, err := dexClient.FetchMarketPairs(marketPairsLimit)
if err != nil {
return err
}

tokensList, err := dexClient.GetTokensList(tokensListLimit)
tokensList, err := dexClient.FetchTokens(tokensListLimit)
if err != nil {
return err
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func createInfoJSON(chain coin.Coin, a explorer.Bep2Asset) error {
return pkg.CreateJSONFile(assetInfoPath, &assetInfo)
}

func createTokenListJSON(chain coin.Coin, marketPairs []dex.MarketPair, tokenList []dex.Token) error {
func createTokenListJSON(chain coin.Coin, marketPairs []binance.MarketPair, tokenList binance.Tokens) error {
tokens, err := generateTokenList(marketPairs, tokenList)
if err != nil {
return nil
Expand Down Expand Up @@ -168,7 +168,7 @@ func sortTokens(tokens []TokenItem) {
}
}

func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]TokenItem, error) {
func generateTokenList(marketPairs []binance.MarketPair, tokenList binance.Tokens) ([]TokenItem, error) {
if len(marketPairs) < 5 {
return nil, fmt.Errorf("no markets info is returned from Binance DEX: %d", len(marketPairs))
}
Expand All @@ -179,7 +179,7 @@ func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]T

pairsMap := make(map[string][]Pair)
pairsList := make(map[string]struct{})
tokensMap := make(map[string]dex.Token)
tokensMap := make(map[string]binance.Token)

for _, token := range tokenList {
tokensMap[token.Symbol] = token
Expand Down Expand Up @@ -225,7 +225,7 @@ func generateTokenList(marketPairs []dex.MarketPair, tokenList []dex.Token) ([]T
return tokenItems, nil
}

func getPair(marketPair dex.MarketPair) Pair {
func getPair(marketPair binance.MarketPair) Pair {
return Pair{
Base: getAssetIDSymbol(marketPair.BaseAssetSymbol, coin.Coins[coin.BINANCE].Symbol, coin.BINANCE),
LotSize: strconv.FormatInt(numbers.ToSatoshi(marketPair.LotSize), 10),
Expand Down

0 comments on commit 67aacfe

Please sign in to comment.