Skip to content

Commit 77ff7cf

Browse files
committed
[Server] Add POST route
1 parent c1ae956 commit 77ff7cf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

server.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import os
33
from dotenv import load_dotenv
4-
from flask import Flask, jsonify
4+
from flask import Flask, jsonify, request
55
from flask_caching import Cache
66

77
import triangular_arbitrage.detector
@@ -10,8 +10,8 @@
1010
app = Flask(__name__)
1111
cache.init_app(app)
1212

13-
@app.route("/", defaults={'exchange': 'binance'})
14-
@app.route("/<exchange>")
13+
@app.route("/", defaults={'exchange': 'binance'}, methods=['GET'])
14+
@app.route("/<exchange>", methods=['GET'])
1515
@cache.cached(timeout=os.getenv('CACHE_TIME', 60*60)) # cache it 1h by default
1616
def get_data(exchange):
1717
# start arbitrage detection
@@ -23,6 +23,16 @@ def get_data(exchange):
2323
'exchange_name': exchange_name
2424
})
2525

26+
@app.route("/", methods=['POST'])
27+
def upload_data():
28+
if request.method == 'POST':
29+
data = request.json
30+
exchange = data.get('exchange', 'binance')
31+
32+
# start arbitrage detection
33+
print(f"Scanning on {exchange}...")
34+
_, _, _ = asyncio.run(triangular_arbitrage.detector.run_detection(exchange))
35+
return jsonify()
2636

2737
if __name__ == "__main__":
2838
load_dotenv()

0 commit comments

Comments
 (0)