-
Notifications
You must be signed in to change notification settings - Fork 820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitfinex: Fix WS trade processing #1754
base: master
Are you sure you want to change the base?
Conversation
* Add handling for funding trades Fixes thrasher-corp#1746
0dd865c
to
cb416cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice stuff, not much from me.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1754 +/- ##
==========================================
+ Coverage 37.13% 37.37% +0.23%
==========================================
Files 414 415 +1
Lines 180198 178586 -1612
==========================================
- Hits 66925 66746 -179
+ Misses 105413 104042 -1371
+ Partials 7860 7798 -62
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my last nits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK.
It's been a year, and I'm still getting caught out by govet demanding I don't shadow a var I was deliberately shadowing. Made worse by an increase in clashes with stylecheck when they both want opposite things on the same line.
48ebaf7
to
f86fff4
Compare
@@ -1382,17 +1372,44 @@ func TestWsOrderBook(t *testing.T) { | |||
assert.ErrorIs(t, err, errNoSeqNo, "handleWSBookUpdate should send correct error") | |||
} | |||
|
|||
func TestWsTradeResponse(t *testing.T) { | |||
func TestWSAllTrades(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix test
data, ok := d[2].([]interface{}) | ||
if !ok { | ||
return errors.New("trade data type assertion error") | ||
var wsTrades []*wsTrade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this shadowed var name/the original string var name
if valueType != jsonparser.Array { | ||
errs = common.AppendError(errs, fmt.Errorf("%w `tradesSnapshot[1][*]`: %w `%s`", errParsingWSField, jsonparser.UnknownValueTypeError, valueType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little bit extra given that there is only one caller to this and its behind a gate checking if its an array. I am normally one for all checks should be within the function, but its that you just checked to get to this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this simplification?
func (b *Bitfinex) handleWSPublicTradesSnapshot(respRaw []byte) ([]*wsTrade, error) {
var trades []*wsTrade
err := json.Unmarshal(respRaw, &trades)
return trades, err
}
Where handleWSAllTrades
changes with:
k, valueType, _, err := jsonparser.Get(respRaw, "[1]")
...
if wsTrades, err = b.handleWSPublicTradesSnapshot(k); err != nil {
A lot less tangling of additional jsonparser functions, with added bonus of naked return removal
exchange Bitfinex websocket error - unhandled WS trade update event:
TestWs
instead ofTestWS
Fixes #1746
Progresses #1323 with a prototype
Type of change