-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
25 lines (16 loc) · 755 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import FastAPI, Request, WebSocket
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from connect import binance_connect
app = FastAPI()
app.mount(path='/static', app=StaticFiles(directory='static'), name='static')
template = Jinja2Templates(directory='templates')
@app.get('/page')
def get_page(request: Request ):
return template.TemplateResponse(request=request, name='charts.html')
@app.websocket('/ws/{symbol}')
async def ws_connect(websocket: WebSocket, symbol: str):
await websocket.accept()
uri = f"wss://stream.binance.com:443/ws/{symbol}@kline_1s"
async for indicator_data in binance_connect(uri=uri):
await websocket.send_json(indicator_data)