TipperBeats Twitter Integration with Alpaca API

An open-source trading engine utilizing the Twitter and Alpaca API

TipperBeats Twitter Integration with Alpaca API
Twitter Integration with Alpaca API

Please note that this article is for educational purposes only. Alpaca does not recommend any specific securities or investment strategies.

TradeSpotter (@tipperbeats) is a Twitter account created in April 2021 for the purpose of sharing and tracking real-time trading signals. The signals are generated by an algorithm developed over several years that attempts to capture short-term retracement moves in US equities.


Background

The development approach to the algorithm was different from most algorithmic traders, in that we didn’t start with the data and look for patterns but rather with a trading thesis. We started our careers as traders. As such, we often have short-term opinions on stocks, based on their chart pattern and general market environment. What we did was capture those in the form of conditions that express the setup we see in the chart. We then back-tested that setup over stocks traded in the last 20 years or so. This approach helped us minimize data mining, as we began with a speculative approach that we tested as opposed to finding a pattern and attempting to explain it with a thesis.

The algorithm generates both long and short signals, making price predictions with a time frame of between a few hours up to one day ahead. To date, the hit ratio is over 60%, profit ratio is over 65%, yearly rate of return over 70% with a Sharpe of 3. In an effort to be fully transparent, we track and log the performance of all of the signals shared, the log can be found here.

TradeSpotting Tracker
Signal Data Hit Ratio:,53.7%,Num Signals,Longs,Shorts,SPY return for the period:,9.4%,<a href=“https://t.co/V7CLnIq9BI?amp=1”>bit.ly/3vj6bT2</a>,10%,Daily HR:,100.00%,2022-03-30Profit Factor:,1.29,1193,357,836,Total Return:,37.3%,8:44:51 PM,Daily PR:,100.00%Average Signal:,0.28%,HR: 53.7%,57.7...
Tracker


The algorithm does not require lightning-speed execution since the signals are generated from what we believe are anomalies that could take several hours to correct. However, it wasn’t long until some followers started asking about a tool that might assist in execution. Thus the idea for the Modular Trade Execution Engine Bot was born.

The goal was to create a program that would monitor the Twitter account, determine when a signal was being sent, translate these Tweets into orders and execute them automatically. However, it was important for us to broaden the potential scope of the tool to allow for others to participate: we decided it should be open-source so that it could be modified to include other Twitter accounts (and possibly other mediums of signal sharing) by other algorithm-developers and also to include additional brokers.

Alpaca was the first broker chosen since Alpaca’s execution API offers a very straightforward way to operate a fully automated active portfolio of the assets we trade. The trade execution engine can be found here.

GitHub - mtvoid00/MTEEBot-main: Modular Trading Execution Engine
Modular Trading Execution Engine. Contribute to mtvoid00/MTEEBot-main development by creating an account on GitHub.
GitHub

This approach has the potential to create a modular decentralized algorithmic hedge fund by breaking it down to its basic components. Traders/developers can focus on algorithm development, and end-users can execute automatically while allowing their risk profile to inform position sizing, profit target, and stop losses. It does not require any third-party intervention. If an algo proves to be profitable, its creator can grow a following and monetize via subscriptions, etc.


Features

I will now demonstrate some of the features of the program, how to set it up, and how it can be modified and personalized:

Once the program is started up, the trade execution engine runs in the background, and listens for TradeSpotter’s tweets:

Trading Engine Terminal Output

At 4:30 pm a tweet is sent:

Example Tweet

It is then detected by the execution engine:

Tweet Detected

It checks the tweet to make sure all expected fields are present, parses, and translates into an order:

Checking Tweet

And sends it for execution:

Sends Order

Finally, we get the trade confirmation:

Trade Confirmation

And on Alpaca, we can see the trade in the Order History:

Alpaca Order History

And the account status:

Alpaca Account Status

Setup

Once you clone this repository run: npm install to install all dependencies

GitHub - mtvoid00/MTEEBot-main: Modular Trading Execution Engine
Modular Trading Execution Engine. Contribute to mtvoid00/MTEEBot-main development by creating an account on GitHub.
GitHub Repo

Once dependencies are installed run: npm start in your terminal


Requirements

You will need two accounts:

  1. Twitter Developer Account: https://developer.twitter.com/
  2. Alpaca Account: https://www.alpaca.markets

From the Twitter Developer account you will need to get:

  1. consumer_api_key
  2. consumer_api_secret
  3. access_token_key
  4. access_token_secret

From the Alpaca Paper Trading Account, you will need to get

  1. keyId
  2. secretKey

Once you have all the credentials, open the src/settings.ts file and add your credentials

twitter: {
        api: {
            consumer_key: '- TWITTER CONSUMER API KEY -',
            consumer_secret: '- TWITTER CONSUMER API SECRET -',
            access_token_key: '-TWITTER AUTHENTICATION ACCESS TOKEN KEY -',
            access_token_secret: '-TWITTER AUTHENTICATION ACCESS TOKEN SECRET-',
         
        },
        followUsers: [           
            { name: "@TipperBeats", id: "1385168716258742272" },            
        ],
        authorizedSignalsFromUsers: ['@TipperBeats'] 
    },
    alpaca: {
        accountName: 'Paper Account',
        api: {
            keyId: '--- ALPACA API KEY HERE ---',
            secretKey: '--- ALPACA SECRET KEY HERE ---',            
        },
        trades: {
            amountPerTradeInDollars: 10000
        }
    }
API Requests

You can adjust the USD amount traded per signal here as well.

TipperBeats does not provide an explicit stop loss, rather positions are intended to be held until the end of the day regardless of the outcome. Nevertheless, a stop loss is set to be equal distance from the entry price to the profit target. In addition, the program is set up to exit all open positions 5 mins before the market closes. This can be adjusted and modified based on your risk tolerance.



Conclusion

In this article, I discussed the background of the Twitter account TradeSpotter (@tipperbeats), the features of the open-source Modular Trade Execution Engine Bot, and instructions on the integration between the two. Now you are just steps away from connecting a Twitter account to your Alpaca Brokerage account.

In summary, find TradeSpotter (@tipperbeats) here

https://twitter.com/TipperBeats

And the open-source trading engine here

GitHub - mtvoid00/MTEEBot-main: Modular Trading Execution Engine
Modular Trading Execution Engine. Contribute to mtvoid00/MTEEBot-main development by creating an account on GitHub.

Disclaimers

Neither the Twitter signals nor the execution engine is financial advisors. USE AT YOUR OWN RISK.

The signals and software are provided as-is. If you choose to use either, you are responsible for any financial loss or gain.

Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), memberFINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.