Bot & Automation
Treding Forex Ai
/root/hermes-projects/Treding Forex Ai
mt5-bridge/scripts/toggle-bridge-mode.ps1
text
param(
[ValidateSet("dry-run", "demo", "real")]
[string]$Mode = "dry-run"
)
$ErrorActionPreference = "Stop"
$bridgeRoot = Split-Path -Parent $PSScriptRoot
$envPath = Join-Path $bridgeRoot ".env"
$realConfirmation = "I_UNDERSTAND_REAL_MONEY_RISK"
if (-not (Test-Path -LiteralPath $envPath)) {
throw ".env bridge tidak ditemukan."
}
function Set-EnvValue {
param(
[Parameter(Mandatory = $true)]
[string]$Content,
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Value
)
$line = "$Name=$Value"
if ($Content -match "(?m)^$([regex]::Escape($Name))=") {
return [regex]::Replace($Content, "(?m)^$([regex]::Escape($Name))=.*$", $line)
}
return $Content.TrimEnd() + [Environment]::NewLine + $line + [Environment]::NewLine
}
$content = Get-Content -Raw -LiteralPath $envPath
switch ($Mode) {
"dry-run" {
$content = Set-EnvValue -Content $content -Name "BRIDGE_DRY_RUN" -Value "true"
$content = Set-EnvValue -Content $content -Name "ALLOW_DEMO_TRADING" -Value "false"
$content = Set-EnvValue -Content $content -Name "ALLOW_REAL_TRADING" -Value "false"
$content = Set-EnvValue -Content $content -Name "REAL_TRADING_CONFIRM" -Value ""
$label = "DRY-RUN / PAPER. Tidak ada order dikirim ke MT5."
}
"demo" {
$content = Set-EnvValue -Content $content -Name "BRIDGE_DRY_RUN" -Value "false"
$content = Set-EnvValue -Content $content -Name "ALLOW_DEMO_TRADING" -Value "true"
$content = Set-EnvValue -Content $content -Name "ALLOW_REAL_TRADING" -Value "false"
$content = Set-EnvValue -Content $content -Name "REAL_TRADING_CONFIRM" -Value ""
$label = "DEMO MT5. Order sungguhan hanya boleh masuk ke akun demo."
}
"real" {
Write-Host "PERINGATAN: mode real dapat membuka/menutup posisi dengan uang nyata." -ForegroundColor Red
Write-Host "Pastikan REQUIRED_ACCOUNT_LOGIN dan REQUIRED_ACCOUNT_SERVER sudah benar." -ForegroundColor Yellow
$typed = Read-Host "Ketik persis untuk lanjut: $realConfirmation"
if ($typed -ne $realConfirmation) {
throw "Konfirmasi real trading tidak cocok. Tidak ada perubahan."
}
$content = Set-EnvValue -Content $content -Name "BRIDGE_DRY_RUN" -Value "false"
$content = Set-EnvValue -Content $content -Name "ALLOW_DEMO_TRADING" -Value "false"
$content = Set-EnvValue -Content $content -Name "ALLOW_REAL_TRADING" -Value "true"
$content = Set-EnvValue -Content $content -Name "REAL_TRADING_CONFIRM" -Value $realConfirmation
$label = "REAL MT5. Order live aktif hanya jika bridge melihat akun real yang sesuai guard."
}
}
[System.IO.File]::WriteAllText((Resolve-Path -LiteralPath $envPath), $content)
Write-Host "==============================================" -ForegroundColor Green
Write-Host "Mode bridge: $label" -ForegroundColor Green
Write-Host "Restart bridge diperlukan agar env baru terbaca." -ForegroundColor Green
Write-Host "==============================================" -ForegroundColor Green