我正在使用python包装器访问api,并且在文档字符串中表示可以提供列表作为必需参数。
这是我用来调用send_orders
包装器功能
def send_orders(self, runner_id, odds, side, stake, temp_id=None, session=None):
"""
Place an order(s) on a runner, multiple orders can be places by providing lists of the required arguments.
:param runner_id: runner(s) on which to place bets.
:type runner_id: int
:param odds: odds at which we wish to place the bet.
:type odds: float
:param side: The type of bet to place, dependent on exchange.
:type side: MatchbookAPI.bin.enums.Side
:param stake: amount in account currency to place on the bet.
:type stake: float
:param temp_id: A helper ID generated by the client to help understand the correlation between multiple submitted offers and their responses.
:type temp_id: str
:param session: requests session to be used.
:type session: requests.Session
:returns: Orders responses, i.e. filled or at exchange or errors.
:raises: MatchbookAPI.bin.exceptions.ApiError
"""
date_time_sent = datetime.datetime.utcnow()
params = {
'offers': [],
'odds-type': self.client.odds_type,
'exchange-type': self.client.exchange_type,
'currency': self.client.currency,
}
if isinstance(runner_id, list):
if isinstance(temp_id, list):
for i, _ in enumerate(runner_id):
params['offers'].append({'runner-id': runner_id[i], 'side': side[i], 'stake': stake[i],
'odds': odds[i], 'temp-id': temp_id[i]})
else:
for i, _ in enumerate(runner_id):
params['offers'].append({'runner-id': runner_id[i], 'side': side[i], 'stake': stake[i],
'odds': odds[i]})
else:
params['offers'].append(
{'runner-id': runner_id, 'side': side, 'stake': stake, 'odds': odds, 'temp-id': temp_id}
)
method = 'offers'
response = self.request("POST", self.client.urn_edge, method, data=params, session=session)
date_time_received = datetime.datetime.utcnow()
return self.process_response(
response.json().get('offers', []), resources.Order, date_time_sent, date_time_received
)
当我尝试通过下面的代码传递列表时,我得到
NameError: name 'back' is not defined
到目前为止我的代码
from matchbook.apiclient import APIClient
from matchbook.enums import Side, MarketStates, MarketNames, Boolean
from matchbook.endpoints import Betting
mb = APIClient('username', 'pass')
mb.login()
offers= [{'runner-id': 1011160690700015, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 1}],
[{'runner-id': 1011382790240015, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 2}],
[{'runner-id': 1011382952570016, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 3}],
[{'runner-id': 1011475761540015, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 4}],
[{'runner-id': 1011553158760016, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 5}],
[{'runner-id': 1011465386150016, 'odds': 5, 'side': back, 'stake': 5, 'temp-id': 6}],
order_insert = mb.betting.send_orders(offers)
有人可以告诉我如何将一个或多个列表作为参数传递给send_orders
吗?
答案 0 :(得分:1)
在您的代码中,您无需先定义变量即可引用变量back
。这就是为什么您收到错误消息NameError: name 'back' is not defined
的原因。
也许您打算将其定义为字符串?
此外,send_orders
似乎要求其参数是每个订单的各个值的列表:
from matchbook import APIClient
from matchbook.enums import Side
mb = APIClient('username', 'pass')
mb.login()
# Add new elements to each of the lists below to send multiple orders
runner_ids = [1011160690700015]
odds = [2.0]
sides = [Side.Back]
stakes = [5.0]
order_insert = mb.betting.send_orders(runner_ids, odds, sides, stakes)