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

@ -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,6 +923,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
midPrice = s.midPrice
s.lock.Unlock()
}
if !midPrice.IsZero() {
buyOrderTPSL(midPrice)
sellOrderTPSL(midPrice)

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
}