This project is a FastAPI-based trading simulator that allows users to manage a simulated portfolio by buying and selling assets. It integrates with Kraken's API to fetch asset prices and uses Redis for caching.
- View trading dashboard with wallet balance and asset value.
- Fetch and cache asset prices from Kraken.
- Buy and sell assets.
- Export and import trading data as JSON.
- View current holdings.
- API caching with Redis.
- Python 3.8+
- Redis server running on
localhost:6379or using Docker
-
Clone the repository:
git clone <repository-url> cd <project-directory>
-
Install dependencies:
pip install -r requirements.txt
-
Start the Redis server:
redis-server
Or using Docker:
docker run --name redis -p 6379:6379 -d redis
-
Run the FastAPI application:
uvicorn main:app --host 0.0.0.0 --port 8000
To build and run the application using Docker:
docker build -t trading-simulator .
docker run -p 8000:8000 trading-simulatorTo start Redis using Docker:
docker run --name redis -p 6379:6379 -d redisTo build and run the application along with Redis using Docker Compose:
docker-compose up --buildThis will start both the trading application and the Redis server.
To stop the services:
docker-compose down- Description: Renders the main trading dashboard.
- Response: HTML page with wallet balance and asset value.
- Description: Returns the current USDC wallet balance.
- Response:
{ "wallet_usdc": float }
- Description: Returns the total value of all held assets in USDC.
- Response:
{ "total_value": float }
- Description: Fetches and caches ticker prices from Kraken.
- Response:
{ "ticker": price }
- Description: Buys a specified asset.
- Parameters:
ticker: Asset ticker (str)amount: Amount to buy (float)
- Description: Sells a specified asset.
- Parameters:
ticker: Asset ticker (str)amount: Amount to sell (float)
- Description: Returns the current trading status.
- Response: HTML page with holdings.
- Description: Exports trading data to a JSON file.
- Response:
{ "message": "Data exported to JSON" }
- Description: Fetches tradable asset tickers from Kraken and caches them.
- Response:
{ "tickers": ["BTC", "ETH", ...] }
- Description: Returns current asset holdings.
- Response:
{ "holdings": { "ticker": amount } }
- Description: Imports trading data from a JSON file.
- Response:
{ "message": "Data imported from JSON", "status": { ... } }
- Description: Serves the favicon.ico file.
- FastAPI: Web framework for API development.
- Redis: Caching layer for API responses.
- Jinja2: Templating engine for rendering HTML pages.
- Uvicorn: ASGI server to run the application.
- Kraken API: Fetching asset prices.
This project is licensed under the MIT License.