/
trading_pool_statistics.go
74 lines (61 loc) · 1.93 KB
/
trading_pool_statistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package models
import (
"net/http"
"time"
"github.com/jinzhu/gorm"
"github.com/yapkah/go-api/pkg/e"
)
// TradingPoolStatistic struct
type TradingPoolStatistic struct {
ID int `gorm:"primary_key" json:"id"`
Strategy string `json:"strategy"`
TradeID int `json:"trade_id"`
Symbol string `json:"symbol"`
Num float64 `json:"num"`
Earnings float64 `json:"earnings"`
EarningsRatio float64 `json:"earnings_ratio"`
BuyPrice float64 `json:"buy_price"`
SellPrice float64 `json:"sell_price"`
TradeAt time.Time `json:"trade_at"`
BStauts int `json:"b_status"`
Timestamp time.Time `json:"timestamp"`
}
// GetTradingPoolStatisticFn
func GetTradingPoolStatisticFn(arrCond []WhereCondFn, debug bool) ([]*TradingPoolStatistic, error) {
var result []*TradingPoolStatistic
tx := db.Table("trading_pool_statistics").
Order("trading_pool_statistics.trade_at DESC")
if len(arrCond) > 0 {
for _, v := range arrCond {
tx = tx.Where(v.Condition, v.CondValue)
}
}
if debug {
tx = tx.Debug()
}
err := tx.Find(&result).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
return result, nil
}
// GetTradingPoolStatisticGroupFn
func GetTradingPoolStatisticGroupFn(arrCond []WhereCondFn, debug bool) ([]*TradingPoolStatistic, error) {
var result []*TradingPoolStatistic
tx := db.Table("trading_pool_statistics").
Select("Date(trade_at) as date").
Group("DATE(trade_at)")
if len(arrCond) > 0 {
for _, v := range arrCond {
tx = tx.Where(v.Condition, v.CondValue)
}
}
if debug {
tx = tx.Debug()
}
err := tx.Find(&result).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
return result, nil
}