This serverless application uses the Uphold API public ticker and retrieves the BTC-USD (and other currency pairs concurrently) at a rate of 5 seconds. Each time it retrieve a new ask price, the bot will compare it with the first ask price and decide if it should alert of an oscillation. It will alert if the price changes 0.01 percent in either direction (price goes up or down). These alerts are stored in an Aurora PostGres Database.
Note: you can't really run serverless locally, but you can mock and use unit tests to validate that it will work in AWS :)
- npm install
- npm run -s test
- npm run -s test-all
test-all will give the code coverage report as an HTML
Step 1: install aws-cli -> https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html Step 2: npm install -g aws-cdk@latest Step 3: Configure your AWS config : https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html
[default]
aws_access_key_id=********AKIAI44DH********
aws_secret_access_key=*********je7M/*********
Step 4: npm install Step 5: cdk bootstrap //this will install the cdk stack Step 6: cdk deploy Step 7: Login into RDS and login into the Database to create the table: (Sadly CDK can't create tables for RDS, so we have to manually do it... DynamoDb doesn't have this issue lol )
Create TABLE currencyPairAlerts (
id text UNIQUE,
currencyPair text,
interval text,
priceOscillationPercentage float,
timeOfAlert timestamp
);
that's it :) the application is already created to run when necessary :D
should be able to see the alerts in PostGreSQL
Also, if you choose to remove this app from AWS, then all you have to do is 'cdk destroy'
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template