This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (41 loc) · 1.96 KB
/
main.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# [START gae_python38_app]
import logging
from flask import Flask
from src.balancer.balancer import Balancer
from src.controller import Controller
from src.shared.type_definitions import Exchange
from src.uniswap_v2.uniswap import Uniswap
app = Flask(__name__)
@app.route('/update/<string:exchange>/<string:entity_type>/')
@app.route('/update/<string:exchange>/<string:entity_type>/<int:min_liquidity>/')
def update(exchange, entity_type, min_liquidity=None):
logger = logging.getLogger(exchange)
if exchange == 'UNI_V2':
controller = Controller(Uniswap(dex_graph_name='benesjan/uniswap-v2', exchange=Exchange.UNI_V2), logger)
elif exchange == 'BALANCER':
controller = Controller(Balancer(), logger)
elif exchange == 'SUSHI':
controller = Controller(Uniswap(dex_graph_name='benesjan/sushi-swap', exchange=Exchange.SUSHI), logger)
elif exchange == 'MATERIA':
controller = Controller(Uniswap(dex_graph_name='materia-dex/materia', exchange=Exchange.MATERIA), logger)
else:
return '{"success": false, "exception": "Unknown exhchange type."}'
try:
if entity_type == 'snaps':
controller.update_snaps(max_objects_in_batch=100)
elif entity_type == 'staked_snaps':
controller.update_staked_snaps(max_objects_in_batch=100)
elif entity_type == 'yields':
controller.update_yields(max_objects_in_batch=100)
elif entity_type == 'pools':
if min_liquidity is None:
return '{"success": false, "exception": "None min_liquidity URL parameter in update of pools."}'
controller.update_pools(max_objects_in_batch=20, min_liquidity=min_liquidity)
else:
return '{"success": false, "exception": "Unknown entity type."}'
except Exception as e:
return f'{"success": false, "exception": {e}}'
return '{"success": true}'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)
# [END gae_python38_app]