Skip to content

Commit

Permalink
Merge pull request 10Accademy-InsightStreamInc#19 from mikiiiss/main
Browse files Browse the repository at this point in the history
updated frontend
  • Loading branch information
dev-abuke authored Jun 25, 2024
2 parents 49a9643 + 00ee2d4 commit 35b8854
Show file tree
Hide file tree
Showing 20 changed files with 19,250 additions and 0 deletions.
144 changes: 144 additions & 0 deletions backend/updated_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# from typing import List
# from fastapi import FastAPI, Depends, HTTPException
# from sqlalchemy.orm import Session
# from . import models, schemas, database
# import pandas as pd
# import json
# import os, sys

# cwd=os.getcwd()
# sys.path.append(f"{cwd}/backend/utils/")
# sys.path.append(f"{cwd}/scripts/")

# print("The os is :: ", os.getcwd())

# from backend.utils.backtest import run_backtest

# models.Base.metadata.create_all(bind=database.engine)

# app = FastAPI()

# def get_db():
# db = database.SessionLocal()
# try:
# yield db
# finally:
# db.close()

# @app.get('/health')
# def check_health():
# return "API is healthy"

# @app.post('/indicators/', response_model=schemas.Indicator)
# def create_indicator(indicator: schemas.IndicatorCreate, db: Session = Depends(get_db)):
# db_indicator = models.Indicator(**indicator.model_dump())
# db.add(db_indicator)
# db.commit()
# db.refresh(db_indicator)
# return db_indicator

# @app.get('/indicators/', response_model=List[schemas.Indicator])
# def read_indicators(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
# indicators = db.query(models.Indicator).offset(skip).limit(limit).all()
# return indicators

# @app.post('/stocks/', response_model=schemas.Stock)
# def create_stock(stock: schemas.StockCreate, db: Session = Depends(get_db)):
# db_stock = models.Stock(**stock.model_dump())
# db.add(db_stock)
# db.commit()
# db.refresh(db_stock)
# return db_stock

# @app.get('/stocks/', response_model=List[schemas.Stock])
# def read_stocks(skip: int = 0, limit: int = 20, db: Session = Depends(get_db)):
# stocks = db.query(models.Stock).offset(skip).limit(limit).all()
# return stocks

# @app.post('/scenes/', response_model=schemas.Scene)
# def create_scene(scene: schemas.SceneCreate, db: Session = Depends(get_db)):
# db_scene = models.Scene(**scene.model_dump())
# db.add(db_scene)
# db.commit()
# db.refresh(db_scene)
# return db_scene

# @app.get('/scenes/', response_model=List[schemas.Scene])
# def read_scenes(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
# scenes = db.query(models.Scene).offset(skip).limit(limit).all()
# return scenes

# @app.post('/backtests/{scene_id}', response_model=List[schemas.BacktestResult])
# def perform_backtest(scene_id: int, db: Session = Depends(get_db)):
# db_scene = db.query(models.Scene).filter(models.Scene.id == scene_id).first()
# if db_scene is None:
# raise HTTPException(status_code=404, detail="Scene not found")

# # Fetch data based on the scene's date range
# df = fetch_data(db_scene.start_date, db_scene.end_date)

# # Perform backtest
# metrics = run_backtest({
# 'period': db_scene.period,
# 'indicator_name': db_scene.indicator.name
# }, df)

# # Save metrics to database
# backtest_results = []
# for metric in metrics:
# db_backtest_result = models.BacktestResult(scene_id=scene_id, **metric)
# db.add(db_backtest_result)
# db.commit()
# db.refresh(db_backtest_result)
# backtest_results.append(db_backtest_result)

# return backtest_results

# @app.get('/run_backtest/', response_model=List[schemas.BacktestResult])
# def run_backtests(scene: schemas.SceneCreate, db: Session = Depends(get_db)):
# db_scene = models.Scene(**scene.model_dump())
# return db_scene

# @app.get('/backtest_results/', response_model=List[schemas.BacktestResult])
# def read_backtest_results(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)):
# backtest_results = db.query(models.BacktestResult).offset(skip).limit(limit).all()
# return backtest_results

# def fetch_data(start_date, end_date):
# # Replace this with actual data fetching logic
# df = pd.read_csv('btc_usdt_candlestick.csv', index_col='timestamp', parse_dates=True)
# return df.loc[start_date:end_date]



# backend/main.py

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Dict
from scripts.backtesting.main import run_backtest # Adjust the import based on your project structure

app = FastAPI()

class BacktestConfig(BaseModel):
initial_cash: float
start_date: str
end_date: str
ticker: str
indicator: str

@app.get("/")
async def root():
return {"message": "Welcome to the Scalable Backtesting Infrastructure for Crypto Trading"}

@app.post("/backtest")
def perform_backtest(config: BacktestConfig):
try:
result = run_backtest(config.dict())
return result
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
18 changes: 18 additions & 0 deletions test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# test_api.py

import requests

url = "http://localhost:8000/backtest"
payload = {
"initial_cash": 20000,
"start_date": "2022-01-01",
"end_date": "2024-02-11",
"ticker": "NVDA",
"indicator": "SMA"
}
headers = {
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
23 changes: 23 additions & 0 deletions updated_frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions updated_frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading

0 comments on commit 35b8854

Please sign in to comment.