Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Oct 28, 2024
1 parent 0de194b commit 2a8075d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 99 deletions.
6 changes: 0 additions & 6 deletions exchanges/huobi/huobi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,6 @@ type WsAuthenticatedOrdersResponse struct {
Data []WsAuthenticatedOrdersResponseData `json:"data"`
}

// WsOldOrderUpdate response from Orders authenticated subscription
type WsOldOrderUpdate struct {
wsSubResp
Data WsAuthenticatedOrdersResponseData `json:"data"`
}

// WsAuthenticatedOrdersResponseData order data
type WsAuthenticatedOrdersResponseData struct {
SeqID int64 `json:"seq-id"`
Expand Down
166 changes: 73 additions & 93 deletions exchanges/huobi/huobi_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,95 +169,10 @@ func (h *HUOBI) wsHandleData(respRaw []byte) error {
return h.wsHandleChannelMsgs(s, respRaw)
}

switch {
/*
case strings.EqualFold(msg.Op, authOp):
h.Websocket.SetCanUseAuthenticatedEndpoints(true)
// Auth captured
return nil
case strings.EqualFold(msg.Topic, "accounts"):
var response WsAuthenticatedAccountsResponse
err := json.Unmarshal(respRaw, &response)
if err != nil {
return err
}
h.Websocket.DataHandler <- response
case strings.Contains(msg.Topic, "orders") &&
strings.Contains(msg.Topic, "update"):
var response WsAuthenticatedOrdersUpdateResponse
err := json.Unmarshal(respRaw, &response)
if err != nil {
return err
}
data := strings.Split(response.Topic, ".")
if len(data) < 2 {
return errors.New(h.Name +
" - currency could not be extracted from response")
}
orderID := strconv.FormatInt(response.Data.OrderID, 10)
var oSide order.Side
oSide, err = stringToOrderSide(response.Data.OrderType)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var oType order.Type
oType, err = stringToOrderType(response.Data.OrderType)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var oStatus order.Status
oStatus, err = stringToOrderStatus(response.Data.OrderState)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var p currency.Pair
var a asset.Item
p, a, err = h.GetRequestFormattedPairAndAssetType(data[1])
if err != nil {
return err
}
h.Websocket.DataHandler <- &order.Detail{
Price: response.Data.Price,
Amount: response.Data.UnfilledAmount + response.Data.FilledAmount,
ExecutedAmount: response.Data.FilledAmount,
RemainingAmount: response.Data.UnfilledAmount,
Exchange: h.Name,
OrderID: orderID,
Type: oType,
Side: oSide,
Status: oStatus,
AssetType: a,
LastUpdated: time.Unix(response.Timestamp*1000, 0),
Pair: p,
}
case strings.Contains(msg.Topic, "orders"):
var response WsOldOrderUpdate
err := json.Unmarshal(respRaw, &response)
if err != nil {
return err
}
h.Websocket.DataHandler <- response
*/
default:
h.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: h.Name + stream.UnhandledMessage + string(respRaw),
}
return nil
h.Websocket.DataHandler <- stream.UnhandledMessageWarning{
Message: h.Name + stream.UnhandledMessage + string(respRaw),
}

return nil
}

Expand Down Expand Up @@ -294,8 +209,19 @@ func (h *HUOBI) wsHandleChannelMsgs(s *subscription.Subscription, respRaw []byte
return h.wsHandleCandleMsg(s, respRaw)
case subscription.AllTradesChannel:
return h.wsHandleAllTradesMsg(s, respRaw)
case subscription.MyAccountChannel:
return h.wsHandleMyAccountMsg(s, respRaw)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / lint

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)

Check failure on line 213 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

h.wsHandleMyAccountMsg undefined (type *HUOBI has no field or method wsHandleMyAccountMsg)
case subscription.MyOrdersChannel, subscription.MyTradesChannel:
return h.wsHandleMyTradesMsg(s, respRaw)

Check failure on line 215 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

h.wsHandleMyTradesMsg undefined (type *HUOBI has no field or method wsHandleMyTradesMsg)

Check failure on line 215 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

h.wsHandleMyTradesMsg undefined (type *HUOBI has no field or method wsHandleMyTradesMsg)

Check failure on line 215 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

h.wsHandleMyTradesMsg undefined (type *HUOBI has no field or method wsHandleMyTradesMsg)

Check failure on line 215 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

h.wsHandleMyTradesMsg undefined (type *HUOBI has no field or method wsHandleMyTradesMsg)

