main

๐Ÿฆ‰ AthenaAI is an AI-powered ensemble machine-learning trading bot for PocketOption, built on BinaryOptionsToolsV2 โ†’ Get it on GitLab
๐Ÿ’ฌ Need help? Join the Chipa Discord ยท โšก Go no-code with ChipaEditor

Source: main.py. The live-trading entry point. It reads configuration exclusively from environment variables (optionally loaded from a .env file), constructs a BotConfig, and runs AITradingBot under asyncio.run(). No secrets live in source code โ€” the PocketOption session ID must come from the PO_SSID environment variable (see PO_SSID).

Functions

_load_dotenv(path: str = ".env") -> None

Minimal .env loader with no external dependency.

ParameterTypeDefaultMeaning
pathstr".env"Path to the dotenv file

Behavior:

  • Returns silently if path is not a file.
  • Reads the file as UTF-8, line by line. Skips blank lines, lines starting with #, and lines without =.
  • Splits on the first =; strips whitespace and surrounding single/double quotes from the value.
  • Uses os.environ.setdefault(...) โ€” real environment variables always win over .env values. Side effect: mutates os.environ.

Edge cases: no interpolation, no export prefix support, no multi-line values. A malformed line is simply skipped.

_int_tuple(raw: str, fallback: tuple) -> tuple

Parses a comma-separated string of integers (e.g. "120,300,600") into a tuple.

ParameterTypeDefaultMeaning
rawstrโ€”Comma-separated integers; empty items are ignored
fallbacktupleโ€”Returned when raw is empty or unparseable

Returns the parsed tuple, or fallback if the result is empty. On ValueError it prints Warning: could not parse '<raw>', using <fallback> to stdout and returns fallback. Used only for PO_EXPIRY_OPTIONS.

build_config() -> BotConfig

Builds a BotConfig from environment variables. Only these fields are settable via the environment; everything else keeps the dataclass default from src/config.py:

Env varBotConfig fieldDefault used here
PO_SSIDssid""
PO_ASSETasset"EURUSD"
PO_TIMEFRAMEtimeframe60 (seconds)
PO_EXPIRY_OPTIONSexpiry_options(120, 300, 600) (seconds)
PO_DEFAULT_EXPIRYdefault_expiry300 (seconds)
PO_BASE_STAKEbase_stake25.0 ($)
PO_MAX_STAKEmax_stake100.0 ($)
PO_MIN_CONFmin_confidence0.63 (fraction)
PO_MAX_CONFmax_confidence0.85 (fraction)
PO_MAX_DAILY_LOSSmax_daily_loss300.0 ($)
PO_DATASETdataset_path"EURUSD_M1.csv"
PO_BRAIN_PATHbrain_path"athena_brain.pkl"
PO_REQUIRE_ALIGNMENTrequire_indicator_alignmentTrue (any value other than "0" enables it)

Note: PO_DATASET and PO_BRAIN_PATH defaults here ("EURUSD_M1.csv", "athena_brain.pkl") override the BotConfig dataclass defaults ("", "athena_po_brain.pkl"). PO_RETRAIN is not read here โ€” it is read directly by AITradingBot.start() (see bot.md).

Failure behavior: int(...)/float(...) conversions raise ValueError unhandled if an env var contains a non-numeric value; the process exits with a traceback.

main() -> int

  1. Calls _load_dotenv() (default .env in the working directory).
  2. Calls build_config().
  3. If config.ssid is empty, prints an error with export/$env: examples to stderr and returns 1.
  4. Otherwise constructs AITradingBot(config) and runs asyncio.run(bot.start()).
  5. On KeyboardInterrupt (Ctrl+C), prints Interrupted, shutting down... and runs asyncio.run(bot.stop()) โ€” which saves the brain file to disk (side effect; see bot.md).

Returns 0 on normal shutdown, 1 when PO_SSID is missing.

The module guard is raise SystemExit(main()), so the return value becomes the process exit code.

Usage

export PO_SSID='your-session-id'
export PO_ASSET='EURUSD'
python main.py
$env:PO_SSID='your-session-id'
python main.py

See also

๐Ÿ’ฌ Unsure how this interacts with the rest of the configuration? Ask in the Chipa Discord โ€” or prototype strategies no-code with ChipaEditor.