Skip to content

Backend Assignment for Stealth. This trading algorithm uses simple trading strategy to buy and sell stocks in real-time.

Notifications You must be signed in to change notification settings

pakhare/backend-rust-algo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trading Backend

This is a simple trading bot application built with Rust that monitors stock price changes using a mock API. Implements basic trading strategies to buy or sell stocks based on price movements.

Getting Started

Prerequisites

  • Rust and Cargo installed on your machine. You can install them from rustup.rs.

Clone the Repository

git clone https://github.com/pakhare/backend-rust-algo.git
cd backend-rust-algo

Start the mock API server:

cargo run --bin mock_api

This will start the mock API server at http://localhost:8080/api/stock_prices

Build and Run the Trading Bot

In a new terminal window, navigate to the root of the project and run:

cargo run --bin backend_assignment

The trading bot will start monitoring stock prices and executing trades based on the defined strategy.


API Usage

The mock API provides an endpoint to retrieve stock prices:

Endpoint: GET /api/stock_prices
Response:

[
    {
        "id": 1,
        "symbol": "AAPL",
        "price": 150.0,
        "quantity": 10
    },
    {
        "id": 2,
        "symbol": "GOOGL",
        "price": 2800.0,
        "quantity": 5
    }
]

Trading Logic

The trading bot evaluates trades based on the following criteria:

  • Buy: When the stock price drops by 2% compared to the last price, and there are no open positions.
  • Sell: When the stock price rises by 3% compared to the last price, and there is an open position.
  • Profit/Loss Tracking
    • Current Position: Positive for long positions, negative for short positions.
    • Current Balance: The cash balance available for trading.
    • Total Profit: The overall profit/loss based on current positions and balance.

Technologies Used and Dependancies

  • Rust
  • Actix Web (for the mock API)
  • Reqwest (for making HTTP requests)
  • Serde (for JSON serialization/deserialization)
  • Tokio (for asynchronous programming)

About

Backend Assignment for Stealth. This trading algorithm uses simple trading strategy to buy and sell stocks in real-time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages