Commit Graph

218 Commits

Author SHA1 Message Date
Bea
9a6e230e40 BTC Markets: Fix sending trades to the websocket DataHandler (#1847)
* Fix websocket trade streaming

* Fix lint

* Rename trade.Data var

* Update wsTrade side type

* Add test for the invalid side

* Test the side
2025-03-25 16:20:54 +11:00
Bea
d857d704e3 BTSE: Fix sending trades to the websocket DataHandler (#1845)
* Fix ws trades stream

Update the raw trade data to match the API docs
Fix extracting the pair from the topic
Update the test
Amend the configtest to enable the trade feed

* Rename the test, exctract pair from symbol

* Add check if neither trade feed or save trade data is enabled

* Update the channel name to match the API docs

* Change side parsing

* Change tradeHistory Side type

* Fix linter and nit

* Fix linter

* Fix the channel trades channel name
2025-03-20 12:33:08 +11:00
Gareth Kirwan
16d2d9f35a Config: AssetEnabled upgrade (#1735)
* Config: Move assetEnabled upgrade to Version management

* Assets: Do not error on asset not enabled, or disabled

This became more messy with Disabling something that's defaulted to
disabled.
Taking an idealogical stance against erroring that what you want to have
done is already done.

* CurrencyManager: Set AssetEnabled when StorePairs(enabled)

* RPCServer: Fix tests expecting StoreAssetPairFormat to enable the asset

Also assertifies

* Bitfinex: Fix tests for MarginFunding subs

* GCTWrapper: Improve TestMain clarity

* BTSE: Add futures to testconfig

* Exchanges: Rename StoreAssetPairStore

Previously we were calling it "Format", but accepting everything from
the PairStore.
We were also defaulting to turning the Asset on.

Now callers need to get their AssetEnabled set as they want it, so
there's no magic

This change also moves responsibility for error wrapping outside to the
caller.

* Config: AssetEnabled upgrade should respect assetTypes

Previously we ignored the field and just turned on everything.
I think that was because we couldn't get at the old value.
In either case, we have the option to do better, and respect the
assetEnabled value

* Config: Improve exchange config version upgrade error messages
2025-03-17 21:47:37 +11:00
Bea
3d212b6279 Okx: Fix sending trades to the websocket DataHandler (#1833)
* Send trades down the DataHandler, add test

* Send the trades down to the DataHandler

Update the test to process trades for each asset type
Add raw trade data from OKX
Update the timestamp in the method

* Replace pair repetition with p var

* Update the test, remove repetition

* Rename trade var in the test

* Fix nits and slice sorting

* Compare trades

* Fix nits
2025-03-17 10:07:28 +11:00
Bea
72a94a4b6c Huobi: Fix sending trades to the websocket DataHandler (#1817)
* Send trades down the DataHandler

* Send individual trades down the DataHandler

Update the test to send the multiple trades
Remove the ID setting to 0 in the test
Iterate through the trades to send them down individually
Rename the test to match the method

* Fix the timestamp conversion

* Fix the wording

* Update the expected data format

* Update the test name and description

* Fix error case
2025-03-11 10:21:28 +11:00
Bea
7fa2592e31 Kraken: Fix sending trades to the websocket DataHandler (#1813)
* Send trades down the DataHandler

When the tradeFeed is enabled, send the trades down the DataHandler
Add TestWSProcessTrades

* Update assertions

* Add check against null references in slices

* Add an error for ws parsing field to common

* Update kraken websocket ProcessTrades

Send individual trades down the DataHandler
Send multiple trades in test
Test error if the trade length is too short
Nits

* Fix nits
2025-03-04 17:06:07 +11:00
Gareth Kirwan
dc2d7770fb Huobi: V2 subscription support (#1703)
* Huobi: assertify tests

* Testing: Add FixtureToDataHandlerWithErrors

* Huobi: Add V2 websocket support

* Huobi: Fix tests racing on updatePairsOnce

* Huobi: Remove unnecessary funnelData

* Huobi: Clarify V1/V2 pings

* Huobi: Switch to types.Time

* Huobi: Disable websocket Futures and CoinMarginedFutures support

* Huobi: Fix test failures on futureContracts

Per-instance future codes not getting cached causin occassional fails

* Huobi: Fix idiosyncratic naming using TestWs instead of TestWS

* Huobi: Run WS tests in parallel
2025-02-19 16:42:25 +11:00
Gareth Kirwan
5463e359bc Bitfinex: Fix websocket trade processing (#1754)
* Bitfinex: Fix WS trade processing

* Add handling for funding trades

Fixes #1746

* 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.

* Bitfinex: Move websocket constants to websocket file

* Bitfinex: Rename channel consts

* Bitfinex: Send individual WS trades down the DataHandler
2025-02-17 13:20:14 +11:00
Ryan O'Hara-Reid
6613c56738 stream/buffer: remove time.ticker publish limiter for websocket orderbook updates (#1681)
* stream/buffer: remove publish period for for signalling change through data handler

* Add config upgrade and downgrade

* linter: fix

* GK: nits

* Update config/versions/v3.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update config/versions/v3.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update config/versions/v3.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update config/versions/v3.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Update config/versions/v3.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* config: fix up commited suggestion

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
2025-02-10 16:15:33 +11:00
Samuael A.
5c892307c7 exchanges: Okx Update (#1420)
* update acccount ratelimits and added missing endpoints

* completed mapping missing trade accoung REST endpoints and Rate Limit

* added orderbook trading missing REST endpoints

* Added few missing endpoints and unit tests

* Completed grid trading and signal bot trading with unit tests

* Added Recurring Buy endpoints and corresponding unit tests

* Added copy trading endpoints and unit tests

* added newly added block trading and spread endpoints

* completed mapping spread endpoints

* Added new endpoints and unit tests

* Added round 1: Okx types and converts update.

* Update endpoints handling and types update

* Removed constants, updated unit tests, and updated endpoint methods

* Slight endpoint and unit test update

* Added spread and other websocket endpoints and update

* completed Spread WS Orderbook handler

* Added missing spread channels and handlers

* Adding Bussinss websocket and missing subscriptions, update unit tests, and endpoints

* Added spread endpoints to wrapper and unit tests update

* Added missing websocket subscriptions and copy trading endpoints

* Added missing endpoints and re-organize business websocket handlers

* Docs update

* Endpoints code updates

* types, unit test and endpoints update

* Minor unit tests update

* spelling fix

* fix unit test issues

* Updating unit tests error handling

* Updating unit tests error handling

* Unit tests assertion handling update

* Unit tests update

* Resolve linter issues

* linter issues fix

* Orderbook unit test error fix

* Minor fixes

* Change on test handling and types

* Updating unit tests and cleanups

* Fix unit test issues

* Add ratelimit test and update unit tests and methods

* Update method parameters and error declarations

* Added lending endpoints, unit tests, and update endpoint methods and error declarations

* Update ratelimiters, add missing lending and trading endpoints and unit tests

* Update websocket authentication and subscription handling

* Minor update to unit test and types

* Types, error handling, and other minor updates

* Update unit tests and endpoint functions

* error declarations update and unit tests

* Overall update on unit endpoint, unit tests, and types

* Adding review fixes

* Update on endpoints, order types, and unit tests

* Update unit tests and endpoint functions

* Update on endpoint and update missing parameters

* Implemented and tested newly added trading endpoints

* endpoints update and unit tests

* Update missing endpoints and update overall code

* added and testing funding and fiat related endpoints

* Update on convert and fiat related endpoints

* linter fix, types, endpoints, and unit tests update

* linter issues fix

* revert changes on tempos

* Fix Panic and update websocket auth calls handling

* config linter issue fix

* Fix panic issues and update unit tests

* Fix race condition, TestAllExchangeWrappers unit test issues

* Fix withdrawal manager test issue

* Rename ClosePositionForContractrID --> ClosePositionForContractID

* Rename ClosePositionForContractrID --> ClosePositionForContractID

* Fix error

* endpoints update and fix unit test issues

* added unit tests, updated comments, and code sections

* revert change in defaultSubscriptions

* few types comments update

* Minor changes

* remove lending endpoints

* rm mistakenly added code

* fix unit test

* minor unit test fix

* Adding offline error tests, update endpoints function, config update

* Update unit test coverage for offline error handliing

* Updating wrapper algo order coverage, endpoint calls, and unit tests

* Updating wrapper trade functions to accomodate algo orders

* update wrapper unit tests

* Fix wrapper order functions offline errors handling

* Tested and updated wrapper order functions

* Address review comments

* update order unit tests, and okx endpoint functions

* finalize affected order, endpoint, and margin endpoints

* Slight change on margin unit test

* fix margin unit test issues

* Minor change on unit test

* updates on contract settlement and future contract wrapper function

* add test coverage for contract functions and minor fix on wrapper

* Overall update and unit testing

* codespell, unit tests, type declaration and naming, and code-structure updates

* margin types value and validation function fix

* Update tests and helper funcs

* Improve test coverage

* helper functions and unit tests update

* Fix margin unit test

* Minor review updates

* minor fix on if statement

* Update helper functions

* error handling and functions naming update

* update comment

* minor error return fixes

* minor unit test fix

* Minor fix on spread websocket orders handling

* codespell fix

* skip orderbook depth with incomplete price

* skip orderbook depth with incomplete price
2025-02-10 10:44:48 +11:00
Gareth Kirwan
16e5398dd5 HitBTC: Add subscription configuration (#1639)
* HitBTC: Upgrade test config

* HitBTC: Add subscription configuration
2024-12-17 11:04:23 +11:00
Gareth Kirwan
2a4c2d24a7 Bitstamp: Add subscription configuration (#1620)
* Bitstamp: Add subscription configuration

* Bitstamp: Handle sub/unsub responses

* Bitstamp: Fix TestWsOrderbook
2024-12-12 14:08:06 +11:00
Gareth Kirwan
00556f274d Subscriptions: Respect DisableAssetWebsocketSupport for assets (#1693)
* 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
2024-12-06 17:01:36 +11:00
Gareth Kirwan
66a3ff021e Gemini: Add subscription configuration (#1625)
* Gemini: Upgrade test config

* Gemini: Add subscription configuration

* Gemini: Fix negative waitgroup on shutdown

Fixes #1738
2024-12-06 13:13:32 +11:00
Gareth Kirwan
0c4b070ebc BTCMarkets: Add subscription configuration (#1624)
* Subscription: Add List.GroupByPairs

* BTCMarkets: Add subscription conf

* BTCMarkets: Upgrade test config
2024-12-05 14:50:10 +11:00
Scott
291b7b58ea exchanges/Bybit: Fix UpdateOrderExecutionLimits (#1731)
* potentially resolved

* fixes bug with symbol formatting

* fixing lints

* actually uses nextPageCursor

* refactor transforming symbols, add test

* shazbert1000
2024-12-03 10:12:39 +11:00
Gareth Kirwan
8f9ebcb521 BTSE: Add subscription configuration (#1616)
* BTSE: Add subscription configuration

* BTSE: Upgrade test config
2024-11-12 14:29:58 +11:00
Gareth Kirwan
a2a7fed273 Huobi: Add subscription configuration (#1604)
* Huobi: Update test config format

* Huobi: Add subscription configuration

* Huobi: Add subscription documentation

* Huobi: Clarify OB sub Levels usage

* Huobi: Enable websocket for tests

* Subscriptions: Rename ErrPrivateChannelName

Rename ErrPrivateChannelName to ErrUseConstChannelName
2024-11-11 14:19:25 +11:00
Adrian Gallagher
69bb645fc2 docs: Migrate development tracking from Trello to GitHub Projects (#1696)
* docs: Migrate development tracking from Trello to GitHub Projects

* docs: Replace non-template based references and correct templates
2024-11-08 10:10:49 +11:00
Gareth Kirwan
2232340d49 Bitmex: Subscription templating (#1586)
* Exchanges: Allow empty batches in ParallelChanOp

In keeping with both common.Batch and "It's not my responsibility",
ParallelChanOp should just do nothing when given an empty list (and
implicitly an empty batch size.
Whatever it's going to do, it'll delegate to common.Batch,
and this allows us to just inline calls:
```
	return common.AppendError(
		b.ParallelChanOp(subs.Public(), func(l subscription.List) error { return b.manageSubs(wsSubscribeMethod, l, wsPublicStream) }, len(subs)),
		b.ParallelChanOp(subs.Private(), func(l subscription.List) error { return b.manageSubs(wsSubscribeMethod, l, wsPrivateStream) }, len(subs)),
	)
```

* Bitmex: Test config updates

* Bitmex: Sub Templating

* Bitmex: Enable websocket for tests

* Bitmex: Handle subscription errors

This switches to multiplexing so that we know which errors belong to
which stream, particularly for the auth attempt

* Bitmex: Fix ws order side err going to data stream

Shouldn't fall into classification error if it's actually a parsing
error
2024-10-22 17:21:35 +11:00
Gareth Kirwan
ba77c9946d Bitfinex: Add subscription configuration and templating (#1597)
* Bitfinex: Correct comment about R0 OB

* Bitfinex: Test config updates

* Bitfinex: Add missing assets to configtest

* Bitfinex: Rename GenerateDefaultSubscriptions

* Bitfinex: Add Subscription configuration

* Subscriptions: Document panic in templates
2024-10-18 09:23:15 +11:00
Gareth Kirwan
33e82c170f Kraken: Subscription improvements (#1587)
* 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
2024-10-08 10:34:10 +11:00
Gareth Kirwan
bfd499f0c9 GateIO: Add websocket subscription configuration (#1599)
* GateIO: Switch TestMain to using testexch.Setup

* GateIO: Test config updates

* GateIO: Privatise and rename genSubs

* GateIO: Subscription configuration
2024-10-01 09:39:24 +10:00
Adrian Gallagher
74f4df6348 okcoin: Remove exchange implementation (#1626)
* okcoin: Remove exchange implementation

* exchanges/order: Rid TradeMode from Submit type
2024-08-24 12:19:04 +10:00
Adrian Gallagher
ba3dcc8e25 Bybit: Fix UpdateAccountInfo coin balance issue, improve GetWalletBalance and enhance test coverage (#1588)
* Bybit: Fix UpdateAccountInfo and enhance GetWalletBalance

* Update struct field and comments
2024-07-29 12:36:10 +10:00
Gareth Kirwan
c601575c66 subscriptions: Add templating support and integrate with Binance (#1568)
* 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
2024-07-09 15:53:00 +10:00
Ryan O'Hara-Reid
03c1fb7f5c Bybit: Add missing field min notional (#1574)
* bybit: Adds min notional value for contract trading

* update tests

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
2024-07-04 10:00:57 +10:00
Gareth Kirwan
b7a2f617d9 Bybit: Fix WS ticker processing (#1538)
* Bybit: Fix WS ticker processing

* Bybit: Refactor SetDefaults
2024-07-03 16:05:11 +10:00
Samuael A
aeb4a87913 exchanges: Add Deribit exchange support (#1082)
* deribit implementation

* add ws impll

* cleanup

* Update deribit_wrapper.go

* Add missing endpoints

* Fix config file

* asset type update

* Update code structure

* Update authenticated private endpoints unit tests

* Updating websocket

* Updating websocket connection and subscription handling

* Finishing up adding subscription push data

* Adding websocket public endpoint

* Adding WS endpoints

* Adding websocket unit tests

* Minor clean-up

* Integrating websocket endpoints into the wrapper funcs

* Updating exchange documentations

* Fixing test issues

* Code cleaning-up

* fix test issues

* Updating validations and logic errors

* Updating wrapper issues

* fix test issues

* Slight test update

* Unit test and code structure update

* Update websocket tempos

* Slight update on code structure

* Minor update on unit tests

* Update depending on review comments

* Minor code fix and doc re-generating

* Update on Candlestick wrapper functions

* Minor updates

* minor unit test updates

* Minor updates on weboscket and unit tests

* minor linter fix

* codespell and rate limiter issues

* single linter issue fix

* adding rate limiter

* Add ratelimiter to websocket conn and overall code update

* fix websocket push data issue

* Implementing missing wrapper function

* Websocket fix

* Minor update on missing endpoint and other

* fixing websocket issues and cleaningup

* Minor tempo fix

* Minor linter issues

* unit test update

* Indexing error fix

* Websocket connection fix

* string formatting fix

* Small fix on unit tests

* fix minor json conversion issue

* websocket and documentation update

* websocket, wrapper and unit test updates

* Documentation and unit tests update

* Fix unit tests

* wrapper fix for new change

* Unit test fix

* timestamp conversion and unit tests update

* Minor instrument ID conversion fix

* instrument formats and unit test update

* formatting and unit test fix

* config update

* Updating websocket and adding the Spot support

* Add small unit test fix

* unit test and websocket handlers update

* Linter issues fix

* minor documentation and code update

* Minor fix

* added a wrapper func GetLatestFundingRates

* Types, wrapper update, and unit tests

* Minor config update

* fix wrapper unit tests

* Resolve all panic and wrapper test issues

* minor unit test fix

* fix issues and adding newly added endpoints

* updates and added remaining endpoints with unit tests

* Update unit tests using assert

* Added missing endpoints and unit tests

* Minor updates and clean-ups

* Resolve tradable pair fetching  panic

* Mutex fix

* Added Options assets test and minor fixes

* subscription mothod updated

* Remove misadded code lines

* resolve websocket

* Updating tests, types, endpoint methods and others

* Added GetFuturesContractDetails and minor fix

* fix linter issue

* revert change on candlestic time

* Added filters to candles

* minor unit test and wrapper fix

* Minor unit tests update

* cahnge param key for GetOrderMarginByID

* updating unit tests and resolve issues

* Update websocket unit tests

* Minor fix based on review

* Revert unit test change

* fix pair config issue

* Added missing wrapper functions

* Fix missing review changes

* Fix options request pair formatting

* fix AllExchangeWrappers test issue

* Changes with unit test and wrapper based on the review

* Fix to options reg-exp

* wrapper functions fix

* Update MaximumFundingRateHistory filter and minor fixes

* Fix besed on review comment

* Fix issues on review comment

* linter fix

* fix minor unit test issue

* Fix unit test issues

* Update trade order cancellation responses

* fix config files issue

* lint update config files

* Update unit tests

* Update return values and response handling

* added missing endpoint and fixes based on review comment

* toggle useTestNet back

* Update cancel by label and other fix

* fix forgotten cancel all response type

* update CancelResp type

* Fix unmarshaling error

* updated websocket orderbook load issue

* fix websocket lock and groups

* Change Items to Tranche and fix linter issues

* Fix orderbook issue

* Update unit tests offline error handling, and endpoints argument and  error handling

* Contributors documentation update and change error return type

* Updated unit tests based on review comment

* Update unit tests and removed password change endpoint

* Fix race condition

* Update on tests, test pairs, and wrapper config

* Update test tradable pairs loading

* Update unit tests, fix linter issues, and update wrapper functions

* remove credentials

* Update test and fix authentication method and few authenticated endpoints

* fix codespell issue

* group the repeated currency code check to a func

* added unit test for repeated pair check func

* Added a base coin and related updates

---------

Co-authored-by: E Sequeira <earncef@earncef.com>
2024-05-29 10:28:03 +10:00
Gareth Kirwan
7d1eecfa7e Tests: Various race fixes and move TestFixtureToDataHandler (#1534)
* Tests: Move and simplify TestFixtureToDataHandler

* Currency: Fix PairsManager.Load breaking matcher

* Tests: Add multi-instance cache to UpdatePairsOnce

* Kraken: Fix TestUpdateTickers race error

Calling StorePairs on global instance can lead to race

* Bitfinex: Fix TestUpdateTickers racing intermittently

* Currency: Fix concurrent access to PM formats

* Currency: Fix SupportsAsset implementation

This should delegate entirely to PairManager's IsAssetSupported

* Okx: Fix PM intrusion, rm GetPairFromInstrumentID

* Exchange: Fix SetGlobalPairsManager to set asset enabled

* Bitflyer: Fix race on set TestGetCurrURL

TestGetCurrencyTradeURL would fail sometimes due to sequencing of
enabling futures but not having pairs for it.

* Tests: Simplify usage pattern for FixtureToDH
2024-05-16 14:09:26 +10:00
Scott
ece58ebf6d Bybit: Add support for SOL options (#1533) 2024-05-06 16:23:19 +10:00
Bea
a46622a9c8 Bitstamp: Add missing API fields and enhance test coverage (#1510)
* Bitstamp: Add missing fields

* Bitstamp: update assert to require, update tests WIP

* Bitstamp: Update the tests

* Bitstamp: Update GetOrderInfo

* Bitstamp: Add minor updates

* Bitstamp: Update TestGetFee, add Amount to GetOrderInfo

* Bitstamp: Update TestGetFee

* Bitstamp: Update OrderStatus type
2024-05-06 11:05:49 +10:00
Adrian Gallagher
1e95ae9b79 qa: Enforce JSON standard for GCT configs (#1526)
* qa: Enforce JSON lint for GCT configs

* Makefile/GHA: Make output more verbose on success, clean duplicate PHONY and rid excess newlines

* Makefile: Use printf for OS cross-compatibility output
2024-04-30 16:02:09 +10:00
Gareth Kirwan
fdf6014dca Currency: Remove Pair Index formatting/parsing (#1520)
* Currency: Remove Pair Index formatting/parsing

This feature was originally for exchanges with only one pair (e.g. KRW) which made parsing easier.
However there's no examples of this left, and we can reduce complexity
overall by removing it.

* Exchange: Partial assertify tests and fixes

* Currency: Fix panic on a delimiterless small currency
2024-04-19 17:03:12 +10:00
Gareth Kirwan
40193bb8c3 Kucoin: Fix transient test failure on XMR (#1485)
Kucoin delisted XMR temporarily for margin trading.
That seems quite likely long term too, due to XMR's privacy features.

Replace XMR with TRX to hopefully avoid in future
2024-02-21 09:14:12 +11:00
Adrian Gallagher
9f968151be ItBit: Remove exchange implementation (#1463) 2024-02-15 10:40:02 +11:00
Bea
e0c6e118ed Bitstamp/Kraken: Enhance test coverage (#1423)
* Bitstamp: Improve GetAccountTradingFees

* Bitstamp: Improve test coverage

* Bitstamp: Improve TestWithdrawInternationalBank and TestWithdrawFiat

* Bitstamp: Fix the failing tests WIP

* Bitstamp: Fix TestWithdraw mockTest

* Bitstamp: Fix TestWithdrawFiat

* Bitstamp: Fix TestWithdrawInternationalBank

* Bitstamp: Simplify conditions in TestGetDepositAddress

* Bitstamp: Switch Ws functions Errors to assert.Error

* Bitstamp: Fix TestSubmitOrder, update other errors

* Bitstamp: Fix TestGetOrderStatus, amend error comments

* Bitstamp: Fix TestGetOrderInfo

* Bitstamp: Fix TestTransferAccountBalance

* Bitstamp: Update TestGetWithdrawalsHistory, fix linter errors

* Bitstamp: Update TestGetRecentTrades, change type Withdrawal.Requests.Date

* Bitstamp: Update TestGetDepositAddress, TestBitstamp_OHLC, TestBitstamp_GetHistoricCandles, TestBitstamp_GetHistoricCandlesExtended

* Bitstamp: Fix tests

* Bitstamp: Fix the typos and linter, add a side test to TestGetTicker

* Bitstamp: Update WithdrawFiat and WithdrawFiatFundsToInternationalBank

* Bitstamp: Fix the error description

* Bitstamp: Fixup SkipTestIfCredentialsUnset

* Bitstamp: Fixup tests

* Bitstamp: Fix panic, skip live test TestWithdraw, amend mocktest

* Bitstamp: Fixup

* Bitstamp: Fixup

* Bitstamp: Fixup
2024-02-05 10:39:44 +11:00
Gareth Kirwan
68a6f5828f Binance: Subscribe/unsubscribe response handling (#1444)
* Binance: Fix subscription failures ignored

* Testing: Fix race on shared config singleton

* Config: Privatise Global config var

We should *either* use a private var *or* use an accessor, but it
doesn't make sense to mix paradigms.
Since GetConfig() is well established this instead removes the limited uses of direct public access and adds a Setter

* Zip: Fix test failure on http mocks
2024-02-02 19:27:17 +11:00
Adrian Gallagher
804cee4287 ZB: Remove exchange implementation (#1450) 2024-01-25 15:45:55 +11:00
Gareth Kirwan
e007f69f7c exchanges/websocket: Implement subscription configuration (#1394)
* 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.
2024-01-24 15:54:07 +11:00
Scott
b71bf1f3d1 exchanges/futures: Implement open interest (#1417)
* adds open interest to exchanges

* ADDS TESTING YEAH

* New endpoints, BTSE, RPCS, cached

* slight design change, begin gateio

You will need to get cached for
each exchange that supports it

* gateio, huobi, rpc

* fix up kraken, cache retrieval

* okx, gateio

* finalising all implementations and tests

* definitely my final ever commit on this

* Well, well, well

* final v2

* quick fix of bug

* test coverage, assert notempty, test helper

Added a new testhelper for currency
management because its very annoying
in a parallel test setting which wastes
so much space otherwise

* minimises REST requests for Open Interest

* types.Number merge misses

* Minimises Kraken REST calls

* len change, value -> pointer receiver

* further fixup

* fixes gateio, batch calculates open interest

* single gateio, lint const fixes

* rejig and more thorough oi for huobi

* formatting expansion

* minor fix for handling expiring contracts

* rm unused Binance strings

* add bybit support, fix bybit issues

* oopsie doopsie, dont look at my whoopsie

* Fix issue, remove feature

* move an irrelevant function for the pr

* mini bybit upgrades

* fixes cli request bug
2024-01-12 15:27:35 +11:00
Samuael A
fb6d12ac69 exchanges: Update Bybit exchange to V5 (#1301)
* Adding Bybit public endpoints

* Completed adding market endpoints

* Added trade endpoints

* Adding position endpoints

* completing position endpoints

* Adding Pre-upgrade endpoints

* Completed adding Pre-upgrade and Account endpoints

* Added asset endpoints

* Added user endpoints and unit tests

* Adding spot leverage and margin trade endpoints

* spot margin trade added

* added spot-margin-trade, institutional lending, c2c lending, and broker

* Adding wrapper funnctions

* Working on wrapper public methods

* Added wrapper functions and unit tests

* Added websocket support with unit tests

* Update websocket handlers and added rate-limiter

* wrapper function, websocket handlers, and linter issues fixe

* unit tests fixes and codespell correction

* Update documentation

* Minor websocket handling fix and URL consts merging

* types, unit test other updates

* Updated websocket and methods based on review

* Added GetFeeByType method with unit test and fixes

* add filter for Unified and Normal endpoints

* Mock recording and unit tests update

* minor linter issue fix

* websocket and rest tests and fix

* change asset types and wrapper methods update

* rm: forgotten panic message

* endpoints, websocket  and unit tests update

* Added and updated endpoints and unit test

* linter and spell fix

* unit test and orders update

* Update on endpoints, fields, config pairs and formating, and unit tests

* minor update on responses

* Fix unit test and types

* Unit tests, models, and wrapper issues fix and mock test recording

* rm print statement

* Fix issue, add FundingRate wrapper func, mock record

* minor type and unit test update

* Update on order handling and unit test

* Minor test

* Minor fix in wrapper

* unit tests update, recording, and documentation update

* Unit tests and minor wrapper function update

* minor unit test fix

* Added newly added endpoints, unit tests, and mock recording

* Rename GetInstruments -> GetInstrumentInfo

* doc update

* Minor unit tests update

* Minor unit test and wrapper update

* Fix linter issue

* Add unit test and minor updates

* Revert websocket error declaration

* Revert websocket error declaration

* Balace --> Balance

* Fix config issues

* Added next funding time minor fix

* Update GetLatestFundingRates and record mock test data

* Added LatestFundingRate time

* Fix test issue of TestAllExchangeWrappers

* config pairs update

* configtest spot pairs update

* Minor update on options UpdateOrderExecutionLimits wrapper func

* Linter issue fix and added new currency codes

* Added new currency codes

* Update bybit pairs in config_example

* config assets pair format update
2024-01-11 12:35:46 +11:00
Bea
07300d1c70 Bitstamp: Fix GetWithdrawalRequests/GetWithdrawalsHistory date parsing and enhance test coverage (#1406)
* Bitstamp: Fix GetWithdrawalRequests date parsing

* Bitstamp: Add return error to GetWithdrawalsHistory

* Bitstamp: GetWithdrawalsHistory remove log.Errorf, add description to fmt.Errorf

* Bitstamp: Add tests
2023-12-29 14:19:23 +11:00
Gareth Kirwan
37b1121bbd BTSE: Fix duplicate pair errors on Million pairs (M_*) (#1401)
* BTSE: Fix duplicate error on Million pairs (M_*)

BTSE has listed Pitbull token with two symbols:
PIT-USD and M_PIT-USD for millons of PIT / USD.
The native token is not tradable, so we ignore them and
get a base of M_PIT because that's what later APIs will accept

* BTSE: Fix test errors on locked market

* Common: Improve AppendError and ExcludeError

This change switches from a stateful multiError to caring more about the
Unwrap() []error interface, the same as [go standard
lib](https://github.com/golang/go/blob/go1.21.4/src/errors/wrap.go#L54-L68)

Notably, if we implement Unwrap() []error and do NOT implement Is() then
we get free compatibility with the core functions.

The only distateful thing here is needing to deeply unwrap fmt.Errorf
errors, since they don't flatten. I can't see any way around that

* Pairs: Fix exchange config Pairs loading

When a pair string contained two punctuation runes, the first one is used,
and the configFormat is ignored.

This fix checks the list and corrects any with the wrong delimiter, or
errors if the format is inconsistent.

* BTSE: Fix all tickers retrieved by GetTicker

PR #764 introduced GetTickers, but it wasn't rolled out to BTSE.
This fix ensures that when one ticker is a locked market, the rest continue to
function. Particularly important if the locked market wasn't even
enabled anyway.

* Kucoin: Fix test config future pairs

* BTSE: Remove PIT tests; Token removed

BTSE have removed the PIT token pairs

All these changes stand, and this just removes the test

* ITBit: Fix fatal error on second run

This fix removes incorrect config pair delimiter, because it would be
re-inserted into config the first run, and then error the second time.

This delimiter doesn't match the config we have.
There's no implementation of fetching pairs, so what's in config files
now is all that matters

* Engine: Fix TestConfigAllJsonResponse

* Clarity of non-matching json improved
* Handling for fixing pair delimiters
2023-12-19 14:40:13 +11:00
Gareth Kirwan
0620ee034d Okx: Fix GetInsuranceFundInformation "" resp (#1405)
* Okx: Fix GetInsuranceFundInformation "" resp

When amount is "" this was erroring

* Test: Standardise configtest.json

Simple jq formatting of configtest
git diff -w or github ignore whitespaces should show no changes.
Any conflicts, just accept --ours and reformat it. Or not :o)
2023-11-28 09:38:37 +11:00
Adrian Gallagher
0fd433e865 exchanges/bittrex,kucoin: Remove exchange implementation and fix minor test issue (#1403)
* exchanges/Bittrex: Remove exchange implementation

* Kucoin: Fix TestProcessMarketSnapshot after pair removal update

* Kucoin: Fix race due to duplicate setupWS call

Unleash your inner Max Verstappen

* Kucoin: Actually test spot/margin market snapshot replication
2023-11-22 10:20:09 +11:00
Bea
06024fcb56 Kucoin: Fix ProcessMarketSnapshot and add a test (#1392)
* Kucoin: Fix ProcessMarketSnapshot and add a test

* Kucoin: ProcessMarketSnapshot: move the check before the ticker

* Kucoin: remove time.sleep from the test, add if statement to processmarketSnapshot

* Kucoin: ProcessMarketSnapshot to send margin, spot and both margin and spot pair data

* Kucoin: range over listOfAssetsCurrencyPairEnabledFor which returns a slice

* Kucoin: linter fix and pointers placed

* Kucoin: removed AssetWebsocketSupport and ku.CurrencyPairs.IsAssetEnabled, linter error fixed, comment amended
2023-11-21 11:28:38 +11:00
Scott
70690d9a04 futures: Implement GetLatestFundingRates across exchanges (#1339)
* adds funding rate implementations and improvements

* merge fixes x1

* lint

* kucoin funding rates func make

* migrate sync-manager to keys

* some kucoin work

* adds some kucoin wrapper funcs

* ehhh, todo

* kucoin position

* start of orders

* adds the kucoin tests yay

* multiplier

* nits, EWS includes order limits

* NotYetImplemented, IsPerp improvements, cleaning

* lint, test fix, huobi time

* fixes issues, improves testing

* fixes linters I WRECKED

* local lint but remote lint, lint, lint, lint

* fixes err

* skip CI

* lint

* Supported rates, binance endpoints

* fixes weird mocktest problems

* no, CZ is invalid

* fixes some new EWS test errors
2023-11-03 11:01:32 +11:00
Gareth Kirwan
f9437dbd08 Bitfinex: Websocket subscription improvements (#1353)
* Websockets: Add keys to websocket subscriptions

* This switches all RO uses of the mutex to use a RLock method.
* The mutex used for discrete field access has had scope drift from
  name 'connectionMutex' so rename to more appropriate fieldsMutex
* The mutex used for Set/CanUseAuthEndpoints moves from the
  subscriptions endpoint to the fieldsMutex
* Add GetSubscription by key
* Expose stream.Matcher type

* Bitfinex: Subscribe and Unsubscribe atomicly

* Fix Auth failures ignored
* This change makes it so that Subscribe and Unsubscribe wait for success
** Tells the DataHandler about errors
** Errors are returned to consumers
* Subscribes concurrently to the channels
* It also simplifies the chanId to stream mapping
* Removes unable to locate chanID: %d errors which are just noise
* Paves the way for unified channelSubscription id handling
* Adds support for subId for Book subscriptions, which is more robust

* Vastly simplifies what we need to test TestWsSubscribedResponse
This test was working to ensure that the various fancy key parsing
mechanisms all worked. Now that we use subId, we just need a thorough
test of that
* Expose Match.Set in order to capture websocket incoming data
Can't see another way of doing this. Doesn't seem too bad

* Allow tests to run with auth or WS
These flags made it difficult to run the tests whilst working on
websockets

* Enable API auth and WS in testconfig
This change minimises the changes requires for a full test run against
live endpoints, so that new contributors have a clearer testing path.
I cannot see any reason to turn WS off and Auth endpoints off when we're
not going to run API tests without Creds being set, and we're not going
to do live fire tests without canManipulateRealOrders

* TestWsSubscribe and various fixes
** Enables the websocket for live non-authed integration tests by default
** Adds an integration test for subscriptions
** Changes the Ws tests to respect canManipulateRealOrders
** Uses WsConnect instead of setupWs; fixes seqNo config not sent for WS tests
** Allows api creds to live in config/testdata.json which might be
  less likely to accidentally commit, and less obtrusive

* Bitfinex: Support period and timeframe for Candles

* Fixes manual Subscribe() symbol or key formatting
* Unifies handling of params for DefaultSubscriptions and manual
  subsrciptions

* Bitfinex: Handle conf and info WS channel events

* Bitfinex: Better tests for subscriptions

* fixup! Websockets: Add keys to websocket subscriptions

* fixup! Bitfinex: Subscribe and Unsubscribe atomicly

* fixup! Websockets: Add keys to websocket subscriptions

* Websockets: Add Pending subscription status

Add a status tracker so that Sub/Unsub can prevent duplicates,
and also fixes when first message comes before we have added the sub
to the tracker

* Websockets: Add State instead of pending

This change allows more clarity about the current state and
checks for specifically already Unsubing

* Bitfinex: Fix first sub message maybe lost

The only link we have between a sub req and the sub resp is the subID.
And the only link we have between a sub message and the sub is the chanID.
We can't derive a link using Pair or anything else.

This meant that by sending the resp and its chanID down the IncomingData
channel, we allowed the channel reader to maybe process the next
message, the first message on the channel, before the runtime executed
the switch back to subscribeToChan waiting on the chan.

To fix this, we key initially on subId.(string), and then replace it
with chanId.(int64) when we have it *inside* the wsHandleData so we
know we've procedurally handled it before the next message.

subscribeToChan is then free to remove the subId keyed Sub regardless of
error or not

If there's an error, we don't need to inline handling because there
won't be any second update.

Expands test coverage to make sure those subId keyed subscriptions are
removed.

* Websocket: Validate state in SetChanState

* fixup! Bitfinex: Fix first sub message maybe lost

* Websockets: Rename RemoveUnsuccessfulSubs

Implementation doesn't imply Unsuccessful or need to.
This change supports the registering of Pending subs

* Bitfinex: Fix race in Tests
2023-11-02 12:10:43 +11:00
Scott
2ea3083468 exchanges/kraken,bittrex,gemini: Resolve Kraken panic, lint corrections, Bittrex batch tickers, set Gemini order limits and update tradable pairs (#1372)
* fix kraken, batch bittrex, fix lint

* surprise gemini!

* thought this happened automatically

* fix before shazbert sees

* fixes annoying atoi bug

* rm futures from gemini

* lint

* bittrex UpdatedAt, gemini Limits, stats relook

* STATS used HARDEN!(improve stats package)

* Whoopsies in your Daisies

* rm RWMutex, json stringeroo

* fixes additional index issues 😆 😭
2023-10-23 18:06:25 +11:00