RPC API service to serve up Crypto price information.
- Install go
- Intall protobuf
$ brew install protobuf
$ protoc --version # Ensure compiler version is 3+
- Install the protocol compiler plugins for Go.
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
- Update your PATH so that the protoc compiler can find the plugins.
$ export PATH="$PATH:$(go env GOPATH)/bin"
- Build proto_go lib
bazel build //api:all
- Create BUILD files
bazel run //:gazelle
- Build
bazel build //...
- Install mysql
- Connect to mysql server
mysql -u root -p
- Create
coins
database
create database coins;
- Switch to
coins
database
use coins;
- Create
coins
table incoins
database
source /path/to/ziggy/folder/database/create-table.sql
- Check if table is created.
mysql> select * from coins;
should have schema of table coins
.
- Install grpc curl to interact with server
brew install grpcurl
- Run GRPC server
bazel run //cmd/server:server
- Send requests to grpc server.
grpcurl -plaintext -format text \
localhost:5000 crypto.Crypto.ListCoins
grpcurl \
-d '{"coin_names": "5fkh5xg058v"}' \
-plaintext localhost:5000 crypto.Crypto.ListCoins
grpcurl \
-d '{"coin_id": "21304"}' \
-plaintext localhost:5000 crypto.Crypto.GetCoinHistory
grpcurl \
-d '{"coin_id": "2252",
"enableTracking": true}' \
-plaintext localhost:5000 crypto.Crypto.TrackCoin
- Initially more than 5 coins are added to database as CoinMarketPlace API gives 10 coins even when there is limit of 5.
-
API definitions are present here
-
Curl to get
curl -H "X-CMC_PRO_API_KEY: 0b424217-a625-470d-8d51-d1a344bac7d2" -H "Accept: application/json" -d "start=1&limit=5&convert=USD" -G https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/new | jq
curl -H "X-CMC_PRO_API_KEY: 0b424217-a625-470d-8d51-d1a344bac7d2" -H "Accept: application/json" -d "id=1" -G https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest | jq
- Use two database tables, one for storing coins and other for storing history of prices of the coins.
- Create unit tests for all go files.
- Have e2e test to check if the API is working with mysql.
- Use in-build proto validators to check requests.
- Can use
https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyTrendingLatest
to get coins at first. - Method B should take request constraints