{"id":30353151,"url":"https://github.com/mkaganm/algo-trade","last_synced_at":"2026-04-11T14:03:23.093Z","repository":{"id":286632900,"uuid":"961960352","full_name":"mkaganm/algo-trade","owner":"mkaganm","description":"ALGO TRADING PROJECT","archived":false,"fork":false,"pushed_at":"2025-08-17T17:56:14.000Z","size":2200,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T19:29:48.578Z","etag":null,"topics":["docker","golang","grafana","mongo","prometheus","pyroscope","redis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkaganm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-07T12:44:27.000Z","updated_at":"2025-04-10T17:26:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"597eb9bc-1dd3-47bf-a712-d91d7f3f906d","html_url":"https://github.com/mkaganm/algo-trade","commit_stats":null,"previous_names":["mkaganm/algo-trade"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkaganm/algo-trade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkaganm%2Falgo-trade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkaganm%2Falgo-trade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkaganm%2Falgo-trade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkaganm%2Falgo-trade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkaganm","download_url":"https://codeload.github.com/mkaganm/algo-trade/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkaganm%2Falgo-trade/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271086304,"owners_count":24696858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","golang","grafana","mongo","prometheus","pyroscope","redis"],"created_at":"2025-08-19T01:21:13.199Z","updated_at":"2025-12-30T21:43:05.825Z","avatar_url":"https://github.com/mkaganm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ALGO TRADE\n\n---\n\n### SETUP\n\n```\nmake build\n```\n```\nmake run\n```\n\nor\n\n```\ndocker-compose build\n```\n```\ndocker-compose up -d\n```\n\nYou can start the project using the docker-compose commands or the defined make commands.\n\n---\n## DESCRIPTION\n\n![FLOWCHART](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/flowchart.png)\n\nThe Algo Trade project consists of 3 main modules. These are, respectively:\n- collector\n- processor\n- trader\n\n### Collector\nThe Collector collects real-time BTC/USDT data from Binance via WebSocket.\nIt writes the collected data to MongoDB.\n\n### Processor\nThe Processor retrieves and processes data from MongoDB. \nIt calculates the SMA values of this data and makes BUY or SELL decisions accordingly. \nThe decision is logged in MongoDB. \nThe decision is sent as a signal to the Trader module via Redis streams.\n\n### Trader\nThe Trader module receives signals via Redis streams. \nIt acknowledges the stream messages in Redis based on the processed signals.\nBuy and sell commands can be integrated here based on the received signals.\n\n---\nAll services have health check endpoints.\n\nAll services send their metrics to Prometheus via Pyroscope. \nThe metrics in Prometheus can be visualized using Grafana.\n\n---\n### HEALTH CHECKER\n\nThere are health check endpoints for 3 services.\n- collector:\n```\ncurl -X GET http://localhost:8080/healthcheck\n```\n- processor:\n```\ncurl -X GET http://localhost:8082/healthcheck\n```\n- trader:\n```\ncurl -X GET http://localhost:8083/healthcheck\n```\n\nThe Collector health check endpoint checks the MongoDB connection. \n\nThe Processor health check endpoint checks the MongoDB and Redis connections. \n\nThe Trader health check endpoint checks the Redis connection.\n\n![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/healthcheck.png)\n\n---\n\n### METRICS\n\nPyroscope is used to collect metrics.\nPyroscope integrates the collected metrics with Prometheus.\nThey can be visualized using Grafana.\n\nExample metric queries are provided below.\nMany more metrics are already being collected through Pyroscope and Prometheus,\nand they can also be visualized via Grafana.\n\nCollector cpu \n```\nsum(rate(node_cpu_seconds_total{job=\"collector-metrics\", mode!=\"idle\"}[1m]))\n```\nCollector memory \n```\nsum(node_memory_MemTotal_bytes{job=\"processor-metrics\"} - node_memory_MemAvailable_bytes{job=\"processor-metrics\"})\n```\nProcessor cpu \n```\nsum(rate(node_cpu_seconds_total{job=\"processor-metrics\", mode!=\"idle\"}[1m]))\n```\nProcessor memory \n```\nsum(node_memory_MemTotal_bytes{job=\"processor-metrics\"} - node_memory_MemAvailable_bytes{job=\"processor-metrics\"})\n```\nTrader cpu \n```\nsum(rate(node_cpu_seconds_total{job=\"processor-metrics\", mode!=\"idle\"}[1m]))\n```\nTrader memory\n```\nsum(node_memory_MemTotal_bytes{job=\"trader-metrics\"} - node_memory_MemAvailable_bytes{job=\"trader-metrics\"})\n```\n\n![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/grafana.png)\n---\n\n### MongoDB\n\n```\nhttp://127.0.0.1:8081/db/btc_data/\n```\n\nThere are 2 collections in MongoDB.\n- trade_signals: Logs of processed signals\n  ![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/processlogs.png)\n---\n- depth: Collected price data\n  ![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/btcdatadb.png)\n---\n\n### Redis\n\nSignals are being sent and received via trade_signals_stream in Redis.\n\n```\nhttp://127.0.0.1:8001/redis-stack/browser\n```\n\n\n![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/redis.png)\n\n---\n  \n\n### Code Quality\ngolangci-lint was used for code quality, \nand the project's code was written according to these rules.\n\n---\n# TECHNOLOGIES\n\n - Golang\n - MongoDB\n - Redis\n - Pyroscope\n - Prometheus\n - Grafana\n - Docker\n - golinter\n - fiber\n - gorilla/websocket\n - testify\n\n---\n### TEST \n\nExample tests have been written for SMA calculations and signal processing.\n\n![](https://raw.githubusercontent.com/mkaganm/algo-trade/refs/heads/master/documents/unittest.png)\n\n---\n\n## EXPLANATIONS\n\n#### Challenges faced and how you solved them.\n\n- I had only used Redis as a caching mechanism before. \nRedis Streams was new to me, and it was a valuable learning experience.\n- I was unfamiliar with cryptocurrency exchanges and SMA \n(Simple Moving Average) calculations, so I researched and implemented them step by step.\n\n#### How you would ensure scalability, fault tolerance, and security.\n\nScalability\n- Microservices Architecture: The project is divided into Collector, \nProcessor, and Trader modules, allowing independent scaling.\n- Docker: Services run in containers, enabling easy horizontal scaling.\n- Redis Streams: Handles high-throughput data streams efficiently.\n- Monitoring: Prometheus and Pyroscope identify bottlenecks for optimization.\n\n\nFault Tolerance\n- Database Replication: MongoDB Replica Sets and Redis ensure high availability.\n- Health Checks: Each service has endpoints to monitor its status.\n- Retry Mechanisms: Implemented for Redis and MongoDB operations.\n- Container Orchestration: Tools like Kubernetes can restart failed services automatically.\n\n\nSecurity\n- Encryption: TLS/SSL secures data transmission.\n- Authentication: MongoDB and Redis use username/password authentication.\n- Network Isolation: Services run in isolated Docker networks.\n- Code Quality: golangci-lint ensures secure and high-quality code.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkaganm%2Falgo-trade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkaganm%2Falgo-trade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkaganm%2Falgo-trade/lists"}