Crypto.Compare is .NET Core system for collecting and aggregating the best prcie of order book data from cryptocurrency exchanges in real-time. The system provides:
🔄 Real-time connectivity to 7+ crypto exchanges
💾 Dual storage (PostgreSQL + Cache)
🌐 WebSocket and REST API for client connections
🐳 Full Docker support for easy deployment
⚡ High performance thanks to .NET 10 and async/await
┌─────────────────────────────────────────────────────────┐
│ Client Applications │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Web App │ │ Mobile │ │ Desktop │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────┬─────────────────┬─────────────────────┘
│ │
REST API (HTTP) WebSocket (WS)
│ │
┌───────▼─────────────────▼────────┐
│ Crypto.Compare API Gateway │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ REST Contr. │ │ WS Handler │ │
│ └─────────────┘ └─────────────┘ │
└──────────────┬─────────────────┬─┘
│ │
┌────────▼─────┐ ┌─────────▼─────┐
│ Cache │ │ PostgreSQL │
│ │ │ │
└──────────────┘ └───────────────┘
│
┌──────▼─────────────────────┐
│ Exchange Data Collectors │
│ ┌────┐ ┌────┐ ┌────┐ │
│ │Bing│ │Bitg│ │BitM│ ... │
│ │ X │ │ et │ │ art│ │
│ └────┘ └────┘ └────┘ │
└────────────────────────────┘
- Clone the repository:
git clone https://github.com/dmitry575/Crypto.Compare.git
cd Crypto.Compare- Starting the application in docker
- Stopping the current image if it is running
docker-compose -f docker-compose.tests.yml down
- Build main image and database
docker-compose -f docker-compose.tests.yml build api-public sql
- Starting dependencies
docker-compose -f docker-compose.tests.yml run --rm start_dependencies
- Starting the application
docker-compose -f docker-compose.tests.yml up -d api-public
- Open the API documentation:
Swagger UI: http://localhost:18072/swagger
It is enough to launch the file: docker-start.cmd
Since all data about access to exchanges is stored in the database, it is necessary to add the necessary records. After running all the images in the docker container, you can connect to Adminer to manage viewing and adding entries to the database. You need to choose:
- System: Posgresql
- Server: sql
- Username: postgres
- Password: test
Add data to connect to exchanges (Access Key and Private Key)
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('mexc', 'https://mexc.com', 'https://api.mexc.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('xtcom', 'https://xt.com', 'https://sapi.xt.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('bybit', 'https://bybit.com', 'https://api.bybit.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());
Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('bingx', 'https://bingx.com', 'https://open-api.bingx.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'bitget', 'https://bitget.com', 'https://api.bitget.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), 'PasswordKey');Need to replace in the request: AccessKey, SecretKey and PasswordKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'gateio', 'https://gateio.ws', 'https://api.gateio.ws', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), '');Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'bitmart', 'https://bitmart.com', 'https://api-cloud.bitmart.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), '');
Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('binance', 'https://binance.com', 'https://api.binance.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Need to replace in the request: AccessKey and SecretKey - for keys from the exchange's personal account
- ByBit: https://www.bybit.com/en/help-center/article/How-to-create-your-API-key?category=ae1012f19fad1c184e
- Gate.io: https://www.gate.io/help/faq/14730
- Bitget: https://www.bitget.com/bitget-api
- Mexc: https://www.mexc.com/api-docs/spot-v3/introduction
- BitMart: https://www.bitmart.com/api/en/
- XT.com: https://doc.xt.com/
Using PosgreSQL. Script for creating database:
./db/init.sql
- Get data of crypto markets
GET /v1/providers?skip=0&rows=10
- Get data full add of crypto market
GET /v1/providers/{id}
- Get data full add of crypto market
GET /v1/providers/{id}
- Get prices from all markets by ticker of currency
GET /v1/symbols/ticker/{ticker}
curl -X POST "http://localhost:8081/v1/symbols/ticker/btcusdt" \
-H "Content-Type: application/json" ws://localhost:8081
Response
{
"id": "a7aef64b-6ee8-47ea-a17d-72d39874001c",
"type": 0,
"data": {
"message": "Connected to Crypto Compare server"
}
}
Type Welcome = 0
{
"id": "1610dd4f-c266-4928-81c1-33819a22e55e",
"type": -1,
"data": {
"error": "Ticker no found",
"errorCode": 3
}
}
Type Error = -1
Request
{
"type": 1,
"data": {
"ticker": "ethusdt"
}
}
Response
{
"id": "17428ac3-43f4-4362-9d3a-7e25cf011ae9",
"type": 1,
"data": {
"ticker": "ethusdt"
}
}
Type Subscribe = 1
Request
{
"type": 2,
"data": {
"ticker": "ethusdt"
}
}
Response
{
"id": "17428ac3-43f4-4362-9d3a-7e25cf011ae9",
"type": 2,
"data": {
"ticker": "ethusdt"
}
}
Type UnSubscribe = 2
Messages are sent only if there was a subscription to the ticker.
{
"id": "1155b20d-017b-494f-b96c-b6d1913d1120",
"type": 4,
"data": {
"ticker": "ethusdt",
"symbolId": 2,
"providerId": 5,
"priceSell": 3329.82,
"priceBuy": 3329.81
}
}
Type SymbolPriceChange = 4
Real-time Cryptocurrency Exchange Data Aggregator - система для сбора и сравнения данных о лучших ценах в стаканах заявок с ведущих криптовалютных бирж в режиме реального времени.
- 🔌 Поддержка 7+ бирж: Единый интерфейс для работы с BingX, Bitget, BitMart, ByBit, GateIo, Mexc, XT.com
- ⚡ Режим реального времени: WebSocket подключения для мгновенного получения обновлений стаканов
- 💾 Двойное хранение: PostgreSQL для исторических данных + Cache для кэширования
- 🌐 Полноценный API: REST API
- 🐳 Готовая Docker инфраструктура: Полная контейнеризация с Docker Compose
- 📊 Агрегация данных: Сбор и нормализация данных с разных бирж в единый формат
- 🔄 Автоматическое восстановление: Устойчивые подключения с автоматическим переподключением
┌─────────────────────────────────────────────────────────┐
│ Client Applications │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Web App │ │ Mobile │ │ Desktop │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────┬─────────────────┬─────────────────────┘
│ │
REST API (HTTP) WebSocket (WS)
│ │
┌───────▼─────────────────▼────────┐
│ Crypto.Compare API Gateway │
│ ┌─────────────┐ ┌─────────────┐ │
│ │ REST Contr. │ │ WS Handler │ │
│ └─────────────┘ └─────────────┘ │
└──────────────┬─────────────────┬─┘
│ │
┌────────▼─────┐ ┌─────────▼─────┐
│ Cache │ │ PostgreSQL │
│ │ │ │
└──────────────┘ └───────────────┘
│
┌──────▼─────────────────────┐
│ Exchange Data Collectors │
│ ┌────┐ ┌────┐ ┌────┐ │
│ │Bing│ │Bitg│ │BitM│ ... │
│ │ X │ │ et │ │ art│ │
│ └────┘ └────┘ └────┘ │
└────────────────────────────┘
- Платформа: .NET 10, ASP.NET Core Web API
- Базы данных: PostgreSQL (основное хранилище), in-memory кэш
- Контейнеризация: Docker, Docker Compose
- ORM: Entity Framework Core
- Конфигурация: appsettings.json, переменные окружения
- Логирование: Log4net с консольным и файловым выводом
- Кэширование: In-memory кэш
- Документация API: Swagger/OpenAPI
- Клонируйте репозиторий:
git clone https://github.com/dmitry575/Crypto.Compare.git
cd Crypto.Compare- Запуск приложения в докере
docker-compose -f docker-compose.tests.yml down
docker-compose -f docker-compose.tests.yml build api-public sql
docker-compose -f docker-compose.tests.yml run --rm start_dependencies
docker-compose -f docker-compose.tests.yml up -d api-public
- Откройте документацию API:
Swagger UI: http://localhost:18072/swagger
Достаточно запусть файл: docker-start.cmd
Т.к. все данные о доступах к биржам хранятся в базе данных, необходимо добавить нужные записи. После запуска в докер контейнере всех образов, можно подключиться к Adminer для управления просмотра и добавления записей в базе данных. Нужно выбрать:
- System: Posgresql
- Server: sql
- Username: postgres
- Password: test
Добавить данные для подключения к биржам
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('mexc', 'https://mexc.com', 'https://api.mexc.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('xtcom', 'https://xt.com', 'https://sapi.xt.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('bybit', 'https://bybit.com', 'https://api.bybit.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());
Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('bingx', 'https://bingx.com', 'https://open-api.bingx.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Нужно заменить в запросе: AccessKey и SecretKey- на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'bitget', 'https://bitget.com', 'https://api.bitget.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), 'PasswordKey');Нужно заменить в запросе: AccessKey и SecretKey, PasswordKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'gateio', 'https://gateio.ws', 'https://api.gateio.ws', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), '');Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt", "PasswordKey")
VALUES ( 'bitmart', 'https://bitmart.com', 'https://api-cloud.bitmart.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW(), '');
Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
INSERT INTO public."Providers"(
"Name", "WebSite", "BaseUrl", "AccessKey", "SecretKey", "Status", "CreatedAt", "UpdatedAt")
VALUES ('binance', 'https://binance.com', 'https://api.binance.com', 'AccessKey', 'SecretKey', 1,NOW(), NOW());Нужно заменить в запросе: AccessKey и SecretKey - на ключи с личного кабинета биржи
- ByBit: https://www.bybit.com/en/help-center/article/How-to-create-your-API-key?category=ae1012f19fad1c184e
- Gate.io: https://www.gate.io/help/faq/14730
- Bitget: https://www.bitget.com/bitget-api
- Mexc: https://www.mexc.com/api-docs/spot-v3/introduction
- BitMart: https://www.bitmart.com/api/en/
- XT.com: https://doc.xt.com/