本文整理汇总了Python中request.Request.set_body_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Request.set_body_dict方法的具体用法?Python Request.set_body_dict怎么用?Python Request.set_body_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.Request
的用法示例。
在下文中一共展示了Request.set_body_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_body_dict [as 别名]
def close(
self,
accountID,
instrument,
**kwargs
):
"""Close Position
Closeout the open Position for a specific instrument in an Account.
Parameters
----------
accountID :
ID of the Account to close a Position in.
instrument :
Name of the Instrument to close the Positon of.
longUnits : string, optional
Indication of how much of the long Position to closeout. Either the
string "ALL", the string "NONE", or a DecimalNumber representing
how many units of the long position to close using a
PositionCloseout MarketOrder. The units specified must always be
positive.
longClientExtensions : None, optional
The client extensions to add to the MarketOrder used to close the
long position.
shortUnits : string, optional
Indication of how much of the short Position to closeout. Either
the string "ALL", the string "NONE", or a DecimalNumber
representing how many units of the short position to close using a
PositionCloseout MarketOrder. The units specified must always be
positive.
shortClientExtensions : None, optional
The client extensions to add to the MarketOrder used to close the
short position.
"""
request = Request(
'PUT',
'/v3/accounts/{accountID}/positions/{instrument}/close'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'instrument',
instrument
)
body = EntityDict()
body.set('longUnits', kwargs.get('longUnits'))
body.set('longClientExtensions', kwargs.get('longClientExtensions'))
body.set('shortUnits', kwargs.get('shortUnits'))
body.set('shortClientExtensions', kwargs.get('shortClientExtensions'))
request.set_body_dict(body.dict)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
if response.status is 200:
if jbody.get('longOrderCreateTransaction') is not None:
parsed_body['longOrderCreateTransaction'] = \
transaction.MarketOrderTransaction.from_dict(
jbody['longOrderCreateTransaction']
)
if jbody.get('longOrderFillTransaction') is not None:
parsed_body['longOrderFillTransaction'] = \
transaction.OrderFillTransaction.from_dict(
jbody['longOrderFillTransaction']
)
if jbody.get('longOrderCancelTransaction') is not None:
parsed_body['longOrderCancelTransaction'] = \
transaction.OrderCancelTransaction.from_dict(
jbody['longOrderCancelTransaction']
)
if jbody.get('shortOrderCreateTransaction') is not None:
parsed_body['shortOrderCreateTransaction'] = \
transaction.MarketOrderTransaction.from_dict(
jbody['shortOrderCreateTransaction']
#.........这里部分代码省略.........
示例2: set_client_extensions
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_body_dict [as 别名]
def set_client_extensions(
self,
accountID,
tradeID,
**kwargs
):
"""Set Trade Client Extensions
Update the Client Extensions for a Trade
Parameters
----------
accountID :
ID of the Account.
tradeID :
ID of the Trade to update the Client Extension of.
clientExtensions : None, optional
The Client Extensions to update the Trade with.
"""
request = Request(
'PUT',
'/v3/accounts/{accountID}/trades/{tradeID}/clientExtensions'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'tradeID',
tradeID
)
body = EntityDict()
body.set('clientExtensions', kwargs.get('clientExtensions'))
request.set_body_dict(body.dict)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
if response.status is 200:
if jbody.get('tradeClientExtensionsModifyTransaction') is not None:
parsed_body['tradeClientExtensionsModifyTransaction'] = \
transaction.TradeClientExtensionsModifyTransaction.from_dict(
jbody['tradeClientExtensionsModifyTransaction']
)
if jbody.get('relatedTransactionIDs') is not None:
parsed_body['relatedTransactionIDs'] = \
jbody.get('relatedTransactionIDs')
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
if response.status is 400:
if jbody.get('tradeClientExtensionsModifyRejectTransaction') is not None:
parsed_body['tradeClientExtensionsModifyRejectTransaction'] = \
transaction.TradeClientExtensionsModifyRejectTransaction.from_dict(
jbody['tradeClientExtensionsModifyRejectTransaction']
)
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
if response.status is 401:
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
jbody.get('errorMessage')
#.........这里部分代码省略.........
示例3: set_dependent_orders
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_body_dict [as 别名]
def set_dependent_orders(
self,
accountID,
tradeID,
**kwargs
):
"""Set Dependent Orders
Create, replace and cancel a Trade's dependent Orders (Take Profit,
Stop Loss and Trailing Stop Loss) through the Trade itself
Parameters
----------
accountID :
ID of the Account.
tradeID :
ID of the Trade to modify the dependent Orders of.
takeProfit : None, optional
The specification of the Take Profit to create/modify/cancel. If
takeProfit is set to null, the Take Profit Order will be cancelled
if it exists. If takeProfit is not provided, the exisiting Take
Profit Order will not be modified. If a sub-field of takeProfit is
not specified, that field will be set to a default value on create,
and be inherited by the replacing order on modify.
stopLoss : None, optional
The specification of the Stop Loss to create/modify/cancel. If
stopLoss is set to null, the Stop Loss Order will be cancelled if
it exists. If stopLoss is not provided, the exisiting Stop Loss
Order will not be modified. If a sub-field of stopLoss is not
specified, that field will be set to a default value on create, and
be inherited by the replacing order on modify.
trailingStopLoss : None, optional
The specification of the Trailing Stop Loss to
create/modify/cancel. If trailingStopLoss is set to null, the
Trailing Stop Loss Order will be cancelled if it exists. If
trailingStopLoss is not provided, the exisiting Trailing Stop Loss
Order will not be modified. If a sub-field of trailngStopLoss is
not specified, that field will be set to a default value on create,
and be inherited by the replacing order on modify.
"""
request = Request(
'PUT',
'/v3/accounts/{accountID}/trades/{tradeID}/orders'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'tradeID',
tradeID
)
body = EntityDict()
body.set('takeProfit', kwargs.get('takeProfit'))
body.set('stopLoss', kwargs.get('stopLoss'))
body.set('trailingStopLoss', kwargs.get('trailingStopLoss'))
request.set_body_dict(body.dict)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
if response.status is 200:
if jbody.get('takeProfitOrderCancelTransaction') is not None:
parsed_body['takeProfitOrderCancelTransaction'] = \
transaction.OrderCancelTransaction.from_dict(
jbody['takeProfitOrderCancelTransaction']
)
if jbody.get('takeProfitOrderTransaction') is not None:
parsed_body['takeProfitOrderTransaction'] = \
transaction.TakeProfitOrderTransaction.from_dict(
jbody['takeProfitOrderTransaction']
)
if jbody.get('takeProfitOrderFillTransaction') is not None:
parsed_body['takeProfitOrderFillTransaction'] = \
transaction.OrderFillTransaction.from_dict(
jbody['takeProfitOrderFillTransaction']
)
if jbody.get('takeProfitOrderCreatedCancelTransaction') is not None:
#.........这里部分代码省略.........
示例4: close
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_body_dict [as 别名]
def close(
self,
accountID,
tradeID,
**kwargs
):
"""Close Trade
Close (partially or fully) a specific open Trade in an Account
Parameters
----------
accountID :
ID of the Account to close a Trade in.
tradeID :
ID of the Trade to close.
units : string, optional
Indication of how much of the Trade to close. Either the string
"ALL" (indicating that all of the Trade should be closed), or a
DecimalNumber representing the number of units of the open Trade to
Close using a TradeClose MarketOrder. The units specified must
always be positive, and the magnitude of the value cannot exceed
the magnitude of the Trade's open units.
"""
request = Request(
'PUT',
'/v3/accounts/{accountID}/trades/{tradeID}/close'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'tradeID',
tradeID
)
body = EntityDict()
body.set('units', kwargs.get('units'))
request.set_body_dict(body.dict)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
if response.status is 200:
if jbody.get('orderCreateTransaction') is not None:
parsed_body['orderCreateTransaction'] = \
transaction.MarketOrderTransaction.from_dict(
jbody['orderCreateTransaction']
)
if jbody.get('orderFillTransaction') is not None:
parsed_body['orderFillTransaction'] = \
transaction.OrderFillTransaction.from_dict(
jbody['orderFillTransaction']
)
if jbody.get('orderCancelTransaction') is not None:
parsed_body['orderCancelTransaction'] = \
transaction.OrderCancelTransaction.from_dict(
jbody['orderCancelTransaction']
)
if jbody.get('relatedTransactionIDs') is not None:
parsed_body['relatedTransactionIDs'] = \
jbody.get('relatedTransactionIDs')
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
if response.status is 400:
if jbody.get('orderRejectTransaction') is not None:
parsed_body['orderRejectTransaction'] = \
transaction.MarketOrderRejectTransaction.from_dict(
jbody['orderRejectTransaction']
)
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
#.........这里部分代码省略.........
示例5: login
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_body_dict [as 别名]
def login(
self,
**kwargs
):
"""Login
Obtain an authorization token for a client using their username and
password.
Parameters
----------
username : string, optional
The client's username.
password : string, optional
The client's password.
"""
request = Request(
'POST',
'/v3/login'
)
body = EntityDict()
body.set('username', kwargs.get('username'))
body.set('password', kwargs.get('password'))
request.set_body_dict(body.dict)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application/json"):
return response
jbody = json.loads(response.raw_body)
parsed_body = {}
if response.status is 200:
if jbody.get('token') is not None:
parsed_body['token'] = \
jbody.get('token')
if response.status is 400:
parsed_body = jbody
if response.status is 401:
parsed_body = jbody
if response.status is 405:
parsed_body = jbody
response.body = parsed_body
return response