@@ -116,7 +116,8 @@ async def _get(self, path, params=None, decimal_return_fields=None,
116
116
return self ._convert_return_fields (
117
117
res , decimal_return_fields , convert_all )
118
118
119
- async def _post (self , path , data = None ):
119
+ async def _post (self , path , data = None , decimal_return_fields = None ,
120
+ convert_all = False ):
120
121
json_data = json .dumps (data )
121
122
headers = self ._auth_headers (path , method = 'POST' , body = json_data )
122
123
path_url = self .API_URL + path
@@ -126,9 +127,11 @@ async def _post(self, path, data=None):
126
127
data = json_data ) as response :
127
128
res = await response .json ()
128
129
response .raise_for_status ()
129
- return res
130
+ return self ._convert_return_fields (
131
+ res , decimal_return_fields , convert_all )
130
132
131
- async def _delete (self , path , data = None ):
133
+ async def _delete (self , path , data = None , decimal_return_fields = None ,
134
+ convert_all = False ):
132
135
json_data = json .dumps (data )
133
136
headers = self ._auth_headers (path , method = 'DELETE' , body = json_data )
134
137
path_url = self .API_URL + path
@@ -219,9 +222,13 @@ async def buy(self, product_id=None, price=None, size=None, funds=None,
219
222
payload ['size' ] = str (size )
220
223
if funds is not None :
221
224
payload ['funds' ] = str (funds )
225
+
222
226
payload .update (kwargs )
223
227
224
- return await self ._post ('/orders' , data = payload )
228
+ return await self ._post (
229
+ '/orders' , data = payload ,
230
+ decimal_return_fields = {'price' , 'size' , 'fill_fees' , 'filled_size' ,
231
+ 'executed_value' })
225
232
226
233
async def sell (self , product_id = None , price = None , size = None , funds = None ,
227
234
** kwargs ):
@@ -239,7 +246,11 @@ async def sell(self, product_id=None, price=None, size=None, funds=None,
239
246
240
247
payload .update (kwargs )
241
248
242
- return await self ._post ('/orders' , data = payload )
249
+ return await self ._post (
250
+ '/orders' , data = payload ,
251
+ decimal_return_fields = {'price' , 'size' , 'fill_fees' , 'filled_size' ,
252
+ 'executed_value' , 'funds' ,
253
+ 'specified_funds' })
243
254
244
255
async def cancel_order (self , order_id ):
245
256
assert self .authenticated
@@ -252,11 +263,19 @@ async def cancel_all(self, data=None, product_id=''):
252
263
253
264
async def get_order (self , order_id ):
254
265
assert self .authenticated
255
- return await self ._get (f'/orders/{ order_id } ' )
266
+ return await self ._get (
267
+ f'/orders/{ order_id } ' ,
268
+ decimal_return_fields = {'price' , 'size' , 'fill_fees' , 'filled_size' ,
269
+ 'executed_value' , 'funds' ,
270
+ 'specified_funds' })
256
271
257
272
async def get_orders (self ):
258
273
assert self .authenticated
259
- return await self ._get ('/orders' , pagination = True )
274
+ return await self ._get (
275
+ '/orders' , pagination = True ,
276
+ decimal_return_fields = {'price' , 'size' , 'fill_fees' , 'filled_size' ,
277
+ 'executed_value' , 'funds' ,
278
+ 'specified_funds' })
260
279
261
280
async def get_fills (self , order_id = '' , product_id = '' ):
262
281
assert self .authenticated
@@ -265,14 +284,19 @@ async def get_fills(self, order_id='', product_id=''):
265
284
params ['order_id' ] = order_id
266
285
if product_id :
267
286
params ['product_id' ] = product_id or self .product_id
268
- return await self ._get ('/fills' , params = params , pagination = True )
287
+ return await self ._get (
288
+ '/fills' , params = params , pagination = True ,
289
+ decimal_return_fields = {'price' , 'size' , 'fee' })
269
290
270
291
async def get_fundings (self , status ):
271
292
assert self .authenticated
272
293
params = {}
273
294
if status :
274
295
params ['status' ] = status
275
- return await self ._get ('/funding' , params = params , pagination = True )
296
+ return await self ._get (
297
+ '/funding' , params = params , pagination = True ,
298
+ decimal_return_fields = {'amount' , 'repaid_amount' ,
299
+ 'default_amount' })
276
300
277
301
async def repay_funding (self , amount , currency ):
278
302
assert self .authenticated
@@ -291,7 +315,8 @@ async def margin_transfer(self, margin_profile_id, transfer_type,
291
315
"currency" : currency , # example: USD
292
316
"amount" : str (amount ),
293
317
}
294
- return await self ._post ('/profiles/margin-transfer' , data = payload )
318
+ return await self ._post ('/profiles/margin-transfer' , data = payload ,
319
+ decimal_return_fields = {'amount' })
295
320
296
321
async def get_position (self ):
297
322
assert self .authenticated
0 commit comments