11import asyncio
22import os
33from dotenv import load_dotenv
4- from flask import Flask , jsonify
4+ from flask import Flask , jsonify , request
55from flask_caching import Cache
66
77import triangular_arbitrage .detector
1010app = Flask (__name__ )
1111cache .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
1616def 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
2737if __name__ == "__main__" :
2838 load_dotenv ()
0 commit comments