change modules
This commit is contained in:
		
							parent
							
								
									7297621f3d
								
							
						
					
					
						commit
						81db6ec3f7
					
				
							
								
								
									
										15
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								go.mod
									
									
									
									
									
								
							@ -1,31 +1,20 @@
 | 
			
		||||
module github.com/phyer/texus
 | 
			
		||||
 | 
			
		||||
replace (
 | 
			
		||||
	v5sdk_go/config => ./submodules/okex/config
 | 
			
		||||
	v5sdk_go/rest => ./submodules/okex/rest
 | 
			
		||||
	v5sdk_go/utils => ./submodules/okex/utils
 | 
			
		||||
	v5sdk_go/ws => ./submodules/okex/ws
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
go 1.21
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/bitly/go-simplejson v0.5.0
 | 
			
		||||
	github.com/phyer/core v0.0.0-20241212012123-7c451a49d860
 | 
			
		||||
	v5sdk_go/rest v0.0.0-00010101000000-000000000000
 | 
			
		||||
	github.com/phyer/core v0.1.18
 | 
			
		||||
	github.com/phyer/v5sdkgo v0.1.4
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
 | 
			
		||||
	github.com/go-redis/redis v6.15.9+incompatible // indirect
 | 
			
		||||
	github.com/gorilla/websocket v1.5.1 // indirect
 | 
			
		||||
	github.com/kr/pretty v0.3.0 // indirect
 | 
			
		||||
	github.com/onsi/ginkgo v1.16.4 // indirect
 | 
			
		||||
	github.com/onsi/gomega v1.16.0 // indirect
 | 
			
		||||
	github.com/sirupsen/logrus v1.9.3 // indirect
 | 
			
		||||
	golang.org/x/net v0.17.0 // indirect
 | 
			
		||||
	golang.org/x/sys v0.13.0 // indirect
 | 
			
		||||
	v5sdk_go/config v0.0.0-00010101000000-000000000000 // indirect
 | 
			
		||||
	v5sdk_go/utils v0.0.0-00010101000000-000000000000 // indirect
 | 
			
		||||
	v5sdk_go/ws v0.0.0-00010101000000-000000000000 // indirect
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								go.sum
									
									
									
									
									
								
							@ -25,8 +25,7 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
 | 
			
		||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 | 
			
		||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
			
		||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 | 
			
		||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
 | 
			
		||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
 | 
			
		||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 | 
			
		||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 | 
			
		||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
			
		||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
 | 
			
		||||
@ -46,8 +45,10 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
 | 
			
		||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
 | 
			
		||||
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
 | 
			
		||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
 | 
			
		||||
github.com/phyer/core v0.0.0-20241212012123-7c451a49d860 h1:BZvZ7g/dPudXwCB9QNq9vPZb2xDbfTPWHVqyDGXSNBk=
 | 
			
		||||
github.com/phyer/core v0.0.0-20241212012123-7c451a49d860/go.mod h1:LyfJrdqSlm2MTOx0M3pnDntpwa64XD5nf0xYxvZ4El4=
 | 
			
		||||
github.com/phyer/core v0.1.18 h1:pXQ2QDvkbCVtqcmaQl2nCa7LjYYeJkYVQdb26HcTvgc=
 | 
			
		||||
github.com/phyer/core v0.1.18/go.mod h1:oVP5mvnnJvI2Qxlnh4jYGj92DbH7XyY2xeRagQ3hdo8=
 | 
			
		||||
github.com/phyer/v5sdkgo v0.1.4 h1:mAxxjPJVTYGuGDarqOcFGkzj5AgqbbzJGsnYmmsbapU=
 | 
			
		||||
github.com/phyer/v5sdkgo v0.1.4/go.mod h1:QCMnQFQNizOvFRPKytv50fOg/MoxS44IFcQicc4NxOg=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
			
		||||
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
 | 
			
		||||
@ -55,9 +56,16 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
 | 
			
		||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
 | 
			
		||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 | 
			
		||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
			
		||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 | 
			
		||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
 | 
			
		||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
 | 
			
		||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 | 
			
		||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 | 
			
		||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 | 
			
		||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 | 
			
		||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
 | 
			
		||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
 | 
			
		||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 | 
			
		||||
@ -120,5 +128,6 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 | 
			
		||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										44
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								main.go
									
									
									
									
									
								
							@ -1,13 +1,14 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/phyer/v5sdkgo/rest"
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
	"v5sdk_go/rest"
 | 
			
		||||
	// "v5sdk_go/ws"
 | 
			
		||||
	// "v5sdk_go/ws/wImpl"
 | 
			
		||||
 | 
			
		||||
@ -28,7 +29,7 @@ func RestTicker(cr *core.Core, dura time.Duration) {
 | 
			
		||||
	js := simple.Json{}
 | 
			
		||||
	itemList := []interface{}{}
 | 
			
		||||
	fmt.Println("getAllTickerInfo err: ")
 | 
			
		||||
	rsp1, err := cr.GetAllTickerInfo()
 | 
			
		||||
	rsp1, err := GetAllTickerInfo(cr)
 | 
			
		||||
	rsp = *rsp1
 | 
			
		||||
	js1, err := simple.NewJson([]byte(rsp.Body))
 | 
			
		||||
	js = *js1
 | 
			
		||||
@ -44,7 +45,7 @@ func RestTicker(cr *core.Core, dura time.Duration) {
 | 
			
		||||
	fmt.Println("itemList length:", len(itemList))
 | 
			
		||||
	// 关注多少个币,在这里设置, 只需要5个币
 | 
			
		||||
	allTicker := cr.GetScoreList(5)
 | 
			
		||||
	redisCli := cr.RedisCli
 | 
			
		||||
	redisCli := cr.RedisLocalCli
 | 
			
		||||
	// 全部币种列表,跟特定币种列表进行比对,匹配后push到redis
 | 
			
		||||
	for _, v := range itemList {
 | 
			
		||||
		tir := core.TickerInfoResp{}
 | 
			
		||||
@ -101,7 +102,7 @@ func LoopRestTicker(cr *core.Core) {
 | 
			
		||||
// 统一受理发起rest请求的请求
 | 
			
		||||
func LoopSaveCandle(cr *core.Core) {
 | 
			
		||||
	for {
 | 
			
		||||
		ary, err := cr.RedisCli.BRPop(0, "restQueue").Result()
 | 
			
		||||
		ary, err := cr.RedisLocalCli.BRPop(0, "restQueue").Result()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println("brpop err:", err)
 | 
			
		||||
			continue
 | 
			
		||||
@ -127,6 +128,35 @@ func LoopSaveCandle(cr *core.Core) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllTickerInfo(cr *core.Core) (*rest.RESTAPIResult, error) {
 | 
			
		||||
	rsp, err := RestInvoke(cr, "/api/v5/market/tickers?instType=SPOT", rest.GET)
 | 
			
		||||
	return rsp, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RestInvoke(cr *core.Core, subUrl string, method string) (*rest.RESTAPIResult, error) {
 | 
			
		||||
	restUrl, _ := cr.Cfg.Config.Get("connect").Get("restBaseUrl").String()
 | 
			
		||||
	//ep, method, uri string, param *map[string]interface{}
 | 
			
		||||
	rest := rest.NewRESTAPI(restUrl, method, subUrl, nil)
 | 
			
		||||
	key, _ := cr.Cfg.Config.Get("credentialReadOnly").Get("okAccessKey").String()
 | 
			
		||||
	secure, _ := cr.Cfg.Config.Get("credentialReadOnly").Get("secretKey").String()
 | 
			
		||||
	pass, _ := cr.Cfg.Config.Get("credentialReadOnly").Get("okAccessPassphrase").String()
 | 
			
		||||
	isDemo := false
 | 
			
		||||
	if cr.Env == "demoEnv" {
 | 
			
		||||
		isDemo = true
 | 
			
		||||
	}
 | 
			
		||||
	rest.SetSimulate(isDemo).SetAPIKey(key, secure, pass)
 | 
			
		||||
	response, err := rest.Run(context.Background())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Println("restInvoke1 err:", subUrl, err)
 | 
			
		||||
	}
 | 
			
		||||
	return response, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ShowSysTime(cr *core.Core) {
 | 
			
		||||
	rsp, _ := RestInvoke(cr, "/api/v5/public/time", rest.GET)
 | 
			
		||||
	fmt.Println("serverSystem time:", rsp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// period: 每个循环开始的时间点,单位:秒
 | 
			
		||||
// delay:延时多少秒后去取此值, 单位:秒
 | 
			
		||||
// mdura:多少个分钟之内,遍历完获取到的goins列表, 单位:秒
 | 
			
		||||
@ -171,7 +201,7 @@ func LoopAllCoinsList(period int64, delay int64, mdura int, barPeriod string, on
 | 
			
		||||
			nw := time.Now()
 | 
			
		||||
			rand.Seed(nw.UnixNano())
 | 
			
		||||
			ct := rand.Intn(rge)
 | 
			
		||||
			minutes := cr.PeriodToMinutes(barPeriod)
 | 
			
		||||
			minutes, _ := cr.PeriodToMinutes(barPeriod)
 | 
			
		||||
			tmi := nw.UnixMilli()
 | 
			
		||||
			tmi = tmi - tmi%60000
 | 
			
		||||
			tmi = tmi - (int64(ct) * minutes * 60000)
 | 
			
		||||
@ -185,7 +215,7 @@ func LoopAllCoinsList(period int64, delay int64, mdura int, barPeriod string, on
 | 
			
		||||
			}
 | 
			
		||||
			js, err := json.Marshal(restQ)
 | 
			
		||||
			fmt.Println("allCoins lpush js:", string(js))
 | 
			
		||||
			cr.RedisCli.LPush("restQueue", js)
 | 
			
		||||
			cr.RedisLocalCli.LPush("restQueue", js)
 | 
			
		||||
			return err
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
@ -194,7 +224,7 @@ func LoopAllCoinsList(period int64, delay int64, mdura int, barPeriod string, on
 | 
			
		||||
func main() {
 | 
			
		||||
	cr := core.Core{}
 | 
			
		||||
	cr.Init()
 | 
			
		||||
	cr.ShowSysTime()
 | 
			
		||||
	ShowSysTime(&cr)
 | 
			
		||||
	// 从rest接口获取的ticker记录种的交量计入排行榜,指定周期刷新一次
 | 
			
		||||
	go func() {
 | 
			
		||||
		fmt.Println("LoopRestTicker")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user