Skip to content
/ ccd Public

It is a microservice that collect data from a several crypto data providers using its API.

License

Notifications You must be signed in to change notification settings

streamdp/ccd

Repository files navigation

ccd

Go Report Card Website ccd.run.place GitHub release GitHub license

It is a microservice that collect data from several crypto data providers using its API.

This microservice uses:

  • gin-gonic/gin package to start and serve HTTP server
  • nhooyr.io/websocket package to manage websocket connection
  • go-sql-driver/mysql package to work with mysql database
  • lib/pq package to work with postgresql database
  • go-redis/redis package for saving the active session and restoring it when the puller is restarted

Build app

$ go build -o ccd .

Run app

You should previously export some environment variables:

export CCDC_DATAPROVIDER=cryptocompare
export CCDC_DATABASEURL=postgres://username:password@127.0.0.1:5432/dbname?sslmode=disable
export CCDC_APIKEY=put you api key here
export CCDC_SESSIONSTORE=redis // or "db", default value is "db"
export REDIS_URL=redis://:redis_password@127.0.0.1:6379/0 // only when "redis" session store selected

if you want use huobi as data provider export this:

export CCDC_DATAPROVIDER=huobi

If you use mysql db, you should export something like this:

export CCDC_DATABASEURL=mysql://username:password@tcp(localhost:3306)/dbname

And run application:

$ ./ccd -debug

The default port is 8080, you can test the application in a browser or with curl:

$ curl 127.0.0.1:8080/v1/service/ping

You can choose a different port and run more than one copy of ccd on your local host. For example:

$ ./ccd -port 8081

You also can specify some setting before run application:

$ ./ccd -h
ccd is a microservice that collect data from several crypto data providers cryprocompare using its API.

Usage of ccd:
  -dataprovider string
        use selected data provider ("cryptocompare", "huobi") (default "cryptocompare")
  -debug
        run the program in debug mode
  -h    display help
  -port string
        set specify port (default ":8080")
  -session string
        set session store "db" or "redis" (default "db")  
  -timeout int
        how long to wait for a response from the api server before sending data from the cache (default 1000)

List of the implemented endpoints:

  • /healthz [GET] check node status
  • /v1/collect/add [GET] add new worker to collect data for the selected pair
  • /v1/collect/remove [GET] stop and remove worker and collecting data for the selected pair
  • /v1/collect/status [GET] show info about running workers
  • /v1/collect/update [GET] update pulling interval for the selected pair
  • /v1/symbols/add [GET] add new currency symbol to the db
  • /v1/symbols/update [GET] update currency symbol in the db
  • /v1/symbols/remove [GET] remove currency symbol in the db
  • /v1/price [POST, GET] get actual (or cached if dataprovider is unavailable) info for the selected pair
  • /v1/ws [GET] websocket connection url, when you connected, try to send request like {"fsym":"BTC","tsym":"USD"}
  • /v1/ws/subscribe [POST, GET] subscribe to collect data for the selected pair
  • /v1/ws/unsubscribe [POST, GET] unsubscribe to stop collect data for the selected pair
  • /v1/symbols [POST, PUT, DELETE] add, update, delete currency symbol
  • /v1/collect [POST, PUT, DELETE] add, update, delete worker to collect data

Example getting a GET request for getting actual info about selected pair:

$ curl "http://localhost:8080/v1/price?fsym=ETH&tsym=JPY"

Example of sending a POST request to add a new worker:

$ curl -X POST -H "Content-Type: application/json" -d '{ "fsym": "BTC", "tsym": "USD", "interval": 60}' "http://localhost:8080/v1/collect"

Example of sending a GET request to remove worker:

$ curl "http://localhost:8080/v1/collect/remove?fsym=BTC&tsym=USD&interval=60"

Example of sending a GET request to subscribe wss channel:

$ curl "http://localhost:8080/v1/ws/subscribe?fsym=BTC&tsym=USD"

Working example URL: https://ccd.run.place/healthz

Web UI: https://ccd.run.place