rollback to go1.17 and make try lock backward compatible

This commit is contained in:
c9s 2022-05-17 01:32:51 +08:00
parent 51e63fb563
commit 343434685b
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 22 additions and 8 deletions

View File

@ -1,5 +1,5 @@
# First stage container
FROM golang:1.18.2-alpine3.15 AS builder
FROM golang:1.17.6-alpine3.15 AS builder
RUN apk add --no-cache git ca-certificates gcc libc-dev pkgconfig
# gcc is for github.com/mattn/go-sqlite3
# ADD . $GOPATH/src/github.com/c9s/bbgo

View File

@ -796,7 +796,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
bottomBack := s.bottomPrice
spBack := s.sellPrice
if !quoteBalance.IsZero() && !s.sellPrice.IsZero() && !s.DisableShortStop {
//longSignal := types.CrossOver(s.ewo, s.ewoSignal)
// longSignal := types.CrossOver(s.ewo, s.ewoSignal)
// TP
/*if lastPrice.Compare(s.sellPrice) < 0 && (s.ccis.BuySignal() || longSignal.Last()) {
buyall = true
@ -910,7 +910,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
bestBid := ticker.Buy
bestAsk := ticker.Sell
var midPrice fixedpoint.Value
if s.lock.TryLock() {
// TODO: for go1.18 we can use TryLock, use build flag to support this
if tryLock(&s.lock) {
if !bestAsk.IsZero() && !bestBid.IsZero() {
s.midPrice = bestAsk.Add(bestBid).Div(types.Two)
} else if !bestAsk.IsZero() {
@ -921,10 +923,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
midPrice = s.midPrice
s.lock.Unlock()
}
if !midPrice.IsZero() {
buyOrderTPSL(midPrice)
sellOrderTPSL(midPrice)
//log.Debugf("best bid %v, best ask %v, mid %v", bestBid, bestAsk, midPrice)
// log.Debugf("best bid %v, best ask %v, mid %v", bestBid, bestAsk, midPrice)
}
})
@ -974,8 +977,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.CancelAll(ctx)
// To get the threshold for ewo
//mean := types.Mean(s.ewo, 10)
//std := types.Stdev(s.ewo, 10)
// mean := types.Mean(s.ewo, 10)
// std := types.Stdev(s.ewo, 10)
longSignal := types.CrossOver(s.ewo, s.ewoSignal)
shortSignal := types.CrossUnder(s.ewo, s.ewoSignal)
@ -991,9 +994,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
breakDown = kline.Close.Float64() < s.ma5.Last()
}
// kline breakthrough ma5, ma50 trend up, and ewo > threshold
IsBull := bull && breakThrough && s.ccis.BuySignal() //&& s.ewo.Last() > mean + 2 * std
IsBull := bull && breakThrough && s.ccis.BuySignal() // && s.ewo.Last() > mean + 2 * std
// kline downthrough ma5, ma50 trend down, and ewo < threshold
IsBear := !bull && breakDown && s.ccis.SellSignal() //.ewo.Last() < mean - 2 * std
IsBear := !bull && breakDown && s.ccis.SellSignal() // .ewo.Last() < mean - 2 * std
if !s.Environment.IsBackTesting() {
log.Infof("IsBull: %v, bull: %v, longSignal[1]: %v, shortSignal: %v",

View File

@ -0,0 +1,11 @@
//go:build !go1.18
// +build !go1.18
package ewoDgtrd
import "sync"
func tryLock(lock *sync.RWMutex) bool {
lock.Lock()
return true
}