Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python error I cannot fix #4772

Closed as not planned
Closed as not planned
❔ question
Labels
@silfopma3h1

Description

@silfopma3h1

Issue I am facing

Hi I was making a python algo trader bot, when I send a message from my telegram bot than he does a trade but I still get the same error and I cannot get it fixed and even co pilot cannot fix it. Test_Telegram.zip I get this error:

Traceback to the issue

2025-04-2915:25:22.910928:Itensorflow/core/util/port.cc:153]oneDNNcustomoperationsareon.Youmayseeslightlydifferentnumericalresultsduetofloating-pointround-offerrorsfromdifferentcomputationorders.Toturnthemoff,settheenvironmentvariableTF_ENABLE_ONEDNN_OPTS=0.2025-04-2915:25:28.360240:Itensorflow/core/util/port.cc:153]oneDNNcustomoperationsareon.Youmayseeslightlydifferentnumericalresultsduetofloating-pointround-offerrorsfromdifferentcomputationorders.Toturnthemoff,settheenvironmentvariableTF_ENABLE_ONEDNN_OPTS=0.Traceback (mostrecentcalllast):File"C:\Users\silfo\Test_Telegram.py",line206,inmain()File"C:\Users\silfo\Test_Telegram.py",line118,inmaintelegram_bot_polling()# Start Telegram bot polling in a separate thread ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\silfo\Test_Telegram.py", line 110, in telegram_bot_polling updater = Updater(token=TELEGRAM_API_TOKEN, use_context=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Updater.init() got an unexpected keyword argument 'token' PS C:\Users\silfo>

Related part of your code

fromtelegramimportUpdatefromtelegram.extimportApplication,CommandHandler,ContextTypes# === Telegram Command handler ===asyncdefstart_trade(update:Update,context:ContextTypes.DEFAULT_TYPE):command=update.message.text.split()iflen(command)<4:awaitupdate.message.reply_text("Gebruik: /trade <symbool> <buy/sell> <aantal>")returnsymbol,side,qty=command[1],command[2],int(command[3])place_trade(symbol,side,qty)awaitupdate.message.reply_text(f"Trade gestart:{side}{qty}{symbol}")# === Telegram Bot Polling ===asyncdeftelegram_bot_polling():application=Application.builder().token(TELEGRAM_API_TOKEN).build()# Corrected methodapplication.add_handler(CommandHandler("trade",start_trade))awaitapplication.run_polling()# === MAIN loop ===asyncdefmain():warmup_start=datetime.now(timezone.utc)warmup_done=Falseforce_trade_done=Falselast_day=warmup_start.date()daily_trade_count=0last_trade_time=warmup_start-timedelta(minutes=1)print("[STARTING] Trading bot initialized",flush=True)whileTrue:now=datetime.now(timezone.utc)ifnotwarmup_doneand (now-warmup_start).total_seconds()>=60:warmup_done=Trueprint(f"[{now}] Warm-up voltooid. Eerste trade uitvoeren...",flush=True)symbol=random.choice(SYMBOLS)cash=get_account_cash()bars=REST_CLIENT.get_bars(symbol,TimeFrame(30,TimeFrameUnit.Minute),limit=1)bars=bars[symbol]ifisinstance(bars,dict)elsebarsiflen(bars)>=1:side='buy'last_close=bars[-1].cqty=int((cash*MAX_RISK_PER_TRADE)/last_close)ifqty>0:place_trade(symbol,side,qty)daily_trade_count+=1last_trade_time=nowforce_trade_done=Trueelse:print(f"[{now}]{symbol} - Te weinig cash voor trade",flush=True)ifnow.date()!=last_day:daily_trade_count=0last_day=now.date()print(f"[{now}] Nieuwe handelsdag - teller reset.",flush=True)if9<now.hour<16or (now.hour==9andnow.minute>=30):open_positions=sum(1fortintrade_historyift['exit_price']isNone)if (now-last_trade_time).total_seconds()>=600andwarmup_done:symbol=random.choice(SYMBOLS)cash=get_account_cash()headlines=get_news_headlines(symbol,days=1)prob,sentiment=estimate_sentiment(headlines)bars=REST_CLIENT.get_bars(symbol,TimeFrame(30,TimeFrameUnit.Minute),limit=2)bars=bars[symbol]ifisinstance(bars,dict)elsebarsiflen(bars)<2:print(f"[{now}]{symbol} - Onvoldoende data",flush=True)awaitasyncio.sleep(60)continuetoday_return= (bars[-1].c-bars[-2].c)/bars[-2].cprint(f"[{now}]{symbol} - Sentiment:{sentiment} ({prob:.2f}), Return:{today_return:.4f}",flush=True)should_trade=Falseifsentiment=='positive'andprob>0.8andtoday_return>0.005:side='buy'should_trade=Trueelifsentiment=='negative'andprob>0.8andtoday_return<-0.005:side='sell'should_trade=Trueelse:print(f"[{now}]{symbol} - Geen trade: voorwaarden niet voldaan",flush=True)ifshould_trade:last_close=bars[-1].cqty=int((cash*MAX_RISK_PER_TRADE)/last_close)ifqty>0:place_trade(symbol,side,qty)daily_trade_count+=1last_trade_time=nowawaitasyncio.sleep(60)# Check every minute# === Running ===if__name__=="__main__":asyncio.run(main())asyncio.run(telegram_bot_polling())

Operating System

Python

Version of Python, python-telegram-bot & dependencies

telegram bot=20.0python = 3.12.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp