Skip to content

Commit

Permalink
Adds err processing, err channel, fix the others
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriousCode committed Jun 5, 2024
1 parent 5565e98 commit ab81ad1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion exchanges/deribit/deribit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ func (d *Deribit) getAssetPairByInstrument(instrument string) (currency.Pair, as

var item asset.Item
// Find the first occurrence of the delimiter and split the instrument string accordingly
parts := strings.SplitN(instrument, currency.DashDelimiter, -1)
parts := strings.Split(instrument, currency.DashDelimiter)
switch {
case len(parts) == 1:
if i := strings.IndexAny(instrument, currency.UnderscoreDelimiter); i == -1 {
Expand Down
4 changes: 2 additions & 2 deletions exchanges/deribit/deribit_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ func (d *Deribit) wsHandleData(respRaw []byte) error {
}

func (d *Deribit) processUserOrders(respRaw []byte, channels []string) error {
var response WsResponse
if len(channels) != 4 && len(channels) != 5 {
return fmt.Errorf("%w, expected format 'user.orders.{instrument_name}.raw, user.orders.{instrument_name}.{interval}, user.orders.{kind}.{currency}.raw, or user.orders.{kind}.{currency}.{interval}', but found %s", errMalformedData, strings.Join(channels, "."))
}
var orderData []WsOrder
var response WsResponse
orderData := []WsOrder{}
response.Params.Data = orderData
err := json.Unmarshal(respRaw, &response)
if err != nil {
Expand Down
18 changes: 13 additions & 5 deletions exchanges/deribit/deribit_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,28 @@ func (d *Deribit) UpdateTradablePairs(ctx context.Context, forceUpdate bool) err
assets := d.GetAssetTypes(false)
var wg sync.WaitGroup
wg.Add(len(assets))
var errs error
errC := make(chan error, len(assets))
for x := range assets {
go func(x int) {
defer wg.Done()
pairs, err := d.FetchTradablePairs(ctx, assets[x])
if err != nil {
errs = common.AppendError(errs, err)
errC <- err
return
}
err = d.UpdatePairs(pairs, assets[x], false, forceUpdate)
if err != nil {
errs = common.AppendError(errs, err)
errC <- err
return
}
}(x)
}
wg.Wait()
close(errC)
var errs error
for err := range errC {
errs = common.AppendError(errs, err)
}
return errs
}

Expand Down Expand Up @@ -1496,8 +1501,11 @@ func (d *Deribit) GetLatestFundingRates(ctx context.Context, r *fundingrate.Late
return nil, fmt.Errorf("%s %w", r.Asset, asset.ErrNotSupported)
}
isPerpetual, err := d.IsPerpetualFutureCurrency(r.Asset, r.Pair)
if !isPerpetual || err != nil {
return nil, futures.ErrNotPerpetualFuture
if err != nil {
return nil, err
}
if !isPerpetual {
return nil, fmt.Errorf("%w '%s'", futures.ErrNotPerpetualFuture, r.Pair)
}
pFmt, err := d.CurrencyPairs.GetFormat(r.Asset, true)
if err != nil {
Expand Down

0 comments on commit ab81ad1

Please sign in to comment.