本文整理汇总了Python中request.Request.set_path_param方法的典型用法代码示例。如果您正苦于以下问题:Python Request.set_path_param方法的具体用法?Python Request.set_path_param怎么用?Python Request.set_path_param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.Request
的用法示例。
在下文中一共展示了Request.set_path_param方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def get(
self,
accountID,
instrument,
**kwargs
):
"""Instrument Position
Get the details of a single Instrument's Position in an Account. The
Position may by open or not.
Parameters
----------
accountID :
ID of the Account to fetch Positions for.
instrument :
Name of the Instrument fetch the Position of.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/positions/{instrument}'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'instrument',
instrument
)
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('position') is not None:
parsed_body['position'] = \
Position.from_dict(
jbody['position']
)
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
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 405:
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')
response.body = parsed_body
return response
示例2: close
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [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']
#.........这里部分代码省略.........
示例3: list
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def list(
self,
accountID,
**kwargs
):
"""List Positions
List all Positions for an Account. The Positions returned are for every
instrument that has had a position during the lifetime of an a Account.
Parameters
----------
accountID :
ID of the Account to fetch Positions for.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/positions'
)
request.set_path_param(
'accountID',
accountID
)
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('positions') is not None:
parsed_body['positions'] = [
Position.from_dict(d)
for d in jbody.get('positions')
]
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
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 405:
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')
response.body = parsed_body
return response
示例4: list_open
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def list_open(
self,
accountID,
**kwargs
):
"""Open Positions
List all open Positions for an Account. An open Position is a Position
in an Account that currently has a Trade opened for it.
Parameters
----------
accountID :
ID of the Account to fetch open Positions for.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/openPositions'
)
request.set_path_param(
'accountID',
accountID
)
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('positions') is not None:
parsed_body['positions'] = [
Position.from_dict(d)
for d in jbody.get('positions')
]
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
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 405:
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')
response.body = parsed_body
return response
示例5: close
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [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:
#.........这里部分代码省略.........
示例6: set_client_extensions
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [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')
#.........这里部分代码省略.........
示例7: get
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def get(
self,
accountID,
tradeID,
**kwargs
):
"""Trade Details
Get the details of a specific Trade in an Account
Parameters
----------
accountID :
ID of the Account to fetch Trades for.
tradeID :
ID of the Trade to fetch
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/trades/{tradeID}'
)
request.set_path_param(
'accountID',
accountID
)
request.set_path_param(
'tradeID',
tradeID
)
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('trade') is not None:
parsed_body['trade'] = \
Trade.from_dict(
jbody['trade']
)
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
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 405:
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')
response.body = parsed_body
return response
示例8: list_open
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def list_open(
self,
accountID,
**kwargs
):
"""List Open Trades
Get the list of open Trades for an Account
Parameters
----------
accountID :
ID of the Account to fetch Trades for.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/openTrades'
)
request.set_path_param(
'accountID',
accountID
)
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('trades') is not None:
parsed_body['trades'] = [
Trade.from_dict(d)
for d in jbody.get('trades')
]
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
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 405:
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')
response.body = parsed_body
return response
示例9: list
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def list(
self,
accountID,
**kwargs
):
"""List Trades
Get a list of Trades for an Account
Parameters
----------
accountID :
ID of the Account to fetch Trades for.
ids : array, optional
List of Trade IDs to retrieve.
state : , optional
The state to filter the requested Trades by.
instrument : , optional
The instrument to filter the requested Trades by.
count : integer, optional
The maximum number of Trades to return.
beforeID : , optional
The maximum Trade ID to return. If not provided the most recent
Trades in the Account are returned.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/trades'
)
request.set_path_param(
'accountID',
accountID
)
request.set_param(
'ids',
kwargs.get('ids')
)
request.set_param(
'state',
kwargs.get('state')
)
request.set_param(
'instrument',
kwargs.get('instrument')
)
request.set_param(
'count',
kwargs.get('count')
)
request.set_param(
'beforeID',
kwargs.get('beforeID')
)
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('trades') is not None:
parsed_body['trades'] = [
Trade.from_dict(d)
for d in jbody.get('trades')
]
if jbody.get('lastTransactionID') is not None:
parsed_body['lastTransactionID'] = \
jbody.get('lastTransactionID')
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')
if response.status is 404:
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
#.........这里部分代码省略.........
示例10: set_dependent_orders
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [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:
#.........这里部分代码省略.........
示例11: get
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import set_path_param [as 别名]
def get(
self,
accountID,
**kwargs
):
"""Current Prices
Get pricing information for a specified list of Instruments within an
Account.
Parameters
----------
accountID :
ID of the Account to fetch current Prices for.
instruments : array, optional
List of Instruments to get pricing for.
since : , optional
Date/Time filter to apply to the returned prices. Only prices with
a time later than this filter will be provided.
"""
request = Request(
'GET',
'/v3/accounts/{accountID}/pricing'
)
request.set_path_param(
'accountID',
accountID
)
request.set_param(
'instruments',
kwargs.get('instruments')
)
request.set_param(
'since',
kwargs.get('since')
)
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('prices') is not None:
parsed_body['prices'] = [
Price.from_dict(d)
for d in jbody.get('prices')
]
if response.status is 400:
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')
if response.status is 404:
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 405:
if jbody.get('errorCode') is not None:
parsed_body['errorCode'] = \
jbody.get('errorCode')
if jbody.get('errorMessage') is not None:
parsed_body['errorMessage'] = \
#.........这里部分代码省略.........