Skip to content
Alexy Shelest edited this page Aug 13, 2017 · 11 revisions

Lambda Trader - Use Case

AWS Serverless Application Model is a game changer. Availability and fault-tolerance built in. No infrastructure or support, unlimited scalability at a fraction of a cost.

Financial services institutions invest thousands of dollars to maintain their trading systems - invest in hardware, support, availability and upgrades. With ASW SAM you can own a competitive solution at approximate cost of ten dollars a month. Lambda functions are reliable, fault-tolerant solutions that are charged per usage. DynamoDb is free (under 25GB) big data solution capable of processing thousands of orders per second.

This use case can help you to setup your FIX execution engine on Amazon Cloud. You can use transfixed FIX trading library to deploy lambda function that will react to orders submitted to DynamoDb, validate the orders and execute them with your electronic broker using FIX API. Your trading strategy logic can be decoupled from the execution code. All strategy will have to do is to write an order to DynamoDb table to guarantee order execution with the broker API. There is no need to monitor service availability, resources, etc. Lambda FIX trader will always be available to execute your orders.

diagram

  1. Create EC2 instance on Amazon AWS
  2. Install transfixed into your release directory and dependent libraries:
          sudo pip install -t ~/fixtrader transfixed
          sudo pip install -t ~/fixtrader trollius
  1. Find where _quickfix.so was installed and copy into your release directory as well:
          sudo pip install quickfix       
          sudo find / -name *quickfix* -exec cp {} ~/fixtrader/  \;
  1. Copy fix directory, gain_config.ini and lambdatrader.py from https://github.com/th3sys/transfixed/tree/master/use_case into your release directory:
          sudo mkdir ~/fixtrader/fix
          sudo wget https://raw.githubusercontent.com/th3sys/transfixed/master/use_case/lambdatrader.py -P ~/fixtrader/
          sudo wget https://raw.githubusercontent.com/th3sys/transfixed/master/use_case/gain_config.ini -P ~/fixtrader/
          sudo wget https://raw.githubusercontent.com/th3sys/transfixed/master/use_case/fix/FIX42.xml -P ~/fixtrader/fix/
          sudo wget https://raw.githubusercontent.com/th3sys/transfixed/master/use_case/fix/FIX44.xml -P ~/fixtrader/fix/
  1. Copy gain_config.ini into config.ini and update account, username, SenderCompID and password
  2. Prepare package:
          cd fixtrader
          zip -r9 ~/fixtrader.zip *
  1. Create lambda function:
          aws lambda create-function \
           --region us-east-1 \
           --function-name FixTrader \
           --zip-file fileb://fixtrader.zip \
           --role arn:aws:iam::... \
           --handler lambdatrader.lambda_handler \
           --runtime python2.7 \
           --timeout 30 \
           --memory-size 1024
  1. Using Amazon AWS Console add environment variables for email_address, aws_access_key_id and aws_secret_access_key (to generate SMTP credentials)
  2. Using the scripts provided in https://github.com/th3sys/transfixed/blob/master/use_case/create_tables.py create Orders and Securities tables.
  3. Using the example scripts provided in push_items.py populate Securities table with your tradable securities.
  4. Add a DynamoDB insert trigger to the lambda function created earlier.
  5. Push an order into Orders table and confirm that lambda function executed the order and sent the report.
Clone this wiki locally