Provide lists as required arguments to function

Question:

I’m using a python wrapper to access an api and in the docstring it says that you can provide a lists as required arguments.

Here is the function I’m using to call send_orders

wrapper function

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
)

When I try pass the list with my below code I get

NameError: name 'back' is not defined

my code so far

    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)

Can anyone tell me how I can pass a list or lists as arguments to send_orders ?

Link to the repo https://github.com/rozzac90/matchbook

Asked By: tomoc4

||

Answers:

In your code you reference the variable back without first defining it. That is why you get the error message NameError: name 'back' is not defined.

Maybe you meant to define it as a string?

Also, the send_orders seems to require its arguments be lists of the individual values for each order:

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)
Answered By: Pasa
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.