mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add websocket log prefix
This commit is contained in:
parent
0b896e667f
commit
6ceb54679a
|
@ -5,13 +5,13 @@ sessions:
|
|||
envVarPrefix: binance
|
||||
margin: true
|
||||
isolatedMargin: true
|
||||
isolatedMarginSymbol: GMTUSDT
|
||||
isolatedMarginSymbol: GMTBUSD
|
||||
# futures: true
|
||||
|
||||
exchangeStrategies:
|
||||
- on: binance
|
||||
pivotshort:
|
||||
symbol: GMTUSDT
|
||||
symbol: GMTBUSD
|
||||
interval: 5m
|
||||
|
||||
pivotLength: 120
|
||||
|
@ -36,7 +36,7 @@ backtest:
|
|||
startTime: "2022-05-25"
|
||||
endTime: "2022-06-03"
|
||||
symbols:
|
||||
- GMTUSDT
|
||||
- GMTBUSD
|
||||
account:
|
||||
binance:
|
||||
balances:
|
|
@ -1,8 +1,12 @@
|
|||
---
|
||||
sessions:
|
||||
binance:
|
||||
exchange: binance
|
||||
envVarPrefix: binance
|
||||
# futures: true
|
||||
margin: true
|
||||
isolatedMargin: true
|
||||
isolatedMarginSymbol: GMTUSDT
|
||||
# futures: true
|
||||
|
||||
exchangeStrategies:
|
||||
- on: binance
|
||||
|
@ -15,15 +19,15 @@ exchangeStrategies:
|
|||
entry:
|
||||
immediate: true
|
||||
catBounceRatio: 1%
|
||||
quantity: 1000
|
||||
quantity: 20
|
||||
numLayers: 3
|
||||
# marginOrderSideEffect: borrow
|
||||
marginOrderSideEffect: borrow
|
||||
|
||||
exit:
|
||||
takeProfitPercentage: 13%
|
||||
stopLossPercentage: 0.5%
|
||||
shadowTakeProfitRatio: 3%
|
||||
# marginOrderSideEffect: repay
|
||||
marginOrderSideEffect: repay
|
||||
|
||||
|
||||
backtest:
|
||||
|
|
|
@ -364,6 +364,10 @@ func (e *Exchange) queryIsolatedMarginAccount(ctx context.Context) (*types.Accou
|
|||
IsolatedMarginInfo: toGlobalIsolatedMarginAccountInfo(marginAccount), // In binance GO api, Account define marginAccount info which mantain []*AccountAsset and []*AccountPosition.
|
||||
}
|
||||
|
||||
if len(marginAccount.Assets) == 0 {
|
||||
return nil, fmt.Errorf("empty margin account assets, please check your isolatedMarginSymbol is correctly set: %+v", marginAccount)
|
||||
}
|
||||
|
||||
// for isolated margin account, we will only have one asset in the Assets array.
|
||||
if len(marginAccount.Assets) > 1 {
|
||||
return nil, fmt.Errorf("unexpected number of user assets returned, got %d user assets", len(marginAccount.Assets))
|
||||
|
|
|
@ -229,7 +229,7 @@ func (s *StandardStream) Read(ctx context.Context, conn *websocket.Conn, cancel
|
|||
func (s *StandardStream) ping(ctx context.Context, conn *websocket.Conn, cancel context.CancelFunc, interval time.Duration) {
|
||||
defer func() {
|
||||
cancel()
|
||||
log.Debug("ping worker stopped")
|
||||
log.Debug("[websocket] ping worker stopped")
|
||||
}()
|
||||
|
||||
var pingTicker = time.NewTicker(interval)
|
||||
|
@ -245,7 +245,7 @@ func (s *StandardStream) ping(ctx context.Context, conn *websocket.Conn, cancel
|
|||
return
|
||||
|
||||
case <-pingTicker.C:
|
||||
log.Debugf("websocket -> ping")
|
||||
log.Debugf("[websocket] -> ping")
|
||||
if err := conn.WriteControl(websocket.PingMessage, nil, time.Now().Add(writeTimeout)); err != nil {
|
||||
log.WithError(err).Error("ping error", err)
|
||||
s.Reconnect()
|
||||
|
@ -348,19 +348,19 @@ func (s *StandardStream) Dial(ctx context.Context, args ...string) (*websocket.C
|
|||
// Unsolicited pong frames are allowed.
|
||||
conn.SetPingHandler(nil)
|
||||
conn.SetPongHandler(func(string) error {
|
||||
log.Debugf("websocket <- received pong")
|
||||
log.Debugf("[websocket] <- received pong")
|
||||
if err := conn.SetReadDeadline(time.Now().Add(readTimeout * 2)); err != nil {
|
||||
log.WithError(err).Error("pong handler can not set read deadline")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
log.Infof("websocket connected, public = %v, read timeout = %v", s.PublicOnly, readTimeout)
|
||||
log.Infof("[websocket] connected, public = %v, read timeout = %v", s.PublicOnly, readTimeout)
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (s *StandardStream) Close() error {
|
||||
log.Debugf("closing stream...")
|
||||
log.Debugf("[websocket] closing stream...")
|
||||
|
||||
// close the close signal channel, so that reader and ping worker will stop
|
||||
close(s.CloseC)
|
||||
|
@ -382,7 +382,7 @@ func (s *StandardStream) Close() error {
|
|||
return errors.Wrap(err, "websocket write close message error")
|
||||
}
|
||||
|
||||
log.Debugf("stream closed")
|
||||
log.Debugf("[websocket] stream closed")
|
||||
|
||||
// let the reader close the connection
|
||||
<-time.After(time.Second)
|
||||
|
|
Loading…
Reference in New Issue
Block a user