Skip to content

Commit 8a21572

Browse files
committed
refactor: Fix nitterinos
1 parent 34334ed commit 8a21572

File tree

14 files changed

+123
-150
lines changed

14 files changed

+123
-150
lines changed

exchanges/binance/binance.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ func (e *Exchange) OpenOrders(ctx context.Context, pair currency.Pair) ([]QueryO
602602

603603
// AllOrders Get all account orders; active, canceled, or filled.
604604
// orderId optional param
605-
// limit optional param, default 500; max 500
606-
func (e *Exchange) AllOrders(ctx context.Context, symbol currency.Pair, orderID, limit string) ([]QueryOrderData, error) {
605+
// limit optional param, default 500; max 1000
606+
func (e *Exchange) AllOrders(ctx context.Context, symbol currency.Pair, orderID, limit uint64) ([]QueryOrderData, error) {
607607
var resp []QueryOrderData
608608

609609
params := url.Values{}
@@ -612,19 +612,13 @@ func (e *Exchange) AllOrders(ctx context.Context, symbol currency.Pair, orderID,
612612
return resp, err
613613
}
614614
params.Set("symbol", symbolValue)
615-
if orderID != "" {
616-
params.Set("orderId", orderID)
615+
if orderID != 0 {
616+
params.Set("orderId", strconv.FormatUint(orderID, 10))
617617
}
618-
if limit != "" {
619-
params.Set("limit", limit)
618+
if limit != 0 {
619+
params.Set("limit", strconv.FormatUint(limit, 10))
620620
}
621-
if err := e.SendAuthHTTPRequest(ctx,
622-
exchange.RestSpotSupplementary,
623-
http.MethodGet,
624-
allOrders,
625-
params,
626-
spotAllOrdersRate,
627-
&resp); err != nil {
621+
if err := e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, allOrders, params, spotAllOrdersRate, &resp); err != nil {
628622
return resp, err
629623
}
630624
return resp, nil

exchanges/binance/binance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ func TestOpenOrders(t *testing.T) {
12741274
func TestAllOrders(t *testing.T) {
12751275
t.Parallel()
12761276

1277-
_, err := e.AllOrders(t.Context(), currency.NewBTCUSDT(), "", "")
1277+
_, err := e.AllOrders(t.Context(), currency.NewBTCUSDT(), 0, 1000)
12781278
switch {
12791279
case sharedtestvalues.AreAPICredentialsSet(e) && err != nil:
12801280
t.Error("AllOrders() error", err)

exchanges/binance/binance_types.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -800,39 +800,39 @@ type WsBalanceUpdateData struct {
800800

801801
// WsOrderUpdateData defines websocket account order update data
802802
type WsOrderUpdateData struct {
803-
EventType string `json:"e"`
804-
EventTime types.Time `json:"E"`
805-
Symbol string `json:"s"`
806-
ClientOrderID string `json:"c"`
807-
Side order.Side `json:"S"`
808-
OrderType order.Type `json:"o"`
809-
TimeInForce string `json:"f"`
810-
Quantity float64 `json:"q,string"`
811-
Price float64 `json:"p,string"`
812-
StopPrice float64 `json:"P,string"`
813-
IcebergQuantity float64 `json:"F,string"`
814-
OrderListID int64 `json:"g"`
815-
CancelledClientOrderID string `json:"C"`
816-
CurrentExecutionType string `json:"x"`
817-
OrderStatus order.Status `json:"X"`
818-
RejectionReason string `json:"r"`
819-
OrderID int64 `json:"i"`
820-
LastExecutedQuantity float64 `json:"l,string"`
821-
CumulativeFilledQuantity float64 `json:"z,string"`
822-
LastExecutedPrice float64 `json:"L,string"`
823-
Commission float64 `json:"n,string"`
824-
CommissionAsset currency.Code `json:"N"`
825-
TransactionTime types.Time `json:"T"`
826-
TradeID int64 `json:"t"`
827-
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'.
828-
IsOnOrderBook bool `json:"w"`
829-
IsMaker bool `json:"m"`
830-
Ignored2 bool `json:"M"` // See the comment for "I".
831-
OrderCreationTime types.Time `json:"O"`
832-
WorkingTime types.Time `json:"W"`
833-
CumulativeQuoteTransactedQuantity float64 `json:"Z,string"`
834-
LastQuoteAssetTransactedQuantity float64 `json:"Y,string"`
835-
QuoteOrderQuantity float64 `json:"Q,string"`
803+
EventType string `json:"e"`
804+
EventTime types.Time `json:"E"`
805+
Symbol string `json:"s"`
806+
ClientOrderID string `json:"c"`
807+
Side order.Side `json:"S"`
808+
OrderType order.Type `json:"o"`
809+
TimeInForce string `json:"f"`
810+
Quantity float64 `json:"q,string"`
811+
Price float64 `json:"p,string"`
812+
StopPrice float64 `json:"P,string"`
813+
IcebergQuantity float64 `json:"F,string"`
814+
OrderListID int64 `json:"g"`
815+
CancelledClientOrderID string `json:"C"`
816+
CurrentExecutionType string `json:"x"`
817+
OrderStatus order.Status `json:"X"`
818+
RejectionReason string `json:"r"`
819+
OrderID int64 `json:"i"`
820+
LastExecutedQuantity float64 `json:"l,string"`
821+
CumulativeFilledQuantity float64 `json:"z,string"`
822+
LastExecutedPrice float64 `json:"L,string"`
823+
Commission float64 `json:"n,string"`
824+
CommissionAsset currency.Code `json:"N"`
825+
TransactionTime types.Time `json:"T"`
826+
TradeID int64 `json:"t"`
827+
Ignored json.RawMessage `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'.
828+
IsOnOrderBook bool `json:"w"`
829+
IsMaker bool `json:"m"`
830+
Ignored2 json.RawMessage `json:"M"` // Must be ignored explicitly, otherwise it overwrites 'm'
831+
OrderCreationTime types.Time `json:"O"`
832+
WorkingTime types.Time `json:"W"`
833+
CumulativeQuoteTransactedQuantity float64 `json:"Z,string"`
834+
LastQuoteAssetTransactedQuantity float64 `json:"Y,string"`
835+
QuoteOrderQuantity float64 `json:"Q,string"`
836836
}
837837

838838
// WsListStatusData defines websocket account listing status data

exchanges/binance/binance_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ func (e *Exchange) GetOrderHistory(ctx context.Context, req *order.MultiOrderReq
14031403
switch req.AssetType {
14041404
case asset.Spot, asset.Margin:
14051405
for x := range req.Pairs {
1406-
resp, err := e.AllOrders(ctx, req.Pairs[x], "", "1000")
1406+
resp, err := e.AllOrders(ctx, req.Pairs[x], 0, 1000)
14071407
if err != nil {
14081408
return nil, err
14091409
}

exchanges/binance/testdata/http.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11574,7 +11574,7 @@
1157411574
"updateTime": 1499827319559
1157511575
}
1157611576
],
11577-
"queryString": "recvWindow=5000\u0026signature=2d45930bd9a4579c19378046d570031e38473b9c24f796f60a80ba5b7768626d\u0026symbol=BTCUSDT\u0026timestamp=1588749277000",
11577+
"queryString": "limit=1000\u0026recvWindow=5000\u0026signature=2d45930bd9a4579c19378046d570031e38473b9c24f796f60a80ba5b7768626d\u0026symbol=BTCUSDT\u0026timestamp=1588749277000",
1157811578
"bodyParams": "",
1157911579
"headers": {
1158011580
"X-Mbx-Apikey": [

exchanges/binanceus/binanceus_types.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -908,38 +908,38 @@ type wsOrderUpdate struct {
908908

909909
// WsOrderUpdateData defines websocket account order update data
910910
type WsOrderUpdateData struct {
911-
EventType string `json:"e"`
912-
EventTime types.Time `json:"E"`
913-
Symbol string `json:"s"`
914-
ClientOrderID string `json:"c"`
915-
Side order.Side `json:"S"`
916-
OrderType order.Type `json:"o"`
917-
TimeInForce string `json:"f"`
918-
Quantity float64 `json:"q,string"`
919-
Price float64 `json:"p,string"`
920-
StopPrice float64 `json:"P,string"`
921-
IcebergQuantity float64 `json:"F,string"`
922-
OrderListID int64 `json:"g"`
923-
CancelledClientOrderID string `json:"C"`
924-
CurrentExecutionType string `json:"x"`
925-
OrderStatus order.Status `json:"X"`
926-
RejectionReason string `json:"r"`
927-
OrderID int64 `json:"i"`
928-
LastExecutedQuantity float64 `json:"l,string"`
929-
CumulativeFilledQuantity float64 `json:"z,string"`
930-
LastExecutedPrice float64 `json:"L,string"`
931-
Commission float64 `json:"n,string"`
932-
CommissionAsset currency.Code `json:"N"`
933-
TransactionTime types.Time `json:"T"`
934-
TradeID int64 `json:"t"`
935-
Ignored int64 `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'.
936-
IsOnOrderBook bool `json:"w"`
937-
IsMaker bool `json:"m"`
938-
Ignored2 bool `json:"M"` // See the comment for "I".
939-
OrderCreationTime types.Time `json:"O"`
940-
CumulativeQuoteTransactedQuantity float64 `json:"Z,string"`
941-
LastQuoteAssetTransactedQuantity float64 `json:"Y,string"`
942-
QuoteOrderQuantity float64 `json:"Q,string"`
911+
EventType string `json:"e"`
912+
EventTime types.Time `json:"E"`
913+
Symbol string `json:"s"`
914+
ClientOrderID string `json:"c"`
915+
Side order.Side `json:"S"`
916+
OrderType order.Type `json:"o"`
917+
TimeInForce string `json:"f"`
918+
Quantity float64 `json:"q,string"`
919+
Price float64 `json:"p,string"`
920+
StopPrice float64 `json:"P,string"`
921+
IcebergQuantity float64 `json:"F,string"`
922+
OrderListID int64 `json:"g"`
923+
CancelledClientOrderID string `json:"C"`
924+
CurrentExecutionType string `json:"x"`
925+
OrderStatus order.Status `json:"X"`
926+
RejectionReason string `json:"r"`
927+
OrderID int64 `json:"i"`
928+
LastExecutedQuantity float64 `json:"l,string"`
929+
CumulativeFilledQuantity float64 `json:"z,string"`
930+
LastExecutedPrice float64 `json:"L,string"`
931+
Commission float64 `json:"n,string"`
932+
CommissionAsset currency.Code `json:"N"`
933+
TransactionTime types.Time `json:"T"`
934+
TradeID int64 `json:"t"`
935+
Ignored json.RawMessage `json:"I"` // Must be ignored explicitly, otherwise it overwrites 'i'.
936+
IsOnOrderBook bool `json:"w"`
937+
IsMaker bool `json:"m"`
938+
Ignored2 json.RawMessage `json:"M"` // Must be ignored explicitly, otherwise it overwrites 'm'
939+
OrderCreationTime types.Time `json:"O"`
940+
CumulativeQuoteTransactedQuantity float64 `json:"Z,string"`
941+
LastQuoteAssetTransactedQuantity float64 `json:"Y,string"`
942+
QuoteOrderQuantity float64 `json:"Q,string"`
943943
}
944944

945945
// WsListStatus holder for websocket account listing status response including the stream information

exchanges/bitfinex/bitfinex_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ func (e *Exchange) parseOrderToOrderDetail(o *Order) (*order.Detail, error) {
720720
var err error
721721
orderDetail.Type, err = order.StringToOrderType(orderType)
722722
if err != nil {
723-
return nil, fmt.Errorf("unable to convert order type %s to order.Type: %w", orderType, err)
723+
return nil, fmt.Errorf("unable to convert order type %q to order.Type: %w", orderType, err)
724724
}
725725
}
726726

exchanges/bitmex/bitmex_types.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -649,31 +649,17 @@ type MinWithdrawalFee struct {
649649

650650
// WalletInfo wallet information
651651
type WalletInfo struct {
652-
Account int64 `json:"account"`
653-
Addr string `json:"addr"`
654-
Amount float64 `json:"amount"`
655-
ConfirmedDebit int64 `json:"confirmedDebit"`
656-
Currency currency.Code `json:"currency"`
657-
DeltaAmount int64 `json:"deltaAmount"`
658-
DeltaDeposited int64 `json:"deltaDeposited"`
659-
DeltaTransferIn int64 `json:"deltaTransferIn"`
660-
DeltaTransferOut int64 `json:"deltaTransferOut"`
661-
DeltaWithdrawn int64 `json:"deltaWithdrawn"`
662-
Deposited int64 `json:"deposited"`
663-
PendingCredit int64 `json:"pendingCredit"`
664-
PendingDebit int64 `json:"pendingDebit"`
665-
PrevAmount int64 `json:"prevAmount"`
666-
PrevDeposited int64 `json:"prevDeposited"`
667-
PrevTimestamp time.Time `json:"prevTimestamp"`
668-
PrevTransferIn int64 `json:"prevTransferIn"`
669-
PrevTransferOut int64 `json:"prevTransferOut"`
670-
PrevWithdrawn int64 `json:"prevWithdrawn"`
671-
Script string `json:"script"`
672-
Timestamp time.Time `json:"timestamp"`
673-
TransferIn int64 `json:"transferIn"`
674-
TransferOut int64 `json:"transferOut"`
675-
WithdrawalLock []string `json:"withdrawalLock"`
676-
Withdrawn int64 `json:"withdrawn"`
652+
Account int64 `json:"account"`
653+
Currency currency.Code `json:"currency"`
654+
Deposited float64 `json:"deposited"`
655+
Withdrawn float64 `json:"withdrawn"`
656+
TransferIn float64 `json:"transferIn"`
657+
TransferOut float64 `json:"transferOut"`
658+
Amount float64 `json:"amount"`
659+
PendingCredit float64 `json:"pendingCredit"`
660+
PendingDebit float64 `json:"pendingDebit"`
661+
ConfirmedDebit float64 `json:"confirmedDebit"`
662+
Timestamp time.Time `json:"timestamp"`
677663
}
678664

679665
// orderTypeMap holds order type info based on Bitmex data

exchanges/deribit/deribit_websocket.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,14 @@ func (e *Exchange) processOrderbook(respRaw []byte, channels []string) error {
615615
return err
616616
}
617617

618-
if len(channels) != 3 && len(channels) != 5 {
619-
return nil
618+
const (
619+
partialFeedCount = 3
620+
fullFeedCount = 5
621+
)
622+
623+
chanLen := len(channels)
624+
if chanLen != partialFeedCount && chanLen != fullFeedCount {
625+
return fmt.Errorf("expected %d or %d channels, but got %d", partialFeedCount, fullFeedCount, chanLen)
620626
}
621627

622628
cp, a, err := e.getAssetPairByInstrument(ob.InstrumentName)
@@ -626,7 +632,6 @@ func (e *Exchange) processOrderbook(respRaw []byte, channels []string) error {
626632

627633
buildLevels := func(items []orderbookItem) orderbook.Levels {
628634
lvls := make(orderbook.Levels, 0, len(items))
629-
630635
for x := range items {
631636
if items[x].Amount == 0 {
632637
continue
@@ -644,22 +649,7 @@ func (e *Exchange) processOrderbook(respRaw []byte, channels []string) error {
644649
return nil
645650
}
646651

647-
book := &orderbook.Book{
648-
Exchange: e.Name,
649-
Pair: cp,
650-
Asset: a,
651-
Asks: asks,
652-
Bids: bids,
653-
LastUpdateID: ob.ChangeID,
654-
LastUpdated: ob.Timestamp.Time(),
655-
}
656-
657-
switch {
658-
case len(channels) == 3 && ob.Type == "snapshot":
659-
book.ValidateOrderbook = e.ValidateOrderbook
660-
return e.Websocket.Orderbook.LoadSnapshot(book)
661-
662-
case len(channels) == 3 && ob.Type == "change":
652+
if chanLen == partialFeedCount && ob.Type == "change" {
663653
return e.Websocket.Orderbook.Update(&orderbook.Update{
664654
Asks: asks,
665655
Bids: bids,
@@ -668,15 +658,18 @@ func (e *Exchange) processOrderbook(respRaw []byte, channels []string) error {
668658
UpdateID: ob.ChangeID,
669659
UpdateTime: ob.Timestamp.Time(),
670660
})
671-
672-
case len(channels) == 5:
673-
// on the “5-item” feed we always treat every push as a snapshot
674-
return e.Websocket.Orderbook.LoadSnapshot(book)
675-
676-
default:
677-
// either an unknown type or a channel length we don’t handle
678-
return nil
679661
}
662+
663+
return e.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
664+
Exchange: e.Name,
665+
Pair: cp,
666+
Asset: a,
667+
Asks: asks,
668+
Bids: bids,
669+
LastUpdateID: ob.ChangeID,
670+
LastUpdated: ob.Timestamp.Time(),
671+
ValidateOrderbook: e.ValidateOrderbook,
672+
})
680673
}
681674

682675
// generateSubscriptions returns a list of configured subscriptions

exchanges/deribit/deribit_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (e *Exchange) GetWithdrawalsHistory(ctx context.Context, c currency.Code, _
440440
}
441441
resp := []exchange.WithdrawalHistory{}
442442
for x := range currencies {
443-
if currencies[x].Currency.Equal(c) {
443+
if !currencies[x].Currency.Equal(c) {
444444
continue
445445
}
446446
var withdrawalData *WithdrawalsData

0 commit comments

Comments
 (0)