bd35-85 / main.py
Qwertey's picture
Update main.py
04f4967
from typing import List
from fastapi import FastAPI
from pydantic import BaseModel
from pyngrok import ngrok
app = FastAPI()
app = FastAPI()
auth="2aZeouhaHuJSXZQ9WatZC3LQieO_6ckrQG71twNRutGxaLh3H"
ngrok.set_auth_token(auth)
# ngrok_tunnel will store the NgrokTunnel object
ngrok_tunnel = ngrok.connect(8000)
print('Public URL:', ngrok_tunnel.public_url)
class Item(BaseModel):
data: List[List[float]] = []
ratio: int
@app.get("/")
def hello():
return {"Error 404"}
@app.post("/pattern1/")
async def create_item(item: Item):
data = item.data
ratio = item.ratio
# Your existing logic here
if data[2][0] > data[2][1] > data[2][2] < data[2][3] < data[2][4] and data[2][3] < data[2][0]:#and df["Open"][i+2] < df["Close"][i+4]:
#position
position="long"
#stop_loss
st_price = min(data[1][:4])
#Close price of taken trade
close_price = data[2][4]
#points of stop_loss
points = close_price - st_price
#target price
target_price = close_price + (points*ratio)
target_price = round(target_price,2)
#Percentage change for st and close
perc_change_st = -(((st_price - close_price) / close_price) * 100)
return [position,st_price,close_price,target_price,perc_change_st]
elif data[2][0] < data[2][1] < data[2][2] > data[2][3] > data[2][4] and data[2][3] > data[2][0]:# and df["Open"][i+2] > df["Close"][i+4] :
#position
position="short"
#Stop_loss_price
st_price = max(data[0][:4])
#Close price of taken trade
close_price = data[2][4]
#points of stop_loss
points = st_price - close_price
#target price
target_price = (close_price - (points*ratio))
target_price = round(target_price,2)
#Percentage change for st and close
perc_change_st = (((st_price - close_price) / close_price) * 100)
return [position,st_price,close_price,target_price,perc_change_st]
else:
return None