mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
rollback to go1.17 and make try lock backward compatible
This commit is contained in:
parent
51e63fb563
commit
343434685b
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
11
pkg/strategy/ewoDgtrd/trylock.go
Normal file
11
pkg/strategy/ewoDgtrd/trylock.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user