Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPROVE: [biget, xdepthmaker] several improvements #1752

Merged
merged 8 commits into from
Sep 24, 2024
4 changes: 2 additions & 2 deletions pkg/exchange/bitget/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (e *Exchange) QueryKLines(

limit := uint64(options.Limit)
if limit > defaultKLineLimit || limit <= 0 {
log.Debugf("limtit is exceeded or zero, update to %d, got: %d", defaultKLineLimit, options.Limit)
log.Debugf("the parameter limit exceeds the server boundary or is set to zero. changed to %d, original value: %d", defaultKLineLimit, options.Limit)
limit = defaultKLineLimit
}
req.Limit(strconv.FormatUint(limit, 10))
Expand Down Expand Up @@ -568,7 +568,7 @@ func (e *Exchange) QueryTrades(

limit := options.Limit
if limit > queryLimit || limit <= 0 {
log.Debugf("limtit is exceeded or zero, update to %d, got: %d", queryLimit, options.Limit)
log.Debugf("the parameter limit exceeds the server boundary or is set to zero. changed to %d, original value: %d", queryLimit, options.Limit)
limit = queryLimit
}
req.Limit(strconv.FormatInt(limit, 10))
Expand Down
8 changes: 6 additions & 2 deletions pkg/exchange/bitget/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,14 @@ func (s *Stream) handleOrderTradeEvent(m OrderTradeEvent) {
return
}

debugf("received OrderTradeEvent: %+v", m)
debugf("received OrderTradeEvent %s (%s): %+v", m.instId, m.actionType, m)

for _, order := range m.Orders {
debugf("received Order: %+v", order)
if order.TradeId == 0 {
debugf("received %s order update #%d: %+v", m.instId, order.OrderId, order)
} else {
debugf("received %s order update #%d and trade update #%d: %+v", m.instId, order.OrderId, order.TradeId, order)
}

globalOrder, err := order.toGlobalOrder()
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions pkg/exchange/bybit/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
return errs
}

func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, util time.Time, lastOrderID uint64) (orders []types.Order, err error) {
func (e *Exchange) QueryClosedOrders(
ctx context.Context, symbol string, since, util time.Time, lastOrderID uint64,
) (orders []types.Order, err error) {
if !since.IsZero() || !util.IsZero() {
log.Warn("!!!BYBIT EXCHANGE API NOTICE!!! the since/until conditions will not be effected on SPOT account, bybit exchange does not support time-range-based query currently")
}
Expand Down Expand Up @@ -465,7 +467,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type

limit := uint64(options.Limit)
if limit > defaultQueryLimit || limit <= 0 {
log.Debugf("limtit is exceeded or zero, update to %d, got: %d", defaultQueryLimit, options.Limit)
log.Debugf("the parameter limit exceeds the server boundary or is set to zero. changed to %d, original value: %d", defaultQueryLimit, options.Limit)
limit = defaultQueryLimit
}
req.Limit(limit)
Expand Down Expand Up @@ -533,7 +535,9 @@ on the requested interval.
A k-line's start time is inclusive, but end time is not(startTime + interval - 1 millisecond).
e.q. 15m interval k line can be represented as 00:00:00.000 ~ 00:14:59.999
*/
func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) {
func (e *Exchange) QueryKLines(
ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions,
) ([]types.KLine, error) {
req := e.client.NewGetKLinesRequest().Symbol(symbol)
intervalStr, err := toLocalInterval(interval)
if err != nil {
Expand All @@ -543,7 +547,7 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type

limit := uint64(options.Limit)
if limit > defaultKLineLimit || limit <= 0 {
log.Debugf("limtit is exceeded or zero, update to %d, got: %d", defaultKLineLimit, options.Limit)
log.Debugf("the parameter limit exceeds the server boundary or is set to zero. changed to %d, original value: %d", defaultQueryLimit, options.Limit)
limit = defaultKLineLimit
}
req.Limit(limit)
Expand Down
37 changes: 37 additions & 0 deletions pkg/fixedpoint/mutex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fixedpoint

import "sync"

type MutexValue struct {
value Value
mu sync.Mutex
}

func (f *MutexValue) Add(v Value) Value {
f.mu.Lock()
f.value = f.value.Add(v)
ret := f.value
f.mu.Unlock()
return ret
}

func (f *MutexValue) Sub(v Value) Value {
f.mu.Lock()
f.value = f.value.Sub(v)
ret := f.value
f.mu.Unlock()
return ret
}

func (f *MutexValue) Set(v Value) {
f.mu.Lock()
f.value = v
f.mu.Unlock()
}

func (f *MutexValue) Get() Value {
f.mu.Lock()
v := f.value
f.mu.Unlock()
return v
}
6 changes: 3 additions & 3 deletions pkg/strategy/dca2/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (s *Strategy) Close(ctx context.Context) error {

var err error
if s.UniversalCancelAllOrdersWhenClose {
err = tradingutil.UniversalCancelAllOrders(ctx, s.ExchangeSession.Exchange, nil)
err = tradingutil.UniversalCancelAllOrders(ctx, s.ExchangeSession.Exchange, s.Symbol, nil)
} else {
err = s.OrderExecutor.GracefulCancel(ctx)
}
Expand All @@ -398,7 +398,7 @@ func (s *Strategy) CleanUp(ctx context.Context) error {
}

// ignore the first cancel error, this skips one open-orders query request
if err := tradingutil.UniversalCancelAllOrders(ctx, session.Exchange, nil); err == nil {
if err := tradingutil.UniversalCancelAllOrders(ctx, session.Exchange, s.Symbol, nil); err == nil {
return nil
}

Expand All @@ -418,7 +418,7 @@ func (s *Strategy) CleanUp(ctx context.Context) error {
break
}

if err := tradingutil.UniversalCancelAllOrders(ctx, session.Exchange, openOrders); err != nil {
if err := tradingutil.UniversalCancelAllOrders(ctx, session.Exchange, s.Symbol, openOrders); err != nil {
s.logger.WithError(err).Errorf("unable to cancel all orders")
werr = multierr.Append(werr, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/liquiditymaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
util.LogErr(err, "unable to cancel adjustment orders")
}

if err := tradingutil.UniversalCancelAllOrders(ctx, s.Session.Exchange, nil); err != nil {
if err := tradingutil.UniversalCancelAllOrders(ctx, s.Session.Exchange, s.Symbol, nil); err != nil {
util.LogErr(err, "unable to cancel all orders")
}

Expand Down
Loading
Loading