Browse Source

[dev]token list v2

Zhangzhenhua 2 weeks ago
parent
commit
91b97302ff
3 changed files with 49 additions and 23 deletions
  1. 2 1
      .env
  2. 23 22
      internal/consts/consts.go
  3. 24 0
      internal/library/birdeye/token/token.go

+ 2 - 1
.env

@@ -1,2 +1,3 @@
 BIRD_EYE_API_KEY = "b738f9a666c843a4a658211b523cb690"
-DEFI_URL = "https://public-api.birdeye.so/defi/"
+DEFI_URL = "https://public-api.birdeye.so/defi/"
+TOKEN_LIST_V2_URL = "https://public-api.birdeye.so/defi/v2/tokens/all"

+ 23 - 22
internal/consts/consts.go

@@ -4,26 +4,27 @@ const (
 	GET  string = "GET"
 	POST string = "POST"
 
-	NET_WORKS        string = "networks"
-	PRICE            string = "price"
-	MULTIPLE_PRICE   string = "multi_price"
-	QUESTION_MARK    string = "?"
-	X_API_KEY        string = "X-API-KEY"
-	DEFI_URL         string = "DEFI_URL"
-	TOKEN_URL        string = "DEFI_URL"
-	BIRD_EYE_API_KEY string = "BIRD_EYE_API_KEY"
-	CheckLiquidity   string = "check_liquidity"
-	IncludeLiquidity string = "include_liquidity"
-	ADDRESS          string = "address"
-	ACCEPT           string = "accept"
-	X_CHAIN          string = "x_chain"
-	APPLICATION_JSON string = "application/json"
-	LIST_ADDRESS     string = "list_address"
-	COMMAS           string = ","
-	SORT_BY          string = "sort_by"
-	SORT_TYPE        string = "sort_type"
-	OFFSET           string = "offset"
-	LIMIT            string = "limit"
-	MIN_LIQUIDITY    string = "min_liquidity"
-	TOKEN_LIST       string = "tokenlist"
+	NET_WORKS         string = "networks"
+	PRICE             string = "price"
+	MULTIPLE_PRICE    string = "multi_price"
+	QUESTION_MARK     string = "?"
+	X_API_KEY         string = "X-API-KEY"
+	DEFI_URL          string = "DEFI_URL"
+	TOKEN_URL         string = "DEFI_URL"
+	TOKEN_LIST_V2_URL string = "TOKEN_LIST_V2_URL"
+	BIRD_EYE_API_KEY  string = "BIRD_EYE_API_KEY"
+	CheckLiquidity    string = "check_liquidity"
+	IncludeLiquidity  string = "include_liquidity"
+	ADDRESS           string = "address"
+	ACCEPT            string = "accept"
+	X_CHAIN           string = "x_chain"
+	APPLICATION_JSON  string = "application/json"
+	LIST_ADDRESS      string = "list_address"
+	COMMAS            string = ","
+	SORT_BY           string = "sort_by"
+	SORT_TYPE         string = "sort_type"
+	OFFSET            string = "offset"
+	LIMIT             string = "limit"
+	MIN_LIQUIDITY     string = "min_liquidity"
+	TOKEN_LIST        string = "tokenlist"
 )

+ 24 - 0
internal/library/birdeye/token/token.go

@@ -54,3 +54,27 @@ func (t *Token) GetListV1(chain_name string, sort_by string, sort_type string, o
 	}
 	return res, nil
 }
+
+func (t *Token) GetListV2(chain_name string) (*token.ListRes, error) {
+	//构建基本请求连接
+	baseURL := os.Getenv(consts.TOKEN_LIST_V2_URL)
+
+	apiReq, err := http.NewRequest(consts.POST, baseURL, nil)
+	if err != nil {
+		return nil, err
+	}
+	//构建请求头
+	apiReq = birdeye.MakeHeader(apiReq, chain_name)
+
+	body, err := birdeye.SendRequest(apiReq)
+	if err != nil {
+		return nil, err
+	}
+	//处理返回数据
+	var res *token.ListRes
+	err = json.Unmarshal([]byte(body), &res)
+	if err != nil {
+		return nil, err
+	}
+	return res, nil
+}