* WS: Relay disconnect errors to subscribers
Subscribers probably care when the WS got disconncted.
Tell them and expose a method to test the error for matching
* Fix linter error
* orderbook: Check assignment of time values and reject if not set.
* linter: fix
* buffer: additional linter winter fixter
* Implement through pending exchanges
* finished push
* linty: minty
* gomod: tidy
* thrasher: nits
* glorious: nits
* orderbook: purge type now in favour of external call allocation
* orderbook: push last param
* orderbook: only 1 unlock call is needed
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
When Kraken has a disconnect or failure that sets SetCanUseAuthenticatedEndpoints(false),
it's never re-enabled when the websocket is reconnected
That means all subsequent requests would fall back to rest
* Kraken: Fix error on WS update without status
* Kraken: Fix parsing of WS updates without Desc
* Kraken: Fix WS market order handling
* Kraken: Fix tests in parallel using DataHandler
* WebsocketManager: Fix order summary printing
* Kraken: Fix parallel tests race with DataHandler
* Kraken: Issue a classification err on asset 404
* Kraken: Switch to testify and close fixture
* Bitfinex: Fix cancel/update order WS ack not seen
Fixes#1288
* Bitfinex: Fix ws Unsubscribe and Resubscribe
Unsubscribe needed to use the channel id.
Resubscribe needs to have the original subscription params.
* Bitfinex: Fix ws Trades Fees on te
The ws channel for authenticated Trades sends two types of update:
* te, Trade Executed
* tu, Trade Execution Update
Only the second one contains fee information.
[See the docs](https://docs.bitfinex.com/reference/ws-auth-trades)
This commit fixes:
`exchange Bitfinex websocket error - unable to type assert trade fee`
after an executed market trade on the te update
* Bitfinex: Fix error on ws auth ok
This fixes:
`Bitfinex Could not find an existing channel subscription: account Pair:
ChannelID: 0`
It's not clear from history why we'd want to store a reference to the
ubiquitous 0 channel like this, but it's definitely wrong, and anything
that attempts to get channel information about 0 chan needs to be fixed
anyway.
* Bitfinex: Refactor wsUpdate handling
This commit doesn't break out all the sub-updater, but attempts to do
something about the unmanagable size of ws update handling
* Binfinex: Fix linter issue on chanId casing
* Bitfinex: Fix linter outdent complaint
* Bitfinex: Fix linter issues on test
* Bitfinex: Fix TestWsTradingPairSnapshot chan lookup
* Bitfinex: Remove unnecessary WsAddSubs in test
* Bitfinex: Fix TestWsSubscribedResponse chan
* Bitfinex: Throw a specific error for bad event
* Bitfinex: WS Type assertions for positionSnapshots
* Bitfinex: tradeUpdate type assertion
* Bitfinex: Reinstate default subscriptions
* Bitfinex: Assert chan assetType is the same
* Bitfinex: Lowercase error string
* Bitfinex: Refactor WS eventType/chanId handling
* Bitfinex: Fix linter issues
* Bitfinex: Fix delimiter for pairs with more than 6 chars
* Bitfinex: Fix WS handling of subscribed symbols
This simplifies the handling of subscription symbols.
Now that we know the channel up front from handling the subscribed
response we can limit the parsing forms needed
* Bitfinex: Placate the linter
* Bitfinex: Disable margin assets for WS
Margin WS Currently not fully implemented and causes subscription collisions with spot
* Bitfinex: Fix parsing of 4 part funding keys
This improves overall handling and errors on a few current assumptions
about key structure
* Bitfinex: Linter fixes
* Bitfinex: Remove key parsing from assetPairFromSymbol
* Bitfinex: Use native error wrapping
* Bitfinex: Skip disabled assets in default ws subs
* Orderbook: Add GetDepth to Base
Base.GetDepth returns the concrete book of which Base is a copy
This is probably useful for immutably monitoring orderbook health and state
whereas FetchOrderbook would trigger a refresh.
* Orderbook: Reword GetDepth comment
* Orderbook: Add test for Base.GetDepth
This prevents the frequent (5x / hour) disconn/reconns we're seeing with a
10s or even 20s traffic timeout.
I'd like to base the interval on the traffic timeout / 2, but that's
non-trivial right now, and 8s isn't an excessive default
* starting public endpoints
* Adding public endpoints
* added public spot market endpoints
* websocket subscriptions updates
* websocket push data handlers completing
* linter fix
* Added funding private endpoints
* Adding authenticated account endpoints
* Added fiat and OTC-RFQ authenticated endpoints
* trading authenticated endpoints
* completing trade endpoints and add public wrapper endpoints
* Authenticated wrapper functions and corresponding unit test
* Adding authenticated websocket endpoint and fixing wrapper functions
* Documentation and exchange websocket update
* update websocket orderbook checksum handling
* linter issues fix and unit test update
* remove invalid orderbook endpoint and unit test
* Documentation, handlers, and model types update
* minot fix
* Minor fixes
* Updating unit tests and added missing endpoints
* Add missing credential check
* Minor unit test fixes
* fix minor linter issue
* add snaphot test unit test
* Fix on update checksum and documentation update
* update exchange, add UpdateOrderExecutionLimits, and update documentation
* Minor fix on tickers fetching
* Minor websocket fix and smaill unit tests
* Minor websocket and naming fixes
* uncomment default channels
* Fix type and unit test issues
* websocket channels and data handling update
* Update Advanced-Algo websocket handling and minor fixes
* documentation and minor code fixes
* Fix name changes
* documentation contribution update
* intervalToString method update
* fix exchange_wrapper_standard tests
* Fix minor issues based on exchange_wrapper_standards_test
* Fix wrapper extended candlestick check
* websocket orders fetching error check method update
* Exchange name check and change
* docs: Add missing contributors
---------
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* stream/buffer: Adds key map optimisation (cherry-pick)
* stream/buffer: Add buffer to DataHandler intermediary. Add field InitialUpdate bool to toggle when first update is seen for initial sync.
* whoops
* buffer: Add difference benchmarks for reference
* glorious: nits (reverting out of context changes)
* RM unused error that will be used later
* purge: benchmark
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
* fixes tests
* pair formats and extra fixes
* quick change before shazbert sees
* sneaky lint
* adds bybit mock testing and fixes test
* whoops
* error response instead
* classic forgetting to lint
* bybit live test no longer auto-records results
* ty thrasher- Update exchanges/bybit/bybit_wrapper.go
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
---------
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* Bitstamp: Fix orderbook snapshot blanking LastUpdate
Drive-By: Remove:
`Bitstamp BTC/USDT spot orderbook has zero bid price, filtering.`
It's unactionable and happens every snapshot right now
* Bitstamp: Use ob timestamps for LastUpdate
Obviously.
* SubmitOrder- order.Buy replaced with IsLong
Progresses #1270
* Btcmarkets: order.Buy and order.Sell changed to order.Bid and order.Ask
* Bithumb: SubmitOrder- order.Buy replaced with IsLong
Progresses #1270
* Binanceus: SubmitOrder- order.Buy replaced with IsLong
Progresses #1720
* Bistamp: SubmitOrder- order.Buy replaced with IsLong
Progresses #1270
* Bitfinex: Changed order Side to IsLong
* Binance:switch added to SubmitOrder
* Binance: Replaced Buy and Sell in SubmitOrder with IsLong and IsShort
* Binance:SubmitOrder if statement for order side simplified
* Bitfinex: Fix ws new/modify Order Fields
Fixes Type, Amount and Symbol for new order, and IsShort for modify
order
* Bitfinex: Fix ws order type for margin
Also unifies the pair symbol method to standardised fixCasing
* Fix lint warning on shadow err
* Bitfinex: Remove CustomID duplication for ws
* Kraken: Fix GetActiveOrders AssetType and CancelOrder wrappers
AssetType wasn't set when calling GetActiveOrders and no default case handling was in CancelOrder
* Kraken: Add basic CancelOrder wrapper asset coverage
* Kraken: Add AssetType to GetOrderInfo
* Kraken: Add order status for open orders
* Bitfinex: Order Execution Limits and Testing
* Bitfinex: added proposed changes
* Bitfinex: lint fixes- removed the unnecessary whitespace and replaced the value with indexing
* Bitfinex: Moved data len check before the string conversion, moved the error for the array conversion before the info len check
* Bitfinex: Change GetSiteInfoConfigData to return slice, add tests
* Bitfinex: Fixed lint issue by preallocating pairs
* kraken: fix websocket orderbook processing
* kraken: clean
* glorious: nits also add todo
* more: add required checksum to TODO for future, move variable to top
* glorious: get mad
* orderbook: fix retrieve issue
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
* Kraken: Load asset limits for pairs
* Kraken: Add test for spot order limit loading
* Kraken: move Limits to UpdateExecutionLimits
* Kraken: Whitespace fixed
* Kraken: added ErrNotYetImplemented for the futures
* Kraken: Fix FetchTradablePairs Loading Limits
* Kraken: changed the error to match the Go 1.13 error package
---------
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Kraken: Fix Balances reporting 0 Free
This switches to BalancesEx(tended) to get Held assets so we can
construct a Total, Held and Free.
Without this fix we get 0 balance from GetFree()
Haven't added tests because no construct for mocks and it's private
data. Considering adding mocks a bridge to far for this fix.
* Kraken: Simplify GetBalance
* Okx: Fix panic during shutdown due to race
Error:
```
panic: runtime error: slice bounds out of range [:13340] with capacity 8192
bufio.(*Reader).Read(0x14000038540, {0x1400059cffc?, 0x4?, 0x0?})
/usr/local/go/src/bufio/bufio.go:250 +0x33c
github.com/gorilla/websocket.(*messageReader).Read(0x1400098bb78, {0x1400059cffc, 0x4, 0x4})
/Users/gbjk/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:1050 +0x208
io.ReadAll({0x12f36c618, 0x1400098bb78})
/usr/local/go/src/io/io.go:701 +0xe4
io/ioutil.ReadAll(...)
/usr/local/go/src/io/ioutil/ioutil.go:27
github.com/gorilla/websocket.(*Conn).ReadMessage(0x3?)
/Users/gbjk/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:1097 +0x54
github.com/thrasher-corp/gocryptotrader/exchanges/stream.(*WebsocketConnection).ReadMessage(0x140006622d0)
/Users/gbjk/go/pkg/mod/github.com/gbjk/gocryptotrader@v0.0.0-20230619070715-ae6f283f6be6/exchanges/stream/websocket_connection.go:217 +0x30
github.com/thrasher-corp/gocryptotrader/exchanges/okx.(*Okx).wsFunnelConnectionData(0x140019321e0?, {0x106909450, 0x140006622d0})
/Users/gbjk/go/pkg/mod/github.com/gbjk/gocryptotrader@v0.0.0-20230619070715-ae6f283f6be6/exchanges/okx/okx_websocket.go:346 +0x94
created by github.com/thrasher-corp/gocryptotrader/exchanges/okx.(*Okx).WsConnect
/Users/gbjk/go/pkg/mod/github.com/gbjk/gocryptotrader@v0.0.0-20230619070715-ae6f283f6be6/exchanges/okx/okx_websocket.go:234 +0x134
exit status 2
```
This happens when there's a race in calls to bufio because it over-reads. See [this comment](https://github.com/golang/go/issues/42289#issuecomment-723393783)
Detected using go -race:
```
WARNING: DATA RACE
Read at 0x00c000818bc0 by goroutine 2156:
github.com/gorilla/websocket.(*Conn).NextReader()
/Users/gbjk/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:1000 +0x38
github.com/gorilla/websocket.(*Conn).ReadMessage()
/Users/gbjk/go/pkg/mod/github.com/gorilla/websocket@v1.5.0/conn.go:1093 +0x28
github.com/thrasher-corp/gocryptotrader/exchanges/stream.(*WebsocketConnection).ReadMessage()
/Users/gbjk/go/pkg/mod/github.com/gbjk/gocryptotrader@v0.0.0-20230619070715-ae6f283f6be6/exchanges/stream/websocket_connection.go:217 +0x44
github.com/thrasher-corp/gocryptotrader/exchanges/okx.(*Okx).wsFunnelConnectionData()
```
Because we started a new wsFunnelConnectionData for each re-connect.
This bug might apply to other exchanges.
* Okx: Fix websocket waitgroup going negative
Move the waitgroup additions to the actual places that use them
* Okx: Add nolint for revive
* Okx: Move wg Adds to outside goros
There is a risk of a race condition if we let the goros Add themselves.
* Okx: Simplify websocket reading
This fixes the issue that the WsRead and Multiplexer were intrinsically
linked to the websocket, even though they need to survive both
disconnects and Disable/Enables.
Messages are now handled in a goro, which means they might not be
sequential, but there's a very high chance that messages of the same
codepath will be handled sequentially. So orderbook, ticked and order
messages should be sequential
* Okx: Switch to blocking processing of ws msgs
* Okx: Remove nolint from Setup
Actioning a review comment: @gloriousCode prefers to avoid having to nolint this in favour of
a func call return.
* Okx: Remove redundant Wg use inside WsReadData
* Okx: Fix WsMultiplexer Re-Run() shutdown
* switch over to package defined const for time layout
* bump appveyor playa
* bumperino to latest while setting patherino
* whoooops
* bump VS version set GOROOT
* puge build cache
* Revert "puge build cache"
This reverts commit 315bb578afc19529457f435e52af2172f5143bc5.
* bumperino to test
* purge setting of golang directory for version and allow default
* purge cache state when file change
* whoops
* thrasher: nits
* don't need to flusherino the cacherino
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
* initial concept of a nice validation tester for exchanges
* adds some datahandler design
* expand testing
* more tests and fixes
* minor end of day fix for bithumb
* fixes implementation issues
* more test coverage and improvements, but not sure if i should continue
* fix more wrapper implementations
* adds error type, more fixes
* changes signature, fixes implementations
* fixes more wrapper implementations
* one more bit
* more cleanup
* WOW things work?
* lintle 1/1337
* mini bump
* fixes all linting
* neaten
* GetOrderInfo+ asset pair fixes+improvements
* adds new websocket test
* expand ws testing
* fix bug, expand tests, improve implementation
* code coverage of a lot of new codes
* fixes everything
* reverts accidental changes
* minor fixes from reviewing code
* removes Bitfinex cancelBatchOrder implementation
* fixes dumb baby typo for babies
* mini nit fixes
* so many nits to address
* addresses all the nits
* Titlecase
* switcheroo
* removes websocket testing for now
* fix appveyor, minor test fix
* fixes typo, re-kindles killed kode
* skip binance wrapper tests when running CI
* expired context, huobi okx fixes
* kodespull
* fix ordering
* time fix because why not
* fix exmo, others
* hopefully this fixes all of my life's problems
* last thing today
* huobi, more like hypotrophy
* golangci-lint, more like mypooroldknee-splint
* fix huobi times by removing them
* should fix okx currency issues
* blocks the application
* adds last little contingency for pairs
* addresses most nits and new problems
* lovely fixed before seeing why okx sucks
* fixes issues with okx websocket
* the classic receieieivaier
* lintle
* adds test and fixes existing tests
* expands error handling messages during setup
* fixes dumb okx bugs introduced
* quick fix for lint and exmo
* fixes nixes
* fix exmo deposit issue
* lint
* fixes issue with extra asset runs missing
* fix surprise race
* all the lint and merge fixes
* fixes surprise bugs in OKx
* fixes issues with times and chains
* fixing all the merge stuff
* merge fix
* rm logs and a panic potential
* lovely lint lament
* an easy demonstration of scenario, but not of initial purpose
* put it in the bin
* Revert "put it in the bin"
This reverts commit 15c6490f713233d43f10957367fcbf18e3818bdd.
* re-add after immediate error popup
* fix mini poor test design
* okx okay
* merge fixes
* fixes issues discovered in lovely test
* I FORGOT TO COMMIT THIS
* nit fixaroonaboo
* forgoetten test fix
* revert old okx asset intrument work
* fixes
* revert problems I didnt understand. update bybit
* fix merge bugs
* test cleanup
* further improvements
* reshuffle and lint
* rm redundant CI_TEST by rm the CI_TEST field that is redundant
* path fix
* move to its own section, dont run on 32 bit + appveyor
* lint
* fix lbank
* address nits
* let it rip
* fix failing test time range
* niteroo boogaloo
* mod tidy, use common.SimpleTimeFormat
* Add test for dispatch channel reuse
* Dispatcher - make chans bidirectional
* No need to to keep the type assertion separate from the Get()
* Unexport Pipe's channel and add getter
* Okx: Fix Instrument unmarshal
This fixes: `json: invalid use of ,string struct tag, trying to unmarshal "" into float64`
when TwapSz or other fields are empty, which happened briefly today.
As a DriveBy it also simplifies the exposed Instrument type to native
types only.
* Okx: Add missing InstrumentFamily to Instrument
* Okx: Add Instrument Unmarshal tests
DriveBy: Removes stray newline in type conversions
* Okx: Fix empty line upsetting linter