-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
227 lines (205 loc) · 5.76 KB
/
server.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
from flask import Flask, jsonify, request, render_template
from flask_restful import Api, Resource
import json
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'api'))
import market
import position
import funding
import liquidation
import account
import order
import trader
app = Flask(__name__)
api = Api(app)
@app.route('/')
@app.route('/v2')
def hello():
return render_template('hello.html')
# overview and markets
@app.route('/v2/protocol', methods=['GET', 'POST'])
def getProtocol():
return jsonify({
'result': market.protocol()
})
@app.route('/v2/markets', methods=['GET', 'POST'])
def getMarkets():
payload = json.loads(request.data) if request.data else {}
result = market.markets(
_asset_list = payload.get('assets')
)
return jsonify({
'result': result
})
@app.route('/v2/markets/specs', methods=['GET', 'POST'])
def getMarketSpecs():
payload = json.loads(request.data) if request.data else {}
result = market.specs(
_asset_list = payload.get('assets')
)
return jsonify({
'result': result
})
# positions, trades, ...
@app.route('/v2/position/trades', methods=['GET', 'POST'])
def getTrades():
payload = json.loads(request.data) if request.data else {}
result = position.trades(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/position/open', methods=['GET', 'POST'])
def getOpenPositions():
payload = json.loads(request.data) if request.data else {}
result = position.openPositions(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/position/closed', methods=['GET', 'POST'])
def getClosedPositions():
payload = json.loads(request.data) if request.data else {}
result = position.closedPositions(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
# funding
@app.route('/v2/funding/updates', methods=['GET', 'POST'])
def getFundingUpdates():
payload = json.loads(request.data) if request.data else {}
result = funding.updates(
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/funding/payments', methods=['GET', 'POST'])
def getFundingPayments():
payload = json.loads(request.data) if request.data else {}
result = funding.settlements(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
# liquidations
@app.route('/v2/liquidations', methods=['GET', 'POST'])
def getLiquidations():
payload = json.loads(request.data) if request.data else {}
result = liquidation.liquidations(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_liquidator = payload.get('liquidator'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
# order
@app.route('/v2/order/open', methods=['GET', 'POST'])
def getOpenOrders():
payload = json.loads(request.data) if request.data else {}
result = order.openOrders(
_maker = payload.get('maker'),
_asset_list = payload.get('assets'),
_lower_tick = payload.get('lower_tick'),
_upper_tick = payload.get('upper_tick'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/order/maker/profile', methods=['GET', 'POST'])
def getMakerStats():
payload = json.loads(request.data) if request.data else {}
result = order.makers(
_address = payload.get('maker'),
)
return jsonify({
'result': result
})
# trader
@app.route('/v2/trader/profile', methods=['GET', 'POST'])
def getTraderProfile():
payload = json.loads(request.data) if request.data else {}
result = trader.profile(
_address = payload.get('trader'),
)
return jsonify({
'result': result
})
@app.route('/v2/trader/badDebts', methods=['GET', 'POST'])
def getTraderBadDebts():
payload = json.loads(request.data) if request.data else {}
result = trader.badDebts(
_trader = payload.get('trader'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/trader/dayData', methods=['GET', 'POST'])
def getTraderDayData():
payload = json.loads(request.data) if request.data else {}
if 'trader' not in payload:
return jsonify({
'error': 'Trader address missing.'
})
result = trader.dayData(
_trader = payload.get('trader'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
# account
@app.route('/v2/account/deposits', methods=['GET', 'POST'])
def getDeposits():
payload = json.loads(request.data) if request.data else {}
result = account.deposits(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
@app.route('/v2/account/withdrawals', methods=['GET', 'POST'])
def getWithdrawals():
payload = json.loads(request.data) if request.data else {}
result = account.withdrawals(
_trader = payload.get('trader'),
_asset_list = payload.get('assets'),
_start = payload.get('start'),
_end = payload.get('end')
)
return jsonify({
'result': result
})
if __name__ == '__main__':
app.run(debug = True)