pkg: return err if rate limit err

This commit is contained in:
Edwin 2023-07-25 15:09:57 +08:00
parent ef8d1c7046
commit b71030c5db
3 changed files with 9 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import (
func (e *Exchange) CancelReplace(ctx context.Context, cancelReplaceMode types.CancelReplaceModeType, o types.Order) (*types.Order, error) { func (e *Exchange) CancelReplace(ctx context.Context, cancelReplaceMode types.CancelReplaceModeType, o types.Order) (*types.Order, error) {
if err := orderLimiter.Wait(ctx); err != nil { if err := orderLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("order rate limiter wait error") log.WithError(err).Errorf("order rate limiter wait error")
return nil, err
} }
if e.IsFutures || e.IsMargin { if e.IsFutures || e.IsMargin {

View File

@ -764,8 +764,9 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
} }
*/ */
if err := orderLimiter.Wait(ctx); err != nil { if err = orderLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("order rate limiter wait error") log.WithError(err).Errorf("order rate limiter wait error")
return nil, err
} }
log.Infof("querying closed orders %s from %s <=> %s ...", symbol, since, until) log.Infof("querying closed orders %s from %s <=> %s ...", symbol, since, until)
@ -822,8 +823,9 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
} }
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err error) { func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err error) {
if err := orderLimiter.Wait(ctx); err != nil { if err = orderLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("order rate limiter wait error") log.WithError(err).Errorf("order rate limiter wait error")
return err
} }
if e.IsFutures { if e.IsFutures {
@ -1086,8 +1088,9 @@ func (e *Exchange) submitSpotOrder(ctx context.Context, order types.SubmitOrder)
} }
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error) { func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error) {
if err := orderLimiter.Wait(ctx); err != nil { if err = orderLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("order rate limiter wait error") log.WithError(err).Errorf("order rate limiter wait error")
return nil, err
} }
if e.IsMargin { if e.IsMargin {

View File

@ -73,6 +73,7 @@ func (r *TelegramReply) Send(message string) {
for _, split := range splits { for _, split := range splits {
if err := sendLimiter.Wait(ctx); err != nil { if err := sendLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("telegram send limit exceeded") log.WithError(err).Errorf("telegram send limit exceeded")
return
} }
checkSendErr(r.bot.Send(r.session.Chat, split)) checkSendErr(r.bot.Send(r.session.Chat, split))
} }
@ -175,6 +176,7 @@ func (tm *Telegram) Start(ctx context.Context) {
for i, split := range splits { for i, split := range splits {
if err := sendLimiter.Wait(ctx); err != nil { if err := sendLimiter.Wait(ctx); err != nil {
log.WithError(err).Errorf("telegram send limit exceeded") log.WithError(err).Errorf("telegram send limit exceeded")
return
} }
if i == len(splits)-1 { if i == len(splits)-1 {
// only set menu on the last message // only set menu on the last message