Skip to content

Trading Bots

FinanceLib includes two trading bots: a cryptocurrency bot and a BIST stock bot.

BIST Trading Bot

from financelib.trading import _get_bist_bot
BISTTradeBotv1 = _get_bist_bot()

bot = BISTTradeBotv1(paper_trading=True, initial_balance=100000)

# Analyze a single stock
signal = bot.analyze("THYAO.IS")
print(signal)

# Execute paper trades based on signals
if signal and signal["signal"] == "BUY":
    bot.execute_paper_trade("THYAO.IS", "BUY", signal["current_price"])

# Scan all common BIST stocks
signals = bot.scan_common_stocks()

# Get portfolio summary
summary = bot.get_portfolio_summary()
print(summary)

Crypto Trading Bot

Warning

The crypto bot requires the bot extra: pip install financelib[bot]

from financelib.trading import _get_cryptor_bot
CryptorTradeBot = _get_cryptor_bot()

# Paper trading mode (no real orders)
bot = CryptorTradeBot(paper_trading=True)

# Run strategy once
result = bot.trading_strategy("BTC/USDT", "bitcoin", market="spot")
print(result)

# Backtest
bt = bot.backtest("BTC/USDT", "bitcoin", initial_balance=10000)
print(f"Profit: {bt['profit']:.2f} ({bt['profit_pct']:+.2f}%)")

Features

  • Technical Indicators: SMA crossover, RSI, MACD, Bollinger Bands
  • Sentiment Analysis: FinBERT model analyzes tweets and news
  • Price Prediction: Transformer neural network forecasts
  • Risk Management: Stop-loss, take-profit, dynamic leverage
  • Multi-Market: Spot, futures (with leverage), and options
  • Backtesting: Test strategies on historical data
  • Paper Trading: Simulate without real money