Skip to content

Add ExchangeKrakenAPI.OnGetCandlesWebSocketAsync implementation #600

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

Merged
merged 5 commits into from
Jun 16, 2021
Merged

Add ExchangeKrakenAPI.OnGetCandlesWebSocketAsync implementation #600

merged 5 commits into from
Jun 16, 2021

Conversation

jdx-john
Copy link
Contributor

  1. The kraken API (https://docs.kraken.com/websockets/#message-ohlc) actually only sends one candle at a time, not an array of candles, so I changed the interface accordingly
  2. The API also requires the candle interval parameter which is part of the channel name, so this was also added to the interface
  3. Provided an implementation for Kraken exchange. There is one quirk* mentioned below
  4. Added ws-candles to ExchangeSharpConsole. Also added a IOptionWithPeriod so the candle interval can be specified on commandline - and applied this to the REST-based CandlesOption with the same default value of 1800

I'm not sure if we have formal tests but I tested from the console app and all looked good except for:

*Note that Kraken sends updates to the current candle when there are new trades, and when it does the open-time is the current time, i.e. the open time changes over the life-time of the candle but the close-time does not. Current implementation passes open-time to ParseCandle extension method as MarketCandle.TimeStamp is specified as the open time of the OHLC candle. So you'll see candle updates with new candle timestamp come through.
I do not know if this would be consider correct/desired functionality by the community, or if the open-time should be set as close-time - period so it is constant? It would be a trivial change to var candle = this.ParseCandle(token[1], marketSymbol, interval * 60, 2, 3, 4, 5, 0, TimestampType.UnixSeconds, 7, null, 6); you are welcome to make.

jdx-john added 4 commits June 14, 2021 22:10
Navigating to a folder using the "Finder" on Mac generates a .DS_Store file holding metadata about the folder (e.g. thumbnails etc.). These files can pollute your git commits and are annoying.
Pull methods and expose accessors on base class for consistency.
@jdx-john
Copy link
Contributor Author

This extends #596 in response to issue #595

Copy link
Collaborator

@vslee vslee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the open-time should be set as close-time - period so it is constant

Yes, I think it would make more sense to do this, if you can make the change

fix candle open time as close time  -interval
@jdx-john jdx-john marked this pull request as draft June 16, 2021 22:44
@jdx-john jdx-john marked this pull request as ready for review June 16, 2021 22:45
@jdx-john
Copy link
Contributor Author

if the open-time should be set as close-time - period so it is constant

Yes, I think it would make more sense to do this, if you can make the change

I've made this change. It's a little hacky but I don't see a nicer way without changing the design... seems a quirk of Kraken. I tested in console again and you now get something like this, note the volume resets each time the candle timestamp changes:

Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600, 38600, 38600, 0.00096647, 37.305742, 38600
Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600.1, 38600, 38600.1, 0.51018957, 19693.368420957, 38600.09981
Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600.1, 38600, 38600.1, 0.51248698, 19782.048676698, 38600.09981
Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600.1, 38573.7, 38573.7, 1.24170387, 47897.112570219, 38584.85925
Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600.1, 38573.7, 38578.8, 1.24190387, 47911.161019956, 38584.85828
Market  XBT/USD: 6/16/2021 10:41:00 PM/60: 38600, 38600.1, 38573.7, 38578.8, 1.24628508, 48080.182844304, 38584.83698
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38578.8, 38578.8, 38578.8, 0.12722003, 4907.996093364, 38578.8
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38578.8, 38578.8, 38578.8, 0.29992003, 11570.554853364, 38578.8
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38578.8, 38578.8, 38578.8, 0.32300629, 12461.195060652, 38578.8
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38579.6, 38578.8, 38579.6, 0.3262455, 12586.4208918, 38578.80794
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38582.7, 38578.8, 38582.7, 0.3312205, 12779.38118535, 38578.8664
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38578.8, 38584, 0.33294188, 12846.22949792, 38578.89294
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38578.7, 38578.7, 1.32370797, 51066.932662239, 38579.20516
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38576.7, 1.32889267, 51264.293862789, 38579.19539
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38576.9, 2.32889267, 89841.459641323, 38578.20977
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38577, 2.32950858, 89865.45249066, 38578.20945
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38577, 5.27560516, 203517.02025732, 38577.53405
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38577, 5.28123638, 203734.25583126, 38577.53348
Market  XBT/USD: 6/16/2021 10:42:00 PM/60: 38578.8, 38584, 38576.7, 38577, 5.57470619, 215055.44069163, 38577.50539
Market  XBT/USD: 6/16/2021 10:43:00 PM/60: 38577, 38577, 38577, 38577, 0.00381331, 147.10605987, 38577

Copy link
Collaborator

@vslee vslee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will merge for now, but if you think of a better way to handle the volume in the future, feel free to send a PR!

This was linked to issues Jun 16, 2021
@vslee vslee merged commit 8a51761 into DigitalRuby:master Jun 16, 2021
@jdx-john jdx-john deleted the add-Kraken-OnGetCandlesWebSocketAsync-implementation branch June 21, 2021 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confused by Kraken XBT/XDG tickers Candles in websockets?
2 participants