Check failure on line 215 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

h.wsHandleMyTradesMsg undefined (type *HUOBI has no field or method wsHandleMyTradesMsg)

var response WsOldOrderUpdate

Check failure on line 217 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

undefined: WsOldOrderUpdate

Check failure on line 217 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

undefined: WsOldOrderUpdate

Check failure on line 217 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

undefined: WsOldOrderUpdate

Check failure on line 217 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

undefined: WsOldOrderUpdate

Check failure on line 217 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

undefined: WsOldOrderUpdate
err := json.Unmarshal(respRaw, &response)
if err != nil {
return err
}
h.Websocket.DataHandler <- response
}
return nil
return fmt.Errorf("%w: %w", common.ErrNotSupported, s.Channel)

Check failure on line 224 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

undefined: common.ErrNotSupported

Check failure on line 224 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

undefined: common.ErrNotSupported

Check failure on line 224 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

undefined: common.ErrNotSupported

Check failure on line 224 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

undefined: common.ErrNotSupported

Check failure on line 224 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

undefined: common.ErrNotSupported
}

func (h *HUOBI) wsHandleCandleMsg(s *subscription.Subscription, respRaw []byte) error {
Expand Down Expand Up @@ -415,6 +341,60 @@ func (h *HUOBI) wsHandleOrderbookMsg(s *subscription.Subscription, respRaw []byt
return h.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
}

func (h *HUOBI) wsHandleMyOrdersMsg(respRaw []byte) error {
var response WsAuthenticatedOrdersUpdateResponse
if err := json.Unmarshal(respRaw, &response); err != nil {
return err
}
orderID := strconv.FormatInt(response.Data.OrderID, 10)
oSide, err := stringToOrderSide(response.Data.OrderType)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var oType order.Type
oType, err = stringToOrderType(response.Data.OrderType)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var oStatus order.Status
oStatus, err = stringToOrderStatus(response.Data.OrderState)
if err != nil {
h.Websocket.DataHandler <- order.ClassificationError{
Exchange: h.Name,
OrderID: orderID,
Err: err,
}
}
var p currency.Pair
var a asset.Item
p, a, err = h.GetRequestFormattedPairAndAssetType(data[1])

Check failure on line 378 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

undefined: data

Check failure on line 378 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

undefined: data

Check failure on line 378 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

undefined: data

Check failure on line 378 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

undefined: data

Check failure on line 378 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

undefined: data
if err != nil {
return err
}
h.Websocket.DataHandler <- &order.Detail{
Price: response.Data.Price,
Amount: response.Data.UnfilledAmount + response.Data.FilledAmount,
ExecutedAmount: response.Data.FilledAmount,
RemainingAmount: response.Data.UnfilledAmount,
Exchange: h.Name,
OrderID: orderID,
Type: oType,
Side: oSide,
Status: oStatus,
AssetType: a,
LastUpdated: time.Unix(response.Timestamp*1000, 0),
Pair: p,
}
}

Check failure on line 396 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

missing return

Check failure on line 396 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

missing return

Check failure on line 396 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

missing return

Check failure on line 396 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

missing return

Check failure on line 396 in exchanges/huobi/huobi_websocket.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

missing return

// generateSubscriptions returns a list of subscriptions from the configured subscriptions feature
func (h *HUOBI) generateSubscriptions() (subscription.List, error) {
return h.Features.Subscriptions.ExpandTemplates(h)
Expand Down Expand Up @@ -472,19 +452,19 @@ func (h *HUOBI) manageSubs(op string, subs subscription.List) error {
}
if err != nil {
if op == wsSubOp {
h.Websocket.RemoveSubscriptions(c, s)
_ = h.Websocket.RemoveSubscriptions(c, s)
}
return fmt.Errorf("%s: %w", s, err)
}
if op == wsSubOp {
s.SetState(subscription.SubscribedState)
err = s.SetState(subscription.SubscribedState)
if h.Verbose {
log.Debugf(log.ExchangeSys, "%s Subscribed to %s", h.Name, s)
}
} else {
h.Websocket.RemoveSubscriptions(c, s)
err = h.Websocket.RemoveSubscriptions(c, s)
}
return nil
return err
}

func (h *HUOBI) wsGenerateSignature(creds *account.Credentials, timestamp string) ([]byte, error) {
Expand Down

0 comments on commit 2a8075d

Please sign in to comment.