Skip to content

straightcore/deribit-marketdata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deribit Marketdata Adapter project

Exercice

Guidelines:

This exercise is intended to be straight forward, but you may encounter some questions or issues - please work through these using your best judgement and document any assumptions/decisions you take (comments inside of the code are fine for that).

In an effort to have something complete for #1, please document (code comments are fine for that as well) any design decisions you take that you may have done differently with more time.

Coding Exercise:

Using C# and .netcore, implement a market data recorder for Deribit instruments and expose that market data for client consumption.

  1. Using either Websockets or Rest (your choice), fetch the latest price per instrument every N seconds while respecting the rate limit. Persist the retrieved data into the data store of your choice (text file, database, etc).

  2. Time permitting, create a service for clients to retrieve the pricing data you've persisted above.

How to start process

  1. Use the build.bat to publish all projects under ./publish
  2. Open 2 cmd with Run as Administrator
  3. Start MarketData.Deribit.WebAPI
  4. Start MarketData.Adapter.Deribit.Host

Note: to start process you have two choices:

  1. Windows use the exe file
  2. Otherwise, use the dotnet cli: dotnet MarketData.Deribit.WebAPI.dll

Caution

[Obsolete]

  1. The Daemon (or windows services) under "MarketData.Adapter.Deribit.>Host" execute
    1. dotnet build -c release 
    2. cd bin/Release/netcoreapp3.1
    3. start MarketData.Adapter.Deribit.Host.exe

Caution

2. Start the web API, under "MarketData.Deribit.WebAPI execute

    1. dotnet build -c release
    2. ***CMD run as Administrator***
    3. cd bin/Release/netcoreapp3.1
    4. **Run as Administrator** MarketData.Deribit.WebAPI.exe

Methodology

In the best, I use the S.O.L.I.D. implementation, to have the capability to test my code with BDD and TDD with Red, Green, Refactoring methologies.

I use external dependencies to resolve my implementation.

This project should be used in CI/CD workflow.

Technologies

  • dotnet core 3.1
  • JSON-RPC ApI by OpenAPI, I rework it and rebuild in dotnet core 3.1.
  • SQL Lite, to store the market data. This choice is very simple, I need to show you that it works !

    [!NOTE]- For more performance / scalability, I use mongodb with timeseries

In reality

  • I don't finish the code in TDD / BDD, I chose between delivery and expose my capability to delivery my code with the best pratices applied.

  • I don't use the websocket, I never used the JSON-RPC and I failed to execute a query with "WebSocket" api and I find the API by OpenAPI for deribit. I favored delivery.

  • EntityFramework

    • dotnet tool install --global dotnet-ef
    • dotnet add package Microsoft.EntityFrameworkCore.Design
    • dotnet ef migrations add InitialCreate
    • dotnet ef database update

TODO:

[!WARNING] 1- Use credential to connect by websocket // awaiting receive email to confirm my account

2- Begin the fetch instruments by configuration

  • Given the configuration is correct
  • When I start the sservice
  • Then I fetch all instruments

3- Do the marketdata puller

4- Optimize the code

5- begin the datastorage

Caution

Issues

Bad Request get instrument

info: System.Net.Http.HttpClient.Default.LogicalHandler[100] => HTTP GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False Start processing HTTP request GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False info: System.Net.Http.HttpClient.Default.ClientHandler[100] => HTTP GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False Sending HTTP request GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False info: System.Net.Http.HttpClient.Default.ClientHandler[101] => HTTP GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False Received HTTP response after 196.2512ms - BadRequest info: System.Net.Http.HttpClient.Default.LogicalHandler[101] => HTTP GET https://test.deribit.com/api/v2/public/get_instruments?currency=BTC&kind=Future&expired=False End processing HTTP request after 205.2525ms - BadRequest

but curl https://test.deribit.com/api/v2/public/get_instruments?currency=ETH&kind=Option&expired=False works

It is JSON Rpc protocol with recall async the client. Need to use JSON Rpc library

https://www.tpeczek.com/2020/06/json-rpc-in-aspnet-core-with.html

Deribit does not respect the JSON-RPC over HTTP convention https://www.jsonrpc.org/historical/json-rpc-over-http.html

Deribit repo https://github.com/deribit/deribit-api-clients/tree/master/csharp

Tip

I success to use the api deribit, after change .net v4.5 to dotnetcore 3.1 and include the project. They do not provide nuget package. // Best pratice -> fork the project, include it in the CI/CD system and provide an local artifact NUGET by the internal repo

Cron every seconds

I used the Quartz, it is easy and flexible. https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/using-quartz.html

I did not take the decision for HFT context. Just try to ask the problem with "Simple", "Flexibale" and "adaptable" source code. The time not permitting to abstract all framework in my implementation. But the best way for the UnitTest and the Specflow test is to abstract the QuartZ Framework. If in the future we need to change the framework by another or inhouse scheduler high frequency (dispatcher), we just need to change the implementation and inject by the IOC in the startup.cs

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages