Я пытаюсь использовать переменные из предыдущей версии в проге как market_id и selection_id, когда я использую place_order с использованием Betfairlightweight. Размещение кода ставки работает, когда я выполняю тест с определенными идентификаторами, но я не могу заставить его работать с переменными.
Я попытался преобразовать selection_id (который, я думаю, был в формеnumpy.float64) в строку. Когда я выполняю тестовый прогон, я могу использовать переменные, которые я только что назначил, например,
# this is the test that works fine
def bet():
stake = 2
selection = '12988828'
market = '1.163978618'
limit_order_filter = betfairlightweight.filters.limit_order(
size=str(stake),
price=12,
persistence_type='LAPSE')
instructions_filter = betfairlightweight.filters.place_instruction(
selection_id=str(selection),
order_type="LIMIT",
side="BACK",
limit_order=limit_order_filter)
order = trading.betting.place_orders(
market_id=str(market),
customer_strategy_ref='back_the_fav',
instructions=[instructions_filter])
# but this is the code that doesnt
def placing_a_back_bet_on_the_favourite_horse():
stake = 2
limit_order_filter = betfairlightweight.filters.limit_order(
size=str(stake),
price=12,
persistence_type='LAPSE')
instructions_filter = betfairlightweight.filters.place_instruction(
selection_id=str(fav_selection_id),
order_type="LIMIT",
side="BACK",
limit_order=limit_order_filter)
order = trading.betting.place_orders(
market_id=str(currentraceid),
customer_strategy_ref='back_the_fav',
instructions=[instructions_filter] )
def checking_the_odds_of_the_top(): # the code for how the variables are created...this is the fav_selection_id
global fav_selection_id
fav_selection_id = runners_df.iloc[0,1]
def process_runner_books(runner_books):#from
best_back_prices = [runner_book.ex.available_to_back[0].price
if runner_book.ex.available_to_back
else 100
for runner_book
in runner_books]
best_lay_prices = [runner_book.ex.available_to_lay[0].price
if runner_book.ex.available_to_lay
else 1000.0
for runner_book
in runner_books]
selection_ids = [runner_book.selection_id for runner_book in runner_books]
last_prices_traded = [runner_book.last_price_traded for runner_book in runner_books]
df = pd.DataFrame({
'Last Price Traded': last_prices_traded,
'Best Back Price': best_back_prices,
'Selection ID': selection_ids,
'Best Lay Price': best_lay_prices,
}).set_index('Last Price Traded').sort_index()
return df
def getting_market_info_for_all_the_horses_in_a_race():
global runners_df
try:
price_filter = betfairlightweight.filters.price_projection(price_data=['EX_BEST_OFFERS'])
market_books = trading.betting.list_market_book(market_ids=[currentraceid],price_projection=price_filter)
market_book = market_books[0]
runners_df = process_runner_books(market_book.runners)
print(runners_df)
def finding_the_races(): # and the currentraceid is from...
global currentraceid
global marketfinishtime
datetime_in_a_week = (datetime.datetime.utcnow() + datetime.timedelta(hours=1)).strftime("%Y-%m-%dT%TZ")
market_catalogue_filter = betfairlightweight.filters.market_filter(event_ids=[currentmeetingid], market_start_time={'to': datetime_in_a_week})
market_catalogues = trading.betting.list_market_catalogue(filter=market_catalogue_filter,
market_projection=["MARKET_START_TIME"],
max_results='10',
sort='FIRST_TO_START'
)
market_types_mooney_valley = pd.DataFrame({
'mst':[market_cat_object.market_start_time for market_cat_object in market_catalogues],
'Market ID': [market_cat_object.market_id for market_cat_object in market_catalogues],
'Market Name': [market_cat_object.market_name for market_cat_object in market_catalogues],
'Total Matched': [market_cat_object.total_matched for market_cat_object in market_catalogues],
}).set_index('Total Matched').sort_index(ascending=False)
print(market_types_mooney_valley)
marketfinishtime = market_types_mooney_valley.iloc[0,0]
currentraceid = market_types_mooney_valley.iloc[0,1]
Извините за действительно длинный Q, но я слишком много обошел круг по этому вопросу слишком долго. Заранее спасибо за помощь