From 02eb854bffb4bba4585a589c5dda62c503d89363 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Fri, 31 May 2024 08:34:13 -0400 Subject: WIP --- .gitpod.yml | 5 - README.md | 53 +++----- api/hived.postman_collection.json | 255 -------------------------------------- api/swagger.yaml | 155 ----------------------- arbiter/.golangci.yml | 18 +++ arbiter/arbiter.go | 73 +++-------- arbiter/go.mod | 2 +- docker-compose-test.yaml | 116 +++++++++++++++-- docker-compose.yaml | 8 +- hived/.golangci.yml | 22 ++++ hived/docker-entrypoint.sh | 6 +- hived/go.mod | 2 +- hived/hived.go | 45 +++---- telebot/.golangci.yml | 19 +++ telebot/go.mod | 2 +- telebot/telebot.go | 21 ++-- 16 files changed, 243 insertions(+), 559 deletions(-) delete mode 100644 .gitpod.yml delete mode 100644 api/hived.postman_collection.json delete mode 100644 api/swagger.yaml create mode 100644 arbiter/.golangci.yml create mode 100644 hived/.golangci.yml create mode 100644 telebot/.golangci.yml diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index f15c853..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,5 +0,0 @@ -image: - file: .gitpod.Dockerfile - -tasks: - - init: go mod download diff --git a/README.md b/README.md index dcc2af2..8542d55 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,64 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/terminaldweller/hived)](https://goreportcard.com/report/github.com/terminaldweller/hived) -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1e67ac7026904cddb55ede7097995ad8)](https://www.codacy.com/gh/terminaldweller/hived/dashboard?utm_source=github.com&utm_medium=referral&utm_content=terminaldweller/hived&utm_campaign=Badge_Grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/1e67ac7026904cddb55ede7097995ad8)](https://www.codacy.com/gh/terminaldweller/hived/dashboard?utm_source=github.com&utm_medium=referral&utm_content=terminaldweller/hived&utm_campaign=Badge_Grade) # hived -`hived` is the second version of my personal cryptocurrency server:
-* hived is currently using redis as its DB because its tiny and fast.
-* It sends notifications through telegram.
-* telebot and hived talk with grpc.
+ +`hived` is small personal cryptocurrency server:
+ +- It sends notifications through telegram.
Currently it has 5 endpoint:
### /price + Lets you ask for the price of the currency. You can determine the currency the value is returned in.
### /pair + Takes in a pair of currencies and a multiplier. Determines and returns the ratio.
### /alert + #### POST + Takes in a name and a math expression containing the names of the currencies. Checks the expression periodically. Sends a message over telegram when the expression holds true.
The expression's result must be boolean. As an example:
+ ```Go ETH*50>50000. ETH*60/(DOGE*300000) < 4. ``` + You can have as many parameters as you like. The requests for the crypto prices are all turned into individual goroutines so it's fast.
The expression evaluation is powered by [govaluate](https://github.com/Knetic/govaluate). So for a set of rules and what you can and cannot do please check the documentation over there.
#### DELETE + Deletes the key from the DB so you will no longer receive updates.
#### PUT + Updates the alert.
#### GET + Fetch the alert with the given name.
### /ex + Gets the list of currencies that are available to be traded.
You can check under `./test` for some examples of curl commands.
### /health -Returns the health status of the service.
-## How to Run -Before you can run this, you need a [telegram bot token](https://core.telegram.org/bots#6-botfather) and a [changelly](https://changelly.com/) API key.
-The keys are put in files and then given to Docker as secrets.The docker entrypoint script then exports these as environment variables.
+Returns the health status of the service.
```sh TELEGRAM_BOT_TOKEN="my-telegram-bot-api-key" ``` -And -```sh -CHANGELLY_API_KEY:"my-changelly-api-key" -``` -And -```sh -CHANGELLY_API_SECRET:"my-changelly-api-secret" -``` -If you want to use docker-compose, it's as simple as running `docker-compose up`. You just need to provide the files. You can check the file names in the docker-compose file.
+ +If you want to use docker-compose, it's as simple as running `docker-compose up`. You just need to provide the files. You can check the file names in the docker-compose file.
Both the server itself and the redis image are alpine-based so they're pretty small.
## telebot -`telebot` is the service that handles sending notifications through telegram. telebot uses grpc.
-You can find the grpc repo for it [here](https://github.com/terminaldweller/grpc).
- -## Gitpod -`hived` is gitpod-ready. Gitpod might need to install some go lsp tools once it is loaded. You will get prompted for those.
- -## Docs -You can find the swagger and postman docs under `/api`.
- -## TODO -* ~~fix travis~~ -* add unit tests -* ~~fix `hived -help` crashing~~ -* ~~haproxy~~ -* ~~turn the telegram bot into its own microservice~~ -* update openapi3.0 spec and postman -* ~~telegram bot's endpoint should be gRPC~~ diff --git a/api/hived.postman_collection.json b/api/hived.postman_collection.json deleted file mode 100644 index f025c5b..0000000 --- a/api/hived.postman_collection.json +++ /dev/null @@ -1,255 +0,0 @@ -{ - "info": { - "_postman_id": "75c431f8-b05d-4706-a6a8-e7ba5b36b2fe", - "name": "hived", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "price", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://127.0.0.1:8008/price?name=CAKE&unit=USD", - "protocol": "http", - "host": [ - "127", - "0", - "0", - "1" - ], - "port": "8008", - "path": [ - "price" - ], - "query": [ - { - "key": "name", - "value": "CAKE" - }, - { - "key": "unit", - "value": "USD" - } - ] - } - }, - "response": [] - }, - { - "name": "pair", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://127.0.0.1:8008/pair?one=BNB&two=CAKE&multiplier=41.56", - "protocol": "http", - "host": [ - "127", - "0", - "0", - "1" - ], - "port": "8008", - "path": [ - "pair" - ], - "query": [ - { - "key": "one", - "value": "BNB" - }, - { - "key": "two", - "value": "CAKE" - }, - { - "key": "multiplier", - "value": "41.56" - } - ] - } - }, - "response": [] - }, - { - "name": "alert-post", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"name\":\"alert4\",\r\n \"expr\":\"ETH>CAKE\"\r\n}" - }, - "url": { - "raw": "http://127.0.0.1:8008/alert", - "protocol": "http", - "host": [ - "127", - "0", - "0", - "1" - ], - "port": "8008", - "path": [ - "alert" - ] - } - }, - "response": [] - }, - { - "name": "alert-put", - "request": { - "method": "PUT", - "header": [], - "body": { - "mode": "raw", - "raw": "{\r\n \"name\":\"alert4\",\r\n \"expr\":\"ETH