Explorar o código

分段拉取 r0, r1

skyfffire %!s(int64=2) %!d(string=hai) anos
pai
achega
194156028d
Modificáronse 4 ficheiros con 45 adicións e 23 borrados
  1. 39 0
      arbitrage/api/blockchain_api.go
  2. 3 3
      arbitrage/config.go
  3. 2 1
      arbitrage/history.go
  4. 1 19
      arbitrage/lp_utils.go

+ 39 - 0
arbitrage/api/blockchain_api.go

@@ -5,6 +5,7 @@ import (
 	"crypto/md5"
 	"encoding/json"
 	"fmt"
+	"github.com/ethereum/go-ethereum/log"
 	"io"
 	"net/http"
 	"os"
@@ -112,3 +113,41 @@ func (a *JavaApi) GetV2LpListFromLocal(path string) []V2Lp {
 
 	return lpList
 }
+
+func (a *JavaApi) GetAllV2LpList(path string) []V2Lp {
+	// 本地获取
+	lpList := a.GetV2LpListFromLocal(path)
+
+	if len(lpList) != 0 {
+		log.Warn(fmt.Sprintf("本地获取lp成功,总量:%+v.", len(lpList)))
+		return lpList
+	}
+
+	// 不成功就远程获取
+	rst, _ := a.V2LpCountByChainId(V2LpCountByChainIdRequest{
+		ChainId: 1116,
+		AuthObj: GenerateAuth(),
+	})
+
+	log.Warn(fmt.Sprintf("远程获取lp,总量:%+v.", rst.Data))
+
+	pageNumber := 1
+	pageSize := rst.Data
+
+	finalRst, err := a.V2LpListByChainIdAndPaginate(V2LpListByChainIdAndPaginateRequest{
+		ChainId:    1116,
+		PageNumber: uint64(pageNumber),
+		PageSize:   uint64(pageSize),
+		AuthObj:    GenerateAuth(),
+	})
+
+	// 将当前页的lp放入lpList中
+	if err != nil {
+		log.Warn(err.Error())
+	} else {
+		lpList = finalRst.Data
+		log.Warn(fmt.Sprintf("远程获取lp, 总量%+v已获取。", len(lpList)))
+	}
+
+	return lpList
+}

+ 3 - 3
arbitrage/config.go

@@ -10,9 +10,6 @@ var V2ToolsContract = Contract{
 
 /* lp 相关 */
 
-// MaxLpLength 从数据库取出的最大lp数量
-var MaxLpLength = uint64(5000)
-
 // MaxLevel 最大path等级
 var MaxLevel = int64(3)
 
@@ -20,3 +17,6 @@ var MaxLevel = int64(3)
 
 // LogPath 日志目录
 var LogPath = "J:\\temp\\history.log"
+
+// V2LpPath Lp目录
+var V2LpPath = "J:\\temp\\v2-lp-list.json"

+ 2 - 1
arbitrage/history.go

@@ -65,7 +65,8 @@ func RegisterHistoryArbitrage(stack *node.Node, ctx *cli.Context, apiBackend eth
 	}
 
 	// 设置日志输出目录
-	SetLogFile(LogFile)
+	//SetLogFile(LogFile)
+	SetLogFile(os.Stdout)
 
 	h.Register()
 }

+ 1 - 19
arbitrage/lp_utils.go

@@ -3,7 +3,6 @@ package arbitrage
 import (
 	"github.com/ethereum/go-ethereum/arbitrage/api"
 	"github.com/ethereum/go-ethereum/log"
-	"github.com/ethereum/go-ethereum/params"
 	"github.com/shopspring/decimal"
 )
 
@@ -280,24 +279,7 @@ func ParseLpListToLpHashList(lpList []api.V2Lp) []string {
 }
 
 func (h *HistoryArbitrage) GetLpList() []api.V2Lp {
-	rst, err := h.javaApi.V2LpListByChainIdAndPaginate(api.V2LpListByChainIdAndPaginateRequest{
-		ChainId:    params.CoreChainConfig.ChainID.Uint64(),
-		PageNumber: 1,
-		PageSize:   MaxLpLength,
-		AuthObj:    api.GenerateAuth(),
-	})
-
-	if err != nil {
-		HistoryError("Get lp list error.", err.Error())
-		return nil
-	}
-
-	if !rst.State {
-		HistoryError("Get lp list java error.", err.Error())
-		return nil
-	}
-
-	return rst.Data
+	return h.javaApi.GetAllV2LpList(V2LpPath)
 }
 
 func PutR0R1ToLpList(lpList []api.V2Lp, balanceMapping map[string][2]decimal.Decimal) {