Skip to content

Commit

Permalink
fix func: bnc.CmFuturesWsPublicMsgUnmarshaler, bnc.UmFuturesWsPublicM…
Browse files Browse the repository at this point in the history
…sgUnmarshaler
  • Loading branch information
dwdwow committed Jul 31, 2024
1 parent ee1d6df commit 999fe04
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
8 changes: 4 additions & 4 deletions bnc/ws_pub_clt_fu_mar_pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type WsMarkPriceStream struct {
EventType WsEvent `json:"e"`
EventTime int64 `json:"E"`
Symbol string `json:"s"`
MarkPrice float64 `json:"p,string"`
EstimatedSettlePrice float64 `json:"P,string"`
IndexPrice float64 `json:"i,string"`
FundingRate float64 `json:"r,string"`
MarkPrice string `json:"p"`
EstimatedSettlePrice string `json:"P"`
IndexPrice string `json:"i"`
FundingRate string `json:"r"`
NextFundingTime int64 `json:"T"`
}

Expand Down
9 changes: 9 additions & 0 deletions bnc/ws_pub_unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func UmFuturesWsPublicMsgUnmarshaler(e WsEvent, isArray bool, data []byte) (any,
}
return unmarshal[WsMarkPriceStream](data)
case WsEventForceOrder:
if isArray {
return unmarshal[[]WsLiquidationOrderStream](data)
}
return unmarshal[WsLiquidationOrderStream](data)
case WsEventKline:
return unmarshal[WsKlineStream](data)
Expand All @@ -63,8 +66,14 @@ func CmFuturesWsPublicMsgUnmarshaler(e WsEvent, isArray bool, data []byte) (any,
case WsEventIndexPriceUpdate:
return unmarshal[WsCMIndexPriceStream](data)
case WsEventMarkPriceUpdate:
if isArray {
return unmarshal[[]WsMarkPriceStream](data)
}
return unmarshal[WsMarkPriceStream](data)
case WsEventForceOrder:
if isArray {
return unmarshal[[]WsLiquidationOrderStream](data)
}
return unmarshal[WsLiquidationOrderStream](data)
case WsEventKline:
return unmarshal[WsKlineStream](data)
Expand Down
41 changes: 29 additions & 12 deletions bnc/ws_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bnc

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -63,7 +62,7 @@ func TestSpotPublicWsClient(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(msg.Data)
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -80,7 +79,7 @@ func TestUmFuturesPublicWsClient(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(msg.Data)
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -97,7 +96,7 @@ func TestCmFuturesPublicWsClient(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(msg.Data)
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -115,7 +114,7 @@ func TestWsClient_SubTrade(t *testing.T) {
t.Error(msg.Err)
break
}
fmt.Printf("%+v\n", msg.Data)
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -133,7 +132,7 @@ func TestWsClient_SubAggTrade(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(msg.Data)
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -151,7 +150,7 @@ func TestWsClient_SubKline(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -169,7 +168,7 @@ func TestWsClient_SubDepthUpdate(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -187,7 +186,25 @@ func TestWsClient_SubMarkPrice1s(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

func TestWsClient_SubAllMarkPrice1s(t *testing.T) {
ws := NewWsClient(CmFuturesWsCfg, nil, nil)
err := ws.start()
props.PanicIfNotNil(err)
err = ws.SubAllMarkPriceStream1s()
props.PanicIfNotNil(err)
sub, err := ws.SubAllMarkPrice1s()
props.PanicIfNotNil(err)
for {
msg := <-sub.Chan()
if msg.Err != nil {
t.Error(msg.Err)
break
}
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -205,7 +222,7 @@ func TestWsClient_SubCMIndexPrice1s(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -223,7 +240,7 @@ func TestWsClient_SubLiquidationOrder(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

Expand All @@ -241,6 +258,6 @@ func TestWsClient_SubAllMarketLiquidationOrder(t *testing.T) {
t.Error(msg.Err)
break
}
t.Log(fmt.Sprintf("%+v", msg.Data))
t.Logf("%+v", msg.Data)
}
}

0 comments on commit 999fe04

Please sign in to comment.