mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
websocket: Remove GenerateMessageID (#2008)
* Exchanges: Remove example BespokeGenerateMessageID * Okx: Replace conn.RequestIDGenerator with MesssageID Continued overall direction to remove the closed-loop of e => conn => e roundtrip for message ids * Exchanges: Add MessageSequence This method removes the either/or nature of message id generation. We don't tie the message ids to connections, or to anything. Consumers just call whichever they want, or even combine them as they want. Anything more complicated will need a separate installation anyway * GateIO: Split usage of MessageID and MessageSequence * Binance: Switch to UUID message IDs * Kraken: Switch to e.MessageSequence * Kucoin: Switch to MessageID * HitBTC: Switch to UUIDv7 for ws message ID * Bybit: Switch to UUIDv7 for ws message ID * Bitfinex: Switch to UUIDv7 and MessageSequence Tested CID - It accepts 53 bits only for an int, so MessageSequence makes sense. Can't use MessageID * Websocket: Remove now unused MessageID function Moved all MessageID usage into funcs and onto base methods, to remove the closed loop of message IDs * Docs: Update guidance for message signatures
This commit is contained in:
@@ -568,7 +568,7 @@ func TestWsGetCurrenciesJSON(t *testing.T) {
|
||||
"delisted": false,
|
||||
"payoutFee": "0.001"
|
||||
},
|
||||
"id": 123
|
||||
"id": "c4ce77f5-1c50-435a-b623-4961191ca129"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -589,7 +589,7 @@ func TestWsGetSymbolsJSON(t *testing.T) {
|
||||
"provideLiquidityRate": "-0.0001",
|
||||
"feeCurrency": "BTC"
|
||||
},
|
||||
"id": 123
|
||||
"id": "1c847290-b366-412b-b8f5-dc630ed5b147"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -744,7 +744,7 @@ func TestWsSubmitOrderJSON(t *testing.T) {
|
||||
"updatedAt": "2017-10-20T12:29:43.166Z",
|
||||
"reportType": "new"
|
||||
},
|
||||
"id": 123
|
||||
"id": "99f55c70-1166-49a7-87e9-3b54a00ad893"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -771,7 +771,7 @@ func TestWsCancelOrderJSON(t *testing.T) {
|
||||
"updatedAt": "2017-10-20T12:31:26.174Z",
|
||||
"reportType": "canceled"
|
||||
},
|
||||
"id": 123
|
||||
"id": "2ce46937-2770-4453-ac99-ee87939bf5bb"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -799,7 +799,7 @@ func TestWsCancelReplaceJSON(t *testing.T) {
|
||||
"reportType": "replaced",
|
||||
"originalRequestClientOrderId": "9cbe79cb6f864b71a811402a48d4b5b1"
|
||||
},
|
||||
"id": 123
|
||||
"id": "91e925d3-3b95-4e29-8ae7-938fd5006709"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -827,7 +827,7 @@ func TestWsGetTradesRequestResponse(t *testing.T) {
|
||||
"reserved": "0.00200000"
|
||||
}
|
||||
],
|
||||
"id": 123
|
||||
"id": "4b1f1391-215e-4d12-972c-5cea9d50edf4"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
@@ -857,7 +857,7 @@ func TestWsGetActiveOrdersRequestJSON(t *testing.T) {
|
||||
"originalRequestClientOrderId": "9cbe79cb6f864b71a811402a48d4b5b1"
|
||||
}
|
||||
],
|
||||
"id": 123
|
||||
"id": "9e67b440-2eec-445a-be3a-e81f962c8391"
|
||||
}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
|
||||
@@ -283,7 +283,7 @@ type capture struct {
|
||||
Method string `json:"method,omitempty"`
|
||||
Result any `json:"result"`
|
||||
Error ResponseError `json:"error"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// ResponseError contains error codes from JSON responses
|
||||
@@ -297,7 +297,7 @@ type WsRequest struct {
|
||||
JSONRPCVersion string `json:"jsonrpc,omitempty"`
|
||||
Method string `json:"method"`
|
||||
Params *WsParams `json:"params,omitempty"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// WsParams are websocket params for a request
|
||||
@@ -359,7 +359,7 @@ type WsTrade struct {
|
||||
type WsLoginRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsLoginData `json:"params"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// WsLoginData sets credentials for WsLoginRequest
|
||||
@@ -378,17 +378,17 @@ type wsActiveOrdersResponse struct {
|
||||
|
||||
type wsReportResponse struct {
|
||||
OrderData wsOrderData `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type wsOrderResponse struct {
|
||||
OrderData wsOrderData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type wsActiveOrderRequestResponse struct {
|
||||
OrderData []wsOrderData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// wsOrderData Active order data for WsActiveOrdersResponse
|
||||
@@ -446,12 +446,12 @@ type WsReportResponseData struct {
|
||||
type WsSubmitOrderRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsSubmitOrderRequestData `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// WsSubmitOrderRequestData WS request data
|
||||
type WsSubmitOrderRequestData struct {
|
||||
ClientOrderID int64 `json:"clientOrderId,string,omitempty"`
|
||||
ClientOrderID string `json:"clientOrderId,omitempty"`
|
||||
Symbol string `json:"symbol"`
|
||||
Side string `json:"side"`
|
||||
Price float64 `json:"price,string"`
|
||||
@@ -461,7 +461,7 @@ type WsSubmitOrderRequestData struct {
|
||||
// WsSubmitOrderSuccessResponse WS response
|
||||
type WsSubmitOrderSuccessResponse struct {
|
||||
Result WsSubmitOrderSuccessResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ type WsSubmitOrderErrorResponseData struct {
|
||||
// WsCancelOrderResponse WS response
|
||||
type WsCancelOrderResponse struct {
|
||||
Result WsCancelOrderResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ type WsCancelOrderResponseData struct {
|
||||
// WsReplaceOrderResponse WS response
|
||||
type WsReplaceOrderResponse struct {
|
||||
Result WsReplaceOrderResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ type WsReplaceOrderResponseData struct {
|
||||
// WsGetActiveOrdersResponse WS response
|
||||
type WsGetActiveOrdersResponse struct {
|
||||
Result []WsGetActiveOrdersResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -576,7 +576,7 @@ type WsGetActiveOrdersResponseData struct {
|
||||
// WsGetTradingBalanceResponse WS response
|
||||
type WsGetTradingBalanceResponse struct {
|
||||
Result []WsGetTradingBalanceResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ type WsGetTradingBalanceResponseData struct {
|
||||
type WsCancelOrderRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsCancelOrderRequestData `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// WsCancelOrderRequestData WS request data
|
||||
@@ -603,7 +603,7 @@ type WsCancelOrderRequestData struct {
|
||||
type WsReplaceOrderRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsReplaceOrderRequestData `json:"params"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
// WsReplaceOrderRequestData WS request data
|
||||
@@ -618,7 +618,7 @@ type WsReplaceOrderRequestData struct {
|
||||
type WsGetCurrenciesRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsGetCurrenciesRequestParameters `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// WsGetCurrenciesRequestParameters parameters
|
||||
@@ -629,7 +629,7 @@ type WsGetCurrenciesRequestParameters struct {
|
||||
// WsGetCurrenciesResponse currency response
|
||||
type WsGetCurrenciesResponse struct {
|
||||
Result WsGetCurrenciesResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -652,7 +652,7 @@ type WsGetCurrenciesResponseData struct {
|
||||
type WsGetSymbolsRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsGetSymbolsRequestParameters `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// WsGetSymbolsRequestParameters request parameters
|
||||
@@ -663,7 +663,7 @@ type WsGetSymbolsRequestParameters struct {
|
||||
// WsGetSymbolsResponse symbol response
|
||||
type WsGetSymbolsResponse struct {
|
||||
Result WsGetSymbolsResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ type WsGetSymbolsResponseData struct {
|
||||
type WsGetTradesRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params WsGetTradesRequestParameters `json:"params"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// WsGetTradesRequestParameters trade request params
|
||||
@@ -698,7 +698,7 @@ type WsGetTradesRequestParameters struct {
|
||||
type WsGetTradesResponse struct {
|
||||
Jsonrpc string `json:"jsonrpc"`
|
||||
Result WsGetTradesResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Error ResponseError `json:"error"`
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func (e *Exchange) wsGetTableName(respRaw []byte) (string, error) {
|
||||
if init.Error.Code == errAuthFailed {
|
||||
e.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
}
|
||||
if init.ID > 0 {
|
||||
if init.ID != "" {
|
||||
if e.Websocket.Match.IncomingWithData(init.ID, respRaw) {
|
||||
return "", nil
|
||||
}
|
||||
@@ -519,7 +519,7 @@ func (e *Exchange) manageSubs(ctx context.Context, op string, subs subscription.
|
||||
for _, s := range subs {
|
||||
r := WsRequest{
|
||||
JSONRPCVersion: rpcVersion,
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s.QualifiedChannel), &r); err != nil {
|
||||
errs = common.AppendError(errs, err)
|
||||
@@ -565,7 +565,7 @@ func (e *Exchange) wsLogin(ctx context.Context) error {
|
||||
Nonce: n,
|
||||
Signature: hex.EncodeToString(hmac),
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
|
||||
err = e.Websocket.Conn.SendJSONMessage(ctx, request.Unset, req)
|
||||
@@ -583,7 +583,7 @@ func (e *Exchange) wsPlaceOrder(ctx context.Context, pair currency.Pair, side st
|
||||
return nil, fmt.Errorf("%v not authenticated, cannot place order", e.Name)
|
||||
}
|
||||
|
||||
id := e.Websocket.Conn.GenerateMessageID(false)
|
||||
id := e.MessageID()
|
||||
fPair, err := e.FormatExchangeCurrency(pair, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -625,7 +625,7 @@ func (e *Exchange) wsCancelOrder(ctx context.Context, clientOrderID string) (*Ws
|
||||
Params: WsCancelOrderRequestData{
|
||||
ClientOrderID: clientOrderID,
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -655,7 +655,7 @@ func (e *Exchange) wsReplaceOrder(ctx context.Context, clientOrderID string, qua
|
||||
Quantity: quantity,
|
||||
Price: price,
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -680,7 +680,7 @@ func (e *Exchange) wsGetActiveOrders(ctx context.Context) (*wsActiveOrdersRespon
|
||||
req := WsReplaceOrderRequest{
|
||||
Method: "getOrders",
|
||||
Params: WsReplaceOrderRequestData{},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -705,7 +705,7 @@ func (e *Exchange) wsGetTradingBalance(ctx context.Context) (*WsGetTradingBalanc
|
||||
req := WsReplaceOrderRequest{
|
||||
Method: "getTradingBalance",
|
||||
Params: WsReplaceOrderRequestData{},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -729,7 +729,7 @@ func (e *Exchange) wsGetCurrencies(ctx context.Context, currencyItem currency.Co
|
||||
Params: WsGetCurrenciesRequestParameters{
|
||||
Currency: currencyItem,
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -758,7 +758,7 @@ func (e *Exchange) wsGetSymbols(ctx context.Context, c currency.Pair) (*WsGetSym
|
||||
Params: WsGetSymbolsRequestParameters{
|
||||
Symbol: fPair.String(),
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
@@ -790,7 +790,7 @@ func (e *Exchange) wsGetTrades(ctx context.Context, c currency.Pair, limit int64
|
||||
Sort: sort,
|
||||
By: by,
|
||||
},
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.MessageID(),
|
||||
}
|
||||
resp, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -443,7 +443,7 @@ func (e *Exchange) SubmitOrder(ctx context.Context, o *order.Submit) (*order.Sub
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderID = strconv.FormatInt(response.ID, 10)
|
||||
orderID = response.ID
|
||||
if response.Result.CumQuantity == o.Amount {
|
||||
status = order.Filled
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user