* docs: Create new CODING_GUIDELINES doc
Rids excess contribution instructions from other packages
Adds AGENTS.md file for the AI overlords
Rids unused templates
Updates ADD_NEW_EXCHANGE.md with minor fixes
* docs: Fix linter issues and minor adjustments based on Copilot feedback
* docs: Update coding guidelines for API parameters and testing practices
* docs: Remove redundant GoDoc references
Adds copilot-instructions.md
* docs: Update CODING_GUIDELINES with export recommendations and test commentary
* docs: Fix formatting inconsistencies in ADD_NEW_EXCHANGE.md links
* docs: Update struct naming conventions for request and response types
* docs: Improve clarity and consistency in ADD_NEW_EXCHANGE.md and CODING_GUIDELINES.md
* refactor: Simplify error handling in QueryOrder method
* GHA, tests: Add additional checks for common issues
These checks include:
- Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`).
- Replacing `%s` with %q
- Enforcing consistent usage of should/must wording for testify assert/require messages
* Add support for checking backticked string format specifiers and fix issues
* tests: Fix error comparisons
* tests: Replace errors.Is(err, nil) usage with testify and automate check
* refactor: Rename ExtractPort to ExtractPortOrDefault
* tests: Replace assert with require for error handling in multiple test files
* tests: Replace assert with require for error handling and improve assertions in data tests
* tests: Fix typo in assertion message for StreamVol test
* OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions
* OKX: Revert intentional error check
* Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
* gateio: Add websocket orderbook update manager
* RM println
* glorious: nit
* Adds delivery futures update processing as well
* Change to const value for delivery
* Drop check out of order, can reinstate if required.
* Adds in validation methods to ensure config changes are correct when expanding templates and return errors with correct info if not.
* fix some things and add in todo when this gets updated
* fix spelling
* linter: fix
* gk: initial nits
* gk: nits shift to template only verification with funcmap, rm interface for single sub checking.
* rm unused error
* linter: fix
* update to const frequency
* gk: wrap with panic and single invocation in template, change name
* gk: nits to check across stored subs with incoming subs
* linter: fix
* updates names, makes things slightly more efficient and adds tests
* linter: fix
* gk: sexc patch v2
* glorious: nits
* gk: nits
* Update exchanges/subscription/template.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
* linter: make peace with linter regulations
* glorious: Add TODO for future template integration
* glorious: commentary nits
* fix name
* give me a break, have a kit kat
* revert whoops
* update wording on comment
* revert secondary call to expand templates and update tests
* misc lint: fix
* Add spot orderbook update interval for 20ms, expand tests, piggy back limit/level off loaded subscription. Thanks to @thrasher-
* linter/spell: fix
* ai nits: drop go routine on mtx RUnlock
* Update exchanges/gateio/ws_ob_update_manager.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: revert to 100ms from 20ms waiting for config upgrade patch
* test: fix
* cranktakular: nits
* strings quoted in fmt call
* thrasher-: nits
* Update exchanges/gateio/gateio_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Update exchanges/gateio/gateio_test.go
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* gk: nits
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
* Tests: Use currency.NewUSD and NewUSDT
Simple refactor to use the provided shortcut methods
* Github: Add CI check to ensure NewPair not used
Add a step to ensure NewPair(BTC, USD*) isn't used
* modernise: Run new gopls modernise tool against codebase
* Address shazbert's nits
* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling
* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS
* refactor: Various slice usage improvements and rename TODO
* tranches: Revert deleteByID changes due to performance decrease
Shazbert was a F1 driver in a past lifetime 🏎️
* tranches: Simply retrieve copy
Thanks to shazbert
* documentation: Sort contributors list by contributions
* tranches: Remove deadcode in deleteByID
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues
* Address shazbert's nitters
* linter/config: Fix new linter issue and use versionSize const
* Address gk's nitters and fix additional linter issue after rebase
* Address glorious nits
* staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6
Also addresses nits
* Improve testing, assertify usage and use common.ErrParsingWSField
* TestCreateNewStrategy: Replace must > should wording
If one asset is enabled but has no enabled pairs, we should ignore that
asset, even for non-pair related subscriptions.
That matches the existing code, but wasn't happening in the context of
asset.All subscriptions with just one asset in this state.
If a user wanted to have non-pair subscriptions, they should use
asset.Empty. Would expect other breakages with no pairs enabled, too.
Note: No enabled pairs for an enabled asset is a transient issue which
can occur due to enableOnePair racing against no available pairs. The
second run, available pairs would be populated and enableOnePair would
work. This situation could persist due to running with --dry or
containerised, though.
Fixes:
`
Okx websocket: subscription failure, myOrders all : subscription template did not generate the expected number of pair records for spread: Got 1;
Expected 0
`
Relates to #1420
* Add check for subscription store insertion and validation with tests
* bybit: fix subscriptions
* deribit: fix subscriptions
* linter: fix
* glorious/nits: add test for updateChannelSubscriptions RM GetChannelDifference method as its only used locally and Diff method can be accessed directly
* glorious/nits: add to store in the loop; add correct formatting to template for edge case perps with settlement
* spelling: fix
* glorious/nit: silly billy
* gk: nits
* gk/nits: split PartitionByPresence into Contained and Missing
* gk/nits: formatPerpetualPairWithSettlement -> formatChannelPair
* stream/websocket: stop full websocket disconnect on Connect when encountering subscription specific error paths
* stream/websocket: rm nil assignment
* glorious: nits
* gk: niterinos
* Update exchanges/stream/websocket_test.go
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* Update exchanges/stream/websocket_test.go
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* Update exchanges/stream/websocket_test.go
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* thrasher: nits
---------
Co-authored-by: shazbert <ryan.oharareid@thrasher.io>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
* tag optional sonic and allow full library conversion
* Add workflow and disallow arm and darwin usage
* Add basic hotswap benchmark
* linter: fix
* use bash
* linter: fix?
* Fix whoopsie, add to make file, also add mention in features list.
* test enforcement
* actually read documentation see if this works
* linter: fix
* linter: fix
* sonic: bump tagged version
* encoding/json: drop build tag arch and os filters
* encoding/json: consolidate tests
* encoding/json: log build tag usage
* rm superfluous builds
* glorious/nits: add template change and regen docs
* glorious/nits: update commentary on nolint directive
* glorious/nits: rm init func and log results in main.go
* Test to actually pull flag in
* linter: fix
* thrasher: nits
* gk: nits 4 goflags goooooooooo!
* gk: nits rn
* make sonic default json implementation
* screen 386
* linter: fix
* Add commentary
* glorious: nits Makefile not working
* gk: nits
* gk: nits whoops
* whoopsirino
* mention 32bit systems won't be sonic
* gk: super-duper nit of extremes
---------
Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
* GateIO: Fix GetFuturesContractDetails for Deliveries
Was returning the product of all the contracts, so 1444 instead of 38
contracts.
* GateIO: Fix GetOpenInterest returning asset.ErrNotEnabled
Using wrong error for pair not enabled
* GateIO: Rename GetSingleContract and GetSingleDeliveryContracts
Especially fixes GetSingleContract, which seems misleading to not say
Futures.
There's a load of `GetSingle*` here that should probably also be fixed,
but these two justified a dyno
* GateIO: Rename GateIOGetPersonalTradingHistory to GetMySpotTradingHistory
* GateIO: Rename GetMyPersonalTradingHistory to GetMyFuturesTradingHistory
* GateIO: Remove duplicate DeliveryTradingHistory
* GateIO: Rename Get*PersonalTradingHistory to GetMy*TradingHistory
* Linter: Disable shadow linting for err
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.
* GateIO: Add missing Futures and tradinghistory fields
* GateIO: Improve WS Header parsing
This unifies handling for time_ms and time in response headers, since
options and delivery have only time, but spot has time_ms as well.
We use the better of the two results.
Also [improves performance 2x](https://gist.github.com/gbjk/7cacb63b9a256e745534bb05ca853c48)
* GateIO: Use time_ms WS fields where available
Removes the deprecated _time json fields and populates our Time fields
with the time_ms values
Thusfar ExpandTemplates had only been called internally.
All methods consumers might want to get, in this case GetPairFormat,
need to be in the interface we're passing out, otherwise users can't
call them (or things that use them, like ExpandTemplates)
* Bitmex: Add index asset to test config
* Subscriptions: Fix unsupported WS assets included
fixed 1692
* Bitmex: Assertify and fix tests
* Subscriptions: Fix all asset subs erroring on no enabled assets
Only subs with Empty asset should do anything when assets are empty.
If asset is set to all and no assets are enabled, we should return
nothing
* Bybit: Subscription configuration for spot
* Bybit: Enable candles ws sub by default
* Orderbook: Use a RW mutex for depth
* Orderbook: Fix race on depth.VerifyOrderbook
Despite being protected by an ob level mutex, this needed to privatise
and protect the option var.
The subscription pairs do not need to be validated as enabled or
available. The check was just belt-and-braces and didn't have a specific
use-case in mind.
Coinbase has a use-case for wanting to subscribe to BTC-USD when it's
not enabled.
Moreover, it shouldn't be our job to check this. You want a sub expanded
with these pairs? Fine. Done. If it doesn't work, you can work out why
* Convert: Fix TimeFromUnixTimestampDecimal using local
All parsed times should be in UTC
* Subscriptions: Add IgnoringAssetsKey
* Tests: Pass tb to curried WS handlers
* Websocket: Make ErrNoMessageListener a public error
* Kraken: Fix URLMap ignored for websocket URLs
* Kraken: Move SeedAssets from Setup to Bootstrap
Having SeedAssets in Setup is cruel and unusual because it calls the
API. Most other interactive data seeding happens in Bootstrap.
This made it so that fixing and creating unit tests for Kraken was
painfully slow, particularly on flaky internet.
* Kraken: Remove convert test
Duplicate of convert_test.go TestTimeFromUnixTimestampDecimal
* Kraken: Test config upgrades
* Kraken: Sub Channel improvements
* Use Websocket subscriptionChannels instead of local slice
* Remove ChannelID - Deprecated in docs
* Simplify ping handlers and hardcodes message
* Add Depth as configurable orderbook channel param
* Simplify auth/non-auth channel updates
* Add configurable Book depth
* Add configurable Candle timeframes
Kraken: Simplify all WS handlers with reqId
* Kraken: Subscription templating
* Generate N+ subs for pairs
If we generate one sub for all pairs, but then fan it out in the
responses, we end up with a mis-match between the sub store and
GenerateSubs, and when we do FlushChannels it will try to resub
everything again.
* Kraken: Rename channelName var throughout
Avoid shadowing func of same name
* Kraken: Add TestEnforceStandardChannelNames
* Websocket: Fix Resubscribe erroring Duplicate
* Currency: Variadic Pairs.Add
This version of Pairs.Add is simpler and [more
performant](https://gist.github.com/gbjk/06a1fc1832d04ee41213ca518938cf74)
Behavioural difference: If there's nothing to add, the same slice is
returned unaltered. This seems like good sauce
* Currency: Variadic Remove
* Common: Add Batch function
* Common: Add common.SortStrings for stringers
* Subscriptions: Add batching to templates
* Subscriptions: Sort list of pairs
* Kucoin: Switch to sub templating
* Kucoin: Simplify channel prefix usage
* Kucoin: Fix race on fetchedFuturesOrderbook
* Subscriptions: Filter AssetPairs
Now only the assetPairs relevant to the subscription are in the context
* Subscriptions: Respect subscription Pairs
* Subscriptions: Trim AssetSeparator early
We want to trim before checking for "AssetSeparator vs All" because a
template should be allowed to reuse a range template and generate just one trailing AssetSeparator
whilst using a specific Asset
* Kucoin: Fix empty margin asset added
* Kucoin: Add Subscription batching
Turns out that contary to the documentation, kucoin supports batching of
all symbols and currencies
* Kucoin: Fix checkSubscriptions and coverage
* Subscriptions: Simplify error checking
This reduces the complexity of error checking to just be "do we get the
correct numbers".
Fixes Asset.All with only one asset erroring on xpandPairs, because we
trimmed the only asset separator, and then errored that we're not
xpanding Assets and the asset on the sub is asset.All
This use-case conflicted with commit 6bbd546d74, which required:
```
Subscriptions: Trim AssetSeparator early
We want to trim before checking for "AssetSeparator vs All" because a
template should be allowed to reuse a range template and generate just one trailing AssetSeparator
whilst using a specific Asset
```
Now we set up the assets earlier, and we remove the check for xpandAssets, since the number of asset lines matching is all that matters.
I've removed the asset tests for this, but they were correctly erroring
on the number of asset lines instead.
Everything hits coverage, as well.
* Kucoin: Remove deprecated fundingBook endpoint
* BTCMarkets: Use common.Batch
* Making Pairs(Add) Variatic
* Slight improvements
* Implementation overhaul
* Improvements
* Changing code which can use the variadic functionality
* Fixing silliness
* thing left over
* Subscriptions: Add List.AssetPairs
* Subscriptions: Add Template and QualifiedChannel
These fields separate the concept of what the channel is from the
qualified resource name
* Subscriptions: Add List.SetStates()
* Subscriptions: Add List.QualifiedChannels
* Subscriptions: Rename testsubs.EqualLists
* Binance: Switch to ExpandTemplates
* Binance: Update ConfigTest format
* Subscriptions: Test Coverage improvements
* Subscriptions: Reenterant List.ExpandTemplates
* Subscriptions: Move templates from subscriptions to exchanges
* Binance: Inline subscription template and improvements
* Websocket: Use ErrSubscribedAlready
instead of errChannelAlreadySubscribed
* Subscriptions: Replace Pair with Pairs
Given that some subscriptions have multiple pairs, support that as the
standard.
* Docs: Update subscriptions in add new exch
* RPC: Update Subscription Pairs
* Linter: Disable testifylint.Len
We deliberately use Equal over Len to avoid spamming the contents of large Slices
* Websocket: Add suffix to state consts
* Binance: Subscription Pairs support
* Bitfinex: Subscription Pairs support
* Bithumb: Subscription Pairs support
* Bitmex: Subscription Pairs support
* Bitstamp: Subscription Pairs support
* BTCMarkets: Subscription Pairs support
* BTSE: Subscription Pairs support
* Coinbase: Subscription Pairs support
* Coinut: Subscription Pairs support
* GateIO: Subscription Pairs support
* Gemini: Subscription Pairs support and improvement
* Hitbtc: Subscription Pairs support
* Huboi: Subscription Pairs support
* Kucoin: Subscription Pairs support
* Okcoin: Subscription Pairs support
* Poloniex: Subscription Pairs support
* Kraken: Add subscription Pairs support
Note: This is a naieve implementation because we want to rebase the
kraken websocket rewrite on top of this
* Bybit: Subscription Pairs support
* Okx: Subscription Pairs support
* Bitmex: Subsription configuration
* Fixes unauthenticated websocket left as CanUseAuth
* Fixes auth subs happening privately
* CoinbasePro: Subscription Configuration
* Consolidate ProductIDs when all subscriptions are for the same list
* Websocket: Log actual sent message when Verbose
* Subscriptions: Improve clarity of which key is which in Match
* Subscriptions: Lint fix for HugeParam
* Subscriptions: Add AddPairs and move keys from test
* Subscriptions: Simplify subscription keys and add key types
* Subscriptions: Add List.GroupPairs Rename sub.AddPairs
* Subscription: Fix ExactKey not matching 0 pairs
* Subscriptions: Remove unused IdentityKey and HasPairKey
* Subscriptions: Fix GetKey test
* Subscriptions: Test coverage improvements
* Websocket: Change State on Add/Remove
* Subscriptions: Improve error context
* Subscriptions: Fix Enable: false subs not ignored
* Bitfinex: Fix WsAuth test failing on DataHandler
DataHandler is eaten by dataMonitor now, so we need to use ToRoutine
* Deribit: Subscription Pairs support
* Websocket: Accept nil lists for checkSubscriptions
If the user passes in a nil (implicitly empty) list, we would not panic.
Therefore the burden of correctness about that data lies with them.
The list of subscriptions is empty, and that's okay, and possibly
convenient
* Websocket: Add context to NilPointer errors
* Subscriptions: Add context to nil errors
* Exchange: Fix error expectations in UnsubToWSChans
* Websockets: Move Subscription to its own package
This allows the small type to be imported from both `config` and from
`stream` without an import cycle, so we don't have to repeat ourselves
* Subs: Renamed Currency to Pair
This was being mis-used through much of the code, and since we're
already touching everything, we might as well fix it
* Websockets: Add Subscription configuration
* Binance: Add subscription configuration
* Kucoin: Subscription configuration
* Simplify GenerateDefaultSubs
* Improve TestGenSubs coverage
* Test Candle Sub generation
* Support Candle intervals
* Full responsibility for formatting Channel name on GenerateDefaultSubs
OR consumer of Subscribe
* Simplify generatePayloads as a result
* Fix test coverage of asset types in processMarketSnapshot
* Exchanges: Abstract ParallelChanOp
* Tests: Generic ws mock instances
* Kucoin: Fix intermittent conflict in test currs
Use isolated test instance for `TestGetOpenInterest`.
`TestGetOpenInterest` would occassionally change pairs before
GenerateDefault Subs.