thrasher-corp / gocryptotrader

A cryptocurrency trading bot and framework supporting multiple exchanges written in Golang.
MIT License
2.98k stars 799 forks source link

stream/match: Reduce complexity and limit locking when match occurs #1581

Closed shazbert closed 2 weeks ago

shazbert commented 1 month ago

PR Description

Inline lock and cleanup when match occurs, reduce the need to lock and close unless there is a timeout.

Fixes # (issue)

Type of change

Please delete options that are not relevant and add an x in [] as item is complete.

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and also consider improving test coverage whilst working on a certain feature or package.

Checklist

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 53.84615% with 54 lines in your changes missing coverage. Please review.

Project coverage is 36.30%. Comparing base (deaee80) to head (3cf852a). Report is 10 commits behind head on master.

Files Patch % Lines
exchanges/coinut/coinut_websocket.go 0.00% 10 Missing :warning:
exchanges/stream/websocket_connection.go 76.92% 6 Missing and 3 partials :warning:
exchanges/hitbtc/hitbtc_websocket.go 0.00% 8 Missing :warning:
exchanges/kraken/kraken_websocket.go 14.28% 6 Missing :warning:
exchanges/bitfinex/bitfinex_websocket.go 33.33% 4 Missing :warning:
exchanges/bybit/bybit_websocket.go 0.00% 3 Missing :warning:
exchanges/huobi/huobi_websocket.go 0.00% 3 Missing :warning:
exchanges/deribit/deribit_websocket.go 0.00% 2 Missing :warning:
exchanges/gateio/gateio_ws_delivery_futures.go 0.00% 2 Missing :warning:
exchanges/gateio/gateio_ws_futures.go 0.00% 2 Missing :warning:
... and 4 more
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581/graphs/tree.svg?width=650&height=150&src=pr&token=41784B23TS&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp)](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp) ```diff @@ Coverage Diff @@ ## master #1581 +/- ## ========================================== - Coverage 36.31% 36.30% -0.02% ========================================== Files 422 422 Lines 183068 183036 -32 ========================================== - Hits 66487 66447 -40 - Misses 108518 108530 +12 + Partials 8063 8059 -4 ``` | [Files](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp) | Coverage Ξ” | | |---|---|---| | [exchanges/binance/binance\_websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fbinance%2Fbinance_websocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2JpbmFuY2UvYmluYW5jZV93ZWJzb2NrZXQuZ28=) | `56.85% <100.00%> (ΓΈ)` | | | [exchanges/deribit/deribit\_websocket\_eps.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fderibit%2Fderibit_websocket_eps.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2RlcmliaXQvZGVyaWJpdF93ZWJzb2NrZXRfZXBzLmdv) | `45.38% <100.00%> (ΓΈ)` | | | [exchanges/kucoin/kucoin\_websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fkucoin%2Fkucoin_websocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2t1Y29pbi9rdWNvaW5fd2Vic29ja2V0Lmdv) | `55.51% <100.00%> (+2.20%)` | :arrow_up: | | [exchanges/stream/stream\_match.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fstream%2Fstream_match.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL3N0cmVhbS9zdHJlYW1fbWF0Y2guZ28=) | `100.00% <100.00%> (ΓΈ)` | | | [exchanges/stream/websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fstream%2Fwebsocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL3N0cmVhbS93ZWJzb2NrZXQuZ28=) | `84.55% <ΓΈ> (ΓΈ)` | | | [exchanges/gateio/gateio\_websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fgateio%2Fgateio_websocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2dhdGVpby9nYXRlaW9fd2Vic29ja2V0Lmdv) | `48.22% <0.00%> (+0.22%)` | :arrow_up: | | [exchanges/gateio/gateio\_ws\_option.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fgateio%2Fgateio_ws_option.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2dhdGVpby9nYXRlaW9fd3Nfb3B0aW9uLmdv) | `50.60% <0.00%> (+0.17%)` | :arrow_up: | | [exchanges/okcoin/okcoin\_websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fokcoin%2Fokcoin_websocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL29rY29pbi9va2NvaW5fd2Vic29ja2V0Lmdv) | `39.39% <0.00%> (ΓΈ)` | | | [exchanges/deribit/deribit\_websocket.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fderibit%2Fderibit_websocket.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2RlcmliaXQvZGVyaWJpdF93ZWJzb2NrZXQuZ28=) | `38.80% <0.00%> (ΓΈ)` | | | [exchanges/gateio/gateio\_ws\_delivery\_futures.go](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree&filepath=exchanges%2Fgateio%2Fgateio_ws_delivery_futures.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp#diff-ZXhjaGFuZ2VzL2dhdGVpby9nYXRlaW9fd3NfZGVsaXZlcnlfZnV0dXJlcy5nbw==) | `9.79% <0.00%> (ΓΈ)` | | | ... and [9 more](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp) | | ... and [31 files with indirect coverage changes](https://app.codecov.io/gh/thrasher-corp/gocryptotrader/pull/1581/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=thrasher-corp)