diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 540e804..f845bcc 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -70,7 +70,7 @@ jobs: # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token - name: Setup Terraform - uses: hashicorp/setup-terraform@v1 + uses: hashicorp/setup-terraform@v3 with: cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} @@ -89,5 +89,5 @@ jobs: # On push to "main", build or change infrastructure according to Terraform configuration files # Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks - name: Terraform Apply - if: github.ref == 'refs/heads/"main"' && github.event_name == 'push' + if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve -input=false diff --git a/bitcoin_trading_simulation.py b/bitcoin_trading_simulation.py index cb07d20..d61ddc9 100644 --- a/bitcoin_trading_simulation.py +++ b/bitcoin_trading_simulation.py @@ -82,9 +82,22 @@ def simulate_trading(signals, initial_cash=10000, quiet=False): portfolio['btc'] = 0.0 portfolio['total_value'] = float(initial_cash) + show_progress = quiet and sys.stdout.isatty() + total_days = len(signals) + if not quiet: print(f"\n{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}") - for i, row in signals.iterrows(): + elif show_progress: + print(f"\n{Colors.BLUE}{Colors.BOLD}Simulating trading...{Colors.ENDC}") + + for idx, (i, row) in enumerate(signals.iterrows()): + if show_progress: + progress = (idx + 1) / total_days + bar_length = 30 + filled = int(bar_length * progress) + bar = '█' * filled + '-' * (bar_length - filled) + print(f"\r{Colors.CYAN}[{bar}] {progress:.0%}{Colors.ENDC}", end="", flush=True) + if i > 0: portfolio.loc[i, 'cash'] = portfolio.loc[i-1, 'cash'] portfolio.loc[i, 'btc'] = portfolio.loc[i-1, 'btc'] @@ -94,14 +107,16 @@ def simulate_trading(signals, initial_cash=10000, quiet=False): btc_to_buy = portfolio.loc[i, 'cash'] / row['price'] portfolio.loc[i, 'btc'] += btc_to_buy portfolio.loc[i, 'cash'] -= btc_to_buy * row['price'] - print(f"{Colors.GREEN}🟢 Day {i}: Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") + if not quiet: + print(f"{Colors.GREEN}🟢 Day {i}: Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") # Sell signal elif row['positions'] == -2.0: if portfolio.loc[i, 'btc'] > 0: cash_received = portfolio.loc[i, 'btc'] * row['price'] portfolio.loc[i, 'cash'] += cash_received - print(f"{Colors.FAIL}🔴 Day {i}: Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") + if not quiet: + print(f"{Colors.FAIL}🔴 Day {i}: Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}") portfolio.loc[i, 'btc'] = 0 portfolio.loc[i, 'total_value'] = portfolio.loc[i, 'cash'] + portfolio.loc[i, 'btc'] * row['price'] @@ -110,6 +125,9 @@ def simulate_trading(signals, initial_cash=10000, quiet=False): print(f"Day {i}: Portfolio Value: ${portfolio.loc[i, 'total_value']:.2f}, " f"Cash: ${portfolio.loc[i, 'cash']:.2f}, BTC: {portfolio.loc[i, 'btc']:.4f}") + if show_progress: + print() + return portfolio diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..ca88e62 --- /dev/null +++ b/main.tf @@ -0,0 +1,2 @@ +terraform { +}