From d2a507decec53a5359c4bcb6eafccf43a0d9ab7b Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Sat, 17 Sep 2022 18:16:06 +0800 Subject: [PATCH] get huge eth price --- api/binancePrice.go | 15 +++++++++++++++ goCharts/draw.go | 19 +++++++++++-------- readme.md | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/api/binancePrice.go b/api/binancePrice.go index 32eb24a..e519f97 100644 --- a/api/binancePrice.go +++ b/api/binancePrice.go @@ -23,3 +23,18 @@ func GetBinanceLatestPrice(symbol string) float64 { global.DB.Where("symbol = ?", symbol).Last(&binancePrice) return binancePrice.Price } + +func GetBinanceLatestPrices(symbol string) []BinancePrice { + var binancePrices []BinancePrice + global.DB.Where("symbol = ?", symbol).Find(&binancePrices) + return binancePrices +} + +func GetSerivers(symbol string) (timeUpdate []string, symbolPrice []float64) { + binancePrices := GetBinanceLatestPrices(symbol) + for _, binancePrice := range binancePrices { + timeUpdate = append(timeUpdate, binancePrice.UpdatedAt.Format("2006-01-02 15:04:05")) + symbolPrice = append(symbolPrice, binancePrice.Price) + } + return +} diff --git a/goCharts/draw.go b/goCharts/draw.go index 68cac43..c4f41a4 100644 --- a/goCharts/draw.go +++ b/goCharts/draw.go @@ -9,6 +9,7 @@ package goCharts */ import ( + "WechatGateWay/api" "github.com/vicanso/go-charts/v2" "math/rand" "time" @@ -24,11 +25,12 @@ func getRand(len int) []float64 { } func Draw() { + timeUpdate, symbolPrice := api.GetSerivers("ETHUSDT") values := [][]float64{ - getRand(30), - getRand(30), - getRand(30), - getRand(30), + symbolPrice, + //getRand(30), + //getRand(30), + //getRand(30), } p, err := charts.LineRender( values, @@ -37,12 +39,13 @@ func Draw() { charts.WidthOptionFunc(720), charts.HeightOptionFunc(1280), charts.TitleTextOptionFunc("symbol price"), - charts.XAxisDataOptionFunc(getLastDays(30)), + charts.XAxisDataOptionFunc(timeUpdate), + //charts.XAxisDataOptionFunc(getLastDays(30)), charts.LegendLabelsOptionFunc([]string{ - "BTC", "ETH", - "BNB", - "TRX", + //"ETH", + //"BNB", + //"TRX", }, "150"), func(opt *charts.ChartOption) { opt.Legend.Padding = charts.Box{ diff --git a/readme.md b/readme.md index ec2d55d..b1c25a9 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ [![Build Status](https://ci.yangqiao.org/api/badges/go/WechatGateWay/status.svg)](https://ci.yangqiao.org/go/WechatGateWay) +![](https://i.niupic.com/images/2022/09/17/a5ia.png) ![](https://cnjdmh6kwm1w.compat.objectstorage.ap-seoul-1.oraclecloud.com/s3/2022/07/29d6e88c6061f4d56315cb36f2c66036.png) # 接收消息与事件 https://developer.work.weixin.qq.com/document/10514