@@ -116,7 +116,8 @@ async def _get(self, path, params=None, decimal_return_fields=None,
116116 return self ._convert_return_fields (
117117 res , decimal_return_fields , convert_all )
118118
119- async def _post (self , path , data = None ):
119+ async def _post (self , path , data = None , decimal_return_fields = None ,
120+ convert_all = False ):
120121 json_data = json .dumps (data )
121122 headers = self ._auth_headers (path , method = 'POST' , body = json_data )
122123 path_url = self .API_URL + path
@@ -126,9 +127,11 @@ async def _post(self, path, data=None):
126127 data = json_data ) as response :
127128 res = await response .json ()
128129 response .raise_for_status ()
129- return res
130+ return self ._convert_return_fields (
131+ res , decimal_return_fields , convert_all )
130132
131- async def _delete (self , path , data = None ):
133+ async def _delete (self , path , data = None , decimal_return_fields = None ,
134+ convert_all = False ):
132135 json_data = json .dumps (data )
133136 headers = self ._auth_headers (path , method = 'DELETE' , body = json_data )
134137 path_url = self .API_URL + path
@@ -219,9 +222,13 @@ async def buy(self, product_id=None, price=None, size=None, funds=None,
219222 payload ['size' ] = str (size )
220223 if funds is not None :
221224 payload ['funds' ] = str (funds )
225+
222226 payload .update (kwargs )
223227
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' })
225232
226233 async def sell (self , product_id = None , price = None , size = None , funds = None ,
227234 ** kwargs ):
@@ -239,7 +246,11 @@ async def sell(self, product_id=None, price=None, size=None, funds=None,
239246
240247 payload .update (kwargs )
241248
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' })
243254
244255 async def cancel_order (self , order_id ):
245256 assert self .authenticated
@@ -252,11 +263,19 @@ async def cancel_all(self, data=None, product_id=''):
252263
253264 async def get_order (self , order_id ):
254265 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' })
256271
257272 async def get_orders (self ):
258273 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' })
260279
261280 async def get_fills (self , order_id = '' , product_id = '' ):
262281 assert self .authenticated
@@ -265,14 +284,19 @@ async def get_fills(self, order_id='', product_id=''):
265284 params ['order_id' ] = order_id
266285 if product_id :
267286 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' })
269290
270291 async def get_fundings (self , status ):
271292 assert self .authenticated
272293 params = {}
273294 if status :
274295 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' })
276300
277301 async def repay_funding (self , amount , currency ):
278302 assert self .authenticated
@@ -291,7 +315,8 @@ async def margin_transfer(self, margin_profile_id, transfer_type,
291315 "currency" : currency , # example: USD
292316 "amount" : str (amount ),
293317 }
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' })
295320
296321 async def get_position (self ):
297322 assert self .authenticated
0 commit comments