You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
package api
|
|
|
|
import (
|
|
"WechatGateWay/global"
|
|
"github.com/jinzhu/gorm"
|
|
"log"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@author: sre
|
|
@date: 2022/9/12 0012
|
|
@desc: todo
|
|
*
|
|
*/
|
|
type BinancePrice struct {
|
|
gorm.Model
|
|
Symbol string
|
|
Price float64
|
|
}
|
|
|
|
func GetBinanceLatestPrice(symbol string) float64 {
|
|
var binancePrice BinancePrice
|
|
global.DB.Where("symbol = ?", symbol).Last(&binancePrice)
|
|
return binancePrice.Price
|
|
}
|
|
|
|
func GetBinanceLatestPrices(symbol string) []BinancePrice {
|
|
var binancePrices []BinancePrice
|
|
global.DB.Where("symbol = ? ", symbol).Order("id desc").Find(&binancePrices)
|
|
//global.DB.Where("symbol = ? order by id desc", symbol).Limit(30).Find(&binancePrices)
|
|
return binancePrices
|
|
}
|
|
|
|
func GetSerivers(symbol string) (timeUpdate []string, symbolPrice []float64) {
|
|
binancePrices := GetBinanceLatestPrices(symbol)
|
|
log.Println("binancePrices: ", len(binancePrices))
|
|
for _, binancePrice := range binancePrices {
|
|
timeUpdate = append(timeUpdate, binancePrice.UpdatedAt.Format("2006-01-02 15:04:05"))
|
|
symbolPrice = append(symbolPrice, binancePrice.Price)
|
|
}
|
|
return
|
|
}
|