Price Aggregation Service for Crypto in AWS Lambda

Kumologica
4 min readApr 14, 2021

Use case

In this use case, we are going to implement an AWS Lambda integration service (API Endpoint) that will fetch and aggregate the price of a given cryptocurrency (user input) from two different exchanges: Kraken and Binance.

Following is the implementation flow of our service:

Use case flow

Pre-requisite

  1. Kumologica DesignerDownload the designer for building the flow.
  2. Access to Kraken and Binance API
Training & Certification
For a limited time, Kumologica offers free online certification for developers on https://training.kumologica.com/

Implementation

We will now start implementing the “CryptoPriceServiceFlow” in Kumologica designer. This flow will expose the endpoint on the resource path /crypto/price.

CryptoPriceServiceFlow

CryptoPriceServiceFlow

Steps

  1. Open Kumologica Designer, click the Home button and choose Create New Kumologica Project.
  2. Enter name (for example CryptoPriceServiceFlow), select directory for project.
  3. press Create Button.

4. Drag and drop EventListener node to the canvas the provide the following configuration.

Display Name :  GET /crypto/price
Provider :
AWS
Event Source
: Amazon API gateway
Verb : GET
URL : /crypto/price

5. Add a Logger node and wire with the EventListener node. Provide the following message.

'Request received for symbol -' & msg.header.event.Records[0].queryStringParameters.symbol

6. Drag and drop the Set-Property node to the canvas and wire it with the logger node. Provide the following configuration.

Display Name :  Set-Symbol
Rules :
Set : msg.symbol
To : msg.header.event.Records[0].queryStringParameters.symbol

7. Add the Scatter node to the canvas and wire it with the set-property node. Provide the following configuration.

8. Drag and drop two loggers and wire them both to the scatter node. Provide the following configuration.

Logger 1 : 'Call Kraken Exchange'
Logger 2 : 'Call Binance Exchange'

9. Drag and drop HTTP Req node to the canvas and wire it with the Logger 1 . Provide the following configuration.

Display Name : Call Kraken API
Method : GET
URL : 'https://api.kraken.com/0/public/Ticker?pair=' & msg.symbol
Return : a parsed JSON object

Similarly drop another HTTP Req node to the canvas and wire it with the Logger 2. Provide the following configuration.

Display Name : Call Binanace API
Method : GET
URL : 'https://api.binance.com/api/v3/ticker/price?symbol=' & msg.symbol
Return : a parsed JSON object

10. Drag and drop the Set-Property node to the canvas and wire it with the logger1 node. Provide the following configuration.

Display Name :  Set-Price
Rules :
Set : msg.payload.kraken
To : J: $string(payload.result.*.o)

11. Similarly, drag and drop another Set-Property node to the canvas and wire it with the logger2 node. Provide the following configuration.

Display Name :  Set-Price
Rules :
Set : msg.payload.binance
To : msg.payload.price

12. Add Gather node to the canvas and join both the Set-Property node to the gather node.

13. Add Datamapper node to the canvas and provide the following mapping.

{
"BINANCE" : msg.payload."0".binance,
"KRAKEN" : msg.payload."1".kraken
}

14. Finally, we will end the flow by adding EventListener End node. Provide the following configuration

Display Name :  Success
Status Code
: 200
Content-Type : application/json
Payload : msg.payload

Deployment

  1. Select AWS icon on the right panel of the designer and select your AWS Profile from the profiles drop-down.

Note: If you haven’t mapped the your local AWS profile with the designer then you may follow the below video to configure it.

Configuring the profile using settings in designer
  1. Click Connect. If successfully connected will show the rest of the configuration options.
  2. Set the Memory to 512mb and Timeout as 20 seconds.
  3. Go to “Trigger” section under cloud tab and select the Amazon API Gateway trigger.

4. Post successful deployment copy the endpoint URL from the Kumologica terminal.

Url eg: https://ii4854fjdj.execute-api.ap-southeast-2.amazonaws.com/test

Testing

Conclusion

This article has shown how to integrate different Cryptocurrency exchanges easily and cost effectively with AWS Lambda using Kumologica.

Remember Kumologica is totally free to download and use. Go ahead and give it a try, we would love to hear your feedback.

--

--

Kumologica

Kumologica is the first low-code development solution that makes your integration services run on serverless compute regardless the cloud provider.