|
@@ -6,6 +6,7 @@ import (
|
|
|
"net/url"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
"birdcall/internal/consts"
|
|
|
"birdcall/internal/library/birdeye"
|
|
@@ -13,10 +14,10 @@ import (
|
|
|
)
|
|
|
|
|
|
type Defi struct {
|
|
|
- Address string ` json:"address" dc:"代币地址"`
|
|
|
- Chain string ` json:"chain" dc:"链名"`
|
|
|
- CheckLiquidity float64 ` json:"check_liquidity" dc:"流动性验证"`
|
|
|
- IncludeLiquidity bool ` json:"include_liquidity" dc:"是否返回流动数据" `
|
|
|
+ Address []string ` json:"address" dc:"代币地址"`
|
|
|
+ Chain string ` json:"chain" dc:"链名"`
|
|
|
+ CheckLiquidity float64 ` json:"check_liquidity" dc:"流动性验证"`
|
|
|
+ IncludeLiquidity bool ` json:"include_liquidity" dc:"是否返回流动数据" `
|
|
|
}
|
|
|
|
|
|
func (d *Defi) Support() (*birdeye.CommonRes, error) {
|
|
@@ -52,7 +53,7 @@ func (d *Defi) Price() (*birdeye.CommonRes, error) {
|
|
|
params := url.Values{}
|
|
|
params.Add(consts.CheckLiquidity, strconv.FormatFloat(d.CheckLiquidity, 'f', 2, 64))
|
|
|
params.Add(consts.IncludeLiquidity, strconv.FormatBool(d.IncludeLiquidity))
|
|
|
- params.Add(consts.ADDRESS, d.Address)
|
|
|
+ params.Add(consts.ADDRESS, d.Address[0])
|
|
|
fullURL := baseURL + consts.PRICE + consts.QUESTION_MARK + params.Encode()
|
|
|
|
|
|
apiReq, err := http.NewRequest(consts.GET, fullURL, nil)
|
|
@@ -78,3 +79,37 @@ func (d *Defi) Price() (*birdeye.CommonRes, error) {
|
|
|
}
|
|
|
return commonRes, nil
|
|
|
}
|
|
|
+
|
|
|
+func (d *Defi) MultiplePrice() (*birdeye.CommonRes, error) {
|
|
|
+ //构建基本请求连接
|
|
|
+ baseURL := os.Getenv(consts.DEFI_URL)
|
|
|
+ params := url.Values{}
|
|
|
+ params.Add(consts.CheckLiquidity, strconv.FormatFloat(d.CheckLiquidity, 'f', 2, 64))
|
|
|
+ params.Add(consts.IncludeLiquidity, strconv.FormatBool(d.IncludeLiquidity))
|
|
|
+ addresses := strings.Join(d.Address, consts.COMMAS)
|
|
|
+ params.Add(consts.LIST_ADDRESS, addresses)
|
|
|
+ fullURL := baseURL + consts.MULTIPLE_PRICE + consts.QUESTION_MARK + params.Encode()
|
|
|
+
|
|
|
+ apiReq, err := http.NewRequest(consts.GET, fullURL, nil)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ //构建请求头
|
|
|
+ apiReq = birdeye.MakeHeader(apiReq, d.Chain)
|
|
|
+
|
|
|
+ //发送请求
|
|
|
+ apiRes, err := http.DefaultClient.Do(apiReq)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理结果
|
|
|
+ body, _ := io.ReadAll(apiRes.Body)
|
|
|
+ var commonRes *birdeye.CommonRes
|
|
|
+ err = json.Unmarshal(body, &commonRes)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return commonRes, nil
|
|
|
+}
|