Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 提供函数所需的参数列表_Python_Json_Django_Flask - Fatal编程技术网

Python 提供函数所需的参数列表

Python 提供函数所需的参数列表,python,json,django,flask,Python,Json,Django,Flask,我使用python包装器来访问api,在docstring中,它说您可以提供一个列表作为所需的参数 下面是我用来调用发送订单的函数 包装函数 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 require

我使用python包装器来访问api,在docstring中,它说您可以提供一个列表作为所需的参数

下面是我用来调用
发送订单的函数

包装函数

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
)
当我尝试用下面的代码传递列表时,我得到

name错误:未定义名称“back”

到目前为止我的代码

    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\u orders


链接到代码中的回购

您引用变量
返回
,而无需首先定义它。这就是为什么会出现错误消息
NameError:name“back”未定义

也许你想把它定义为一个字符串

另外,
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)

你想成为什么样的人?在哪里定义?@Carcigenicate back是订单类型。只有两种订单类型back和lay。所以有“side”:回到列表中应该定义它否?你的意思是使用
“back”
(带引号)?要传递字符串吗?现在,您正在将一个尚未定义的变量
传回
。我不确定。我确实知道,如果你像这样将单参数传递到函数中,它就可以工作
mb.betting.send_orders(1011160690700015,2.0,Side.Back,5.0)
你能试试上面的例子吗(也许可以将
Side
参数替换为任何你知道有效的值,比如
Side.Back
)?我试过这个例子,收到了一个
错误的请求。我对响应进行了编辑,只包含了您所说的过去有效的参数,但是是列表形式的。你能再试一次吗?我刚刚意识到,你的答案是正确的。由于某种原因,我的浏览器选项卡被冻结。所以我看不出它是否有效。谢谢你的解决方案!!