Skip to content

Commit 753ea35

Browse files
committed
codebase: Consolidate orders functionality and other minor fixes
1 parent 53e1421 commit 753ea35

File tree

87 files changed

+1992
-3834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1992
-3834
lines changed

engine/rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3662,7 +3662,7 @@ func parseWithdrawalsHistory(ret []exchange.WithdrawalHistory, exchName string,
36623662
Status: ret[x].Status,
36633663
},
36643664
Request: &gctrpc.WithdrawalRequestEvent{
3665-
Currency: ret[x].Currency,
3665+
Currency: ret[x].Currency.String(),
36663666
Description: ret[x].Description,
36673667
Amount: ret[x].Amount,
36683668
},

exchanges/binance/binance_types.go

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/thrasher-corp/gocryptotrader/currency"
99
"github.com/thrasher-corp/gocryptotrader/encoding/json"
1010
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
11+
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
1112
"github.com/thrasher-corp/gocryptotrader/types"
1213
)
1314

@@ -440,31 +441,31 @@ type CancelOrderResponse struct {
440441

441442
// QueryOrderData holds query order data
442443
type QueryOrderData struct {
443-
Code int `json:"code"`
444-
Msg string `json:"msg"`
445-
Symbol string `json:"symbol"`
446-
OrderID int64 `json:"orderId"`
447-
ClientOrderID string `json:"clientOrderId"`
448-
Price float64 `json:"price,string"`
449-
OrigQty float64 `json:"origQty,string"`
450-
ExecutedQty float64 `json:"executedQty,string"`
451-
Status string `json:"status"`
452-
TimeInForce string `json:"timeInForce"`
453-
Type string `json:"type"`
454-
Side string `json:"side"`
455-
StopPrice float64 `json:"stopPrice,string"`
456-
IcebergQty float64 `json:"icebergQty,string"`
457-
Time types.Time `json:"time"`
458-
IsWorking bool `json:"isWorking"`
459-
CummulativeQuoteQty float64 `json:"cummulativeQuoteQty,string"`
460-
OrderListID int64 `json:"orderListId"`
461-
OrigQuoteOrderQty float64 `json:"origQuoteOrderQty,string"`
462-
UpdateTime types.Time `json:"updateTime"`
444+
Code int `json:"code"`
445+
Msg string `json:"msg"`
446+
Symbol string `json:"symbol"`
447+
OrderID int64 `json:"orderId"`
448+
ClientOrderID string `json:"clientOrderId"`
449+
Price float64 `json:"price,string"`
450+
OrigQty float64 `json:"origQty,string"`
451+
ExecutedQty float64 `json:"executedQty,string"`
452+
Status order.Status `json:"status"`
453+
TimeInForce string `json:"timeInForce"`
454+
Type order.Type `json:"type"`
455+
Side order.Side `json:"side"`
456+
StopPrice float64 `json:"stopPrice,string"`
457+
IcebergQty float64 `json:"icebergQty,string"`
458+
Time types.Time `json:"time"`
459+
IsWorking bool `json:"isWorking"`
460+
CummulativeQuoteQty float64 `json:"cummulativeQuoteQty,string"`
461+
OrderListID int64 `json:"orderListId"`
462+
OrigQuoteOrderQty float64 `json:"origQuoteOrderQty,string"`
463+
UpdateTime types.Time `json:"updateTime"`
463464
}
464465

465466
// Balance holds query order data
466467
type Balance struct {
467-
Asset string `json:"asset"`
468+
Asset currency.Code `json:"asset"`
468469
Free decimal.Decimal `json:"free"`
469470
Locked decimal.Decimal `json:"locked"`
470471
}
@@ -496,12 +497,12 @@ type MarginAccount struct {
496497

497498
// MarginAccountAsset holds each individual margin account asset
498499
type MarginAccountAsset struct {
499-
Asset string `json:"asset"`
500-
Borrowed float64 `json:"borrowed,string"`
501-
Free float64 `json:"free,string"`
502-
Interest float64 `json:"interest,string"`
503-
Locked float64 `json:"locked,string"`
504-
NetAsset float64 `json:"netAsset,string"`
500+
Asset currency.Code `json:"asset"`
501+
Borrowed float64 `json:"borrowed,string"`
502+
Free float64 `json:"free,string"`
503+
Interest float64 `json:"interest,string"`
504+
Locked float64 `json:"locked,string"`
505+
NetAsset float64 `json:"netAsset,string"`
505506
}
506507

507508
// RequestParamsOrderType trade order type
@@ -729,18 +730,18 @@ type WithdrawResponse struct {
729730

730731
// WithdrawStatusResponse defines a withdrawal status response
731732
type WithdrawStatusResponse struct {
732-
Address string `json:"address"`
733-
Amount float64 `json:"amount,string"`
734-
ApplyTime types.Time `json:"applyTime"`
735-
Coin string `json:"coin"`
736-
ID string `json:"id"`
737-
WithdrawOrderID string `json:"withdrawOrderId"`
738-
Network string `json:"network"`
739-
TransferType uint8 `json:"transferType"`
740-
Status int64 `json:"status"`
741-
TransactionFee float64 `json:"transactionFee,string"`
742-
TransactionID string `json:"txId"`
743-
ConfirmNumber int64 `json:"confirmNo"`
733+
Address string `json:"address"`
734+
Amount float64 `json:"amount,string"`
735+
ApplyTime types.Time `json:"applyTime"`
736+
Coin currency.Code `json:"coin"`
737+
ID string `json:"id"`
738+
WithdrawOrderID string `json:"withdrawOrderId"`
739+
Network string `json:"network"`
740+
TransferType uint8 `json:"transferType"`
741+
Status int64 `json:"status"`
742+
TransactionFee float64 `json:"transactionFee,string"`
743+
TransactionID string `json:"txId"`
744+
ConfirmNumber int64 `json:"confirmNo"`
744745
}
745746

746747
// DepositAddress stores the deposit address info
@@ -799,39 +800,39 @@ type WsBalanceUpdateData struct {
799800

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

837838
// WsListStatusData defines websocket account listing status data

exchanges/binance/binance_ufutures.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,19 +1010,12 @@ func (b *Binance) FetchUSDTMarginExchangeLimits(ctx context.Context) ([]order.Mi
10101010

10111011
limits := make([]order.MinMaxLevel, 0, len(usdtFutures.Symbols))
10121012
for x := range usdtFutures.Symbols {
1013-
var cp currency.Pair
1014-
cp, err = currency.NewPairFromStrings(usdtFutures.Symbols[x].BaseAsset,
1015-
usdtFutures.Symbols[x].QuoteAsset)
1016-
if err != nil {
1017-
return nil, err
1018-
}
1019-
10201013
if len(usdtFutures.Symbols[x].Filters) < 7 {
10211014
continue
10221015
}
10231016

10241017
limits = append(limits, order.MinMaxLevel{
1025-
Pair: cp,
1018+
Pair: currency.NewPair(usdtFutures.Symbols[x].BaseAsset, usdtFutures.Symbols[x].QuoteAsset),
10261019
Asset: asset.USDTMarginedFutures,
10271020
MinPrice: usdtFutures.Symbols[x].Filters[0].MinPrice,
10281021
MaxPrice: usdtFutures.Symbols[x].Filters[0].MaxPrice,

exchanges/binance/binance_websocket.go

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -224,42 +224,10 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
224224
if err != nil {
225225
return err
226226
}
227-
var feeAsset currency.Code
228-
if data.CommissionAsset != "" {
229-
feeAsset = currency.NewCode(data.CommissionAsset)
230-
}
231-
orderID := strconv.FormatInt(data.OrderID, 10)
232-
var orderStatus order.Status
233-
orderStatus, err = stringToOrderStatus(data.OrderStatus)
234-
if err != nil {
235-
b.Websocket.DataHandler <- order.ClassificationError{
236-
Exchange: b.Name,
237-
OrderID: orderID,
238-
Err: err,
239-
}
240-
}
241227
clientOrderID := data.ClientOrderID
242-
if orderStatus == order.Cancelled {
228+
if data.OrderStatus == order.Cancelled {
243229
clientOrderID = data.CancelledClientOrderID
244230
}
245-
var orderType order.Type
246-
orderType, err = order.StringToOrderType(data.OrderType)
247-
if err != nil {
248-
b.Websocket.DataHandler <- order.ClassificationError{
249-
Exchange: b.Name,
250-
OrderID: orderID,
251-
Err: err,
252-
}
253-
}
254-
var orderSide order.Side
255-
orderSide, err = order.StringToOrderSide(data.Side)
256-
if err != nil {
257-
b.Websocket.DataHandler <- order.ClassificationError{
258-
Exchange: b.Name,
259-
OrderID: orderID,
260-
Err: err,
261-
}
262-
}
263231
b.Websocket.DataHandler <- &order.Detail{
264232
Price: data.Price,
265233
Amount: data.Quantity,
@@ -269,13 +237,13 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
269237
Cost: data.CumulativeQuoteTransactedQuantity,
270238
CostAsset: pair.Quote,
271239
Fee: data.Commission,
272-
FeeAsset: feeAsset,
240+
FeeAsset: data.CommissionAsset,
273241
Exchange: b.Name,
274-
OrderID: orderID,
242+
OrderID: strconv.FormatInt(data.OrderID, 10),
275243
ClientOrderID: clientOrderID,
276-
Type: orderType,
277-
Side: orderSide,
278-
Status: orderStatus,
244+
Type: data.OrderType,
245+
Side: data.Side,
246+
Status: data.OrderStatus,
279247
AssetType: assetType,
280248
Date: data.OrderCreationTime.Time(),
281249
LastUpdated: data.TransactionTime.Time(),

0 commit comments

Comments
 (0)