This trading pipeline application is designed to perform real-time data streaming, process tick data, and execute trades based on Bollinger Bands and Rejection candlestick patterns. It uses the Deriv API for connecting to the market, fetching tick data, and placing trades on the selected symbol.
- Live Data Streaming: Connects to the Deriv WebSocket API to fetch tick data in real time.
- Technical Analysis: Uses Bollinger Bands and RSI to analyze market conditions and identify buy/sell signals.
- Automated Trading: Automatically executes trades when the appropriate signal is generated.
- Data Preprocessing: Processes live data to generate OHLC (Open, High, Low, Close) candlesticks from tick data.
Ensure that you have the following before running the application:
Python 3.8+
Pip for managing dependencies.
Deriv API app ID and token. You can register for these at Deriv.
Step 1: Clone the Repository
git clone https://github.com/stephen-njiu/Trading-Pipeline
cd <your-repo-directory>
Step 2: Install the Requirements
You can install the required dependencies using the requirements.txt file:
pip install -r requirements.txt
Step 3: Set Up Your Environment
-
You will need to provide your app ID and API token in the code:
app_id = '<your_app_id>' api_token = '<your_api_token>'
Step 1: Connect to the Market
The application connects to the Deriv WebSocket and streams tick data in real time. The first connection is established in the connect() function:
api = asyncio.run(connect())
Step 2: Data Preprocessing and Candlestick Generation
Tick data is processed and converted into candlestick data using the create_candle() function. The data_preprocess() function applies Bollinger Bands, RSI, and Rejection candlestick patterns to the data:
df = data_preprocess(df)
Step 3: Trading Logic
The trading strategy is based on Bollinger Bands and Rejection patterns. It triggers a buy or sell based on the signal generated:
Signal 1: Sell when the close and open prices are above the upper Bollinger Band.
Signal 2: Buy when the close and open prices are below the lower Bollinger Band.
The application places a trade using the api.proposal() and api.buy() functions once a signal is detected.
Usage Example
To run the application, execute the following command:
python main.py
- Once the application is running, it will stream tick data, process it into candlestick format, and execute trades based on the predefined strategy.
- WebSocket Connection: The application connects to Deriv’s WebSocket using websockets.connect().
- Tick Data Handling: Tick data is fetched and stored in the ticks list, which is later used to create candlesticks.
- Bollinger Bands & RSI: These are used to detect overbought or oversold conditions.
- Trade Execution: Trades are placed when the appropriate conditions are met.
- Timeframe: You can change the candlestick timeframe by modifying the candle_stick_timeframe variable.
- Symbol: To trade on a different asset, replace the value of the tick_symbol variable.
- Trade Amount: Adjust the amount variable to set the stake for each trade.
This project is open-source under the MIT License.