-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd80a88
commit a01a328
Showing
22 changed files
with
313 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,10 @@ new_enable = 0 | |
# 设定的价格提醒币种 | ||
enable = 0 | ||
|
||
[listen_coin] | ||
# 监听的币种 | ||
enable = 0 | ||
|
||
[web] | ||
# 监听端口 | ||
port = 3333 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package controllers | ||
|
||
import ( | ||
"strconv" | ||
|
||
"go_binance_futures/models" | ||
"go_binance_futures/utils" | ||
|
||
"github.com/beego/beego/v2/client/orm" | ||
"github.com/beego/beego/v2/server/web" | ||
) | ||
|
||
type ListenCoinController struct { | ||
web.Controller | ||
} | ||
|
||
func (ctrl *ListenCoinController) Get() { | ||
paramsType := ctrl.GetString("type", "") | ||
|
||
o := orm.NewOrm() | ||
var symbols []models.ListenSymbols | ||
query := o.QueryTable("listen_symbols") | ||
if paramsType != "" { | ||
query = query.Filter("Type", paramsType) | ||
} | ||
_, err := query.OrderBy("ID").All(&symbols) | ||
if err != nil { | ||
ctrl.Ctx.Resp(utils.ResJson(400, nil, err.Error())) | ||
} | ||
|
||
ctrl.Ctx.Resp(map[string]interface{} { | ||
"code": 200, | ||
"data": symbols, | ||
"msg": "success", | ||
}) | ||
} | ||
|
||
func (ctrl *ListenCoinController) Edit() { | ||
id := ctrl.Ctx.Input.Param(":id") | ||
var symbols models.ListenSymbols | ||
o := orm.NewOrm() | ||
o.QueryTable("listen_symbols").Filter("Id", id).One(&symbols) | ||
|
||
ctrl.BindJSON(&symbols) | ||
|
||
_, err := o.Update(&symbols) // _ 是受影响的条数 | ||
if err != nil { | ||
// 处理错误 | ||
ctrl.Ctx.Resp(utils.ResJson(400, nil, "修改失败")) | ||
return | ||
} | ||
ctrl.Ctx.Resp(map[string]interface{} { | ||
"code": 200, | ||
"data": symbols, | ||
"msg": "success", | ||
}) | ||
} | ||
|
||
func (ctrl *ListenCoinController) Delete() { | ||
id := ctrl.Ctx.Input.Param(":id") | ||
symbols := new(models.ListenSymbols) | ||
intId, _ := strconv.ParseInt(id, 10, 64) | ||
symbols.ID = intId | ||
o := orm.NewOrm() | ||
|
||
_, err := o.Delete(symbols) | ||
if err != nil { | ||
// 处理错误 | ||
ctrl.Ctx.Resp(utils.ResJson(400, nil, "删除错误")) | ||
return | ||
} | ||
ctrl.Ctx.Resp(map[string]interface{} { | ||
"code": 200, | ||
"msg": "success", | ||
}) | ||
} | ||
|
||
func (ctrl *ListenCoinController) Post() { | ||
symbols := new(models.ListenSymbols) | ||
ctrl.BindJSON(&symbols) | ||
|
||
symbols.Enable = 0 // 默认不开启 | ||
symbols.KlineInterval = "1m" // 默认k线周期 | ||
symbols.ChangePercent = "1.1" // 1.1% 默认变化幅度 | ||
symbols.LastNoticeTime = 0 // 最后一次通知时间 | ||
symbols.NoticeLimitMin = 5 // 最小通知间隔 | ||
|
||
o := orm.NewOrm() | ||
id, err := o.Insert(symbols) | ||
|
||
if err != nil { | ||
// 处理错误 | ||
ctrl.Ctx.Resp(utils.ResJson(400, nil, "新增失败")) | ||
return | ||
} | ||
symbols.ID = id | ||
|
||
ctrl.Ctx.Resp(map[string]interface{} { | ||
"code": 200, | ||
"data": symbols, | ||
"msg": "success", | ||
}) | ||
} | ||
|
||
func (ctrl *ListenCoinController) UpdateEnable() { | ||
flag := ctrl.Ctx.Input.Param(":flag") | ||
|
||
o := orm.NewOrm() | ||
_, err := o.Raw("UPDATE listen_symbols SET enable = ?", flag).Exec() | ||
if err != nil { | ||
// 处理错误 | ||
ctrl.Ctx.Resp(utils.ResJson(400, nil, "更新错误")) | ||
return | ||
} | ||
ctrl.Ctx.Resp(utils.ResJson(200, nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package feature | ||
|
||
import ( | ||
"go_binance_futures/feature/api/binance" | ||
"go_binance_futures/feature/notify" | ||
"go_binance_futures/models" | ||
"strconv" | ||
|
||
"github.com/beego/beego/v2/client/orm" | ||
"github.com/beego/beego/v2/core/logs" | ||
) | ||
|
||
func ListenCoin() { | ||
o := orm.NewOrm() | ||
var coins []models.ListenSymbols | ||
o.QueryTable("listen_symbols").OrderBy("ID").Filter("enable", 1).Filter("type", 2).All(&coins) // 通知币列表 | ||
|
||
for _, coin := range coins { | ||
logs.Info("监听合约币种:", coin.Symbol) | ||
kline_1, err1 := binance.GetKlineData(coin.Symbol, coin.KlineInterval, 10) | ||
if err1 != nil { | ||
logs.Error("k线错误, 合约币种是:", coin.Symbol) | ||
continue | ||
} | ||
|
||
percentLimit, _ := strconv.ParseFloat(coin.ChangePercent, 64) | ||
percentLimit = percentLimit / 100 // 变化幅度 | ||
|
||
lastOpenPrice, _ := strconv.ParseFloat(kline_1[1].Open, 64) // 上一根 k 线的开盘价 | ||
nowPrice, _ := strconv.ParseFloat(kline_1[0].Close, 64) // 当前价格 | ||
|
||
if (nowPrice > lastOpenPrice) && | ||
(nowPrice - lastOpenPrice) / lastOpenPrice >= percentLimit && | ||
((kline_1[0].CloseTime - coin.LastNoticeTime >= 60 * 1000 * coin.NoticeLimitMin && coin.LastNoticeType == "up") || coin.LastNoticeType != "up") { | ||
// 价格上涨 | ||
coin.LastNoticeTime = kline_1[0].CloseTime | ||
coin.LastNoticeType = "up" | ||
orm.NewOrm().Update(&coin) | ||
|
||
notify.ListenFutureCoin(coin.Symbol, "极速上涨", (nowPrice - lastOpenPrice) / lastOpenPrice) | ||
} | ||
if (nowPrice < lastOpenPrice) && | ||
(lastOpenPrice - nowPrice) / lastOpenPrice >= percentLimit && | ||
((kline_1[0].CloseTime - coin.LastNoticeTime >= 60 * 1000 * coin.NoticeLimitMin && coin.LastNoticeType == "down") || coin.LastNoticeType != "down") { | ||
// 价格下跌 | ||
coin.LastNoticeTime = kline_1[0].CloseTime | ||
coin.LastNoticeType = "down" | ||
orm.NewOrm().Update(&coin) | ||
|
||
notify.ListenFutureCoin(coin.Symbol, "极速下跌", (lastOpenPrice - nowPrice) / lastOpenPrice) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,4 +149,16 @@ func NoticeFutureCoin(symbol string, side string, price string, autoOrder string | |
> author <[email protected]>` | ||
DingDing(fmt.Sprintf(text, symbol, symbol, side, price, autoOrder, time.Now().Format("2006-01-02 15:04:05"))) | ||
} | ||
|
||
func ListenFutureCoin(symbol string, listenType string, percent float64) { | ||
text := ` | ||
## %s合约k线监控通知 | ||
#### **币种**:%s | ||
#### **类型**:<font color="#008000">%s</font> | ||
#### **当前变化率**:<font color="#008000">%f</font> | ||
#### **时间**:%s | ||
> author <[email protected]>` | ||
DingDing(fmt.Sprintf(text, symbol, symbol, listenType, percent, time.Now().Format("2006-01-02 15:04:05"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,14 @@ func NoticeSpotCoin(symbol string, side string, price string, autoOrder string) | |
DingDing(fmt.Sprintf(text, symbol, symbol, side, price, autoOrder, time.Now().Format("2006-01-02 15:04:05"))) | ||
} | ||
|
||
func ListenSpotCoin(symbol string, listenType string, percent float64) { | ||
text := ` | ||
## %s现货k线监控通知 | ||
#### **币种**:%s | ||
#### **类型**:<font color="#008000">%s</font> | ||
#### **当前变化率**:<font color="#008000">%f</font> | ||
#### **时间**:%s | ||
> author <[email protected]>` | ||
DingDing(fmt.Sprintf(text, symbol, symbol, listenType, percent, time.Now().Format("2006-01-02 15:04:05"))) | ||
} |
Oops, something went wrong.