TradingAgents/playground.ipynb

408 lines
12 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ab4c0304",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Crypto data for BTC/USDT from 2025-12-20 to 2025-12-25\n",
"# Total records: 7\n",
"# Data retrieved on: 2025-12-30 23:12:08 UTC\n",
"\n",
"Date,Open,High,Low,Close,Volume\n",
"2025-12-19,85506.9,89404.6,85104.9,88141.3,9324\n",
"2025-12-20,88141.3,88570.1,87797.9,88356,2252\n",
"2025-12-21,88356,89085.4,87587.8,88660.8,3438\n",
"2025-12-22,88660.8,90599.9,87888.9,88623.8,9026\n",
"2025-12-23,88623.8,88949.6,86595,87486.5,7168\n",
"2025-12-24,87486.5,88051.1,86412.6,87675,6033\n",
"2025-12-25,87675,88598.6,86953.4,87216.7,3872\n"
]
}
],
"source": [
"from tradingagents.dataflows.bybit import *\n",
"\n",
"print(get_market_data('BTC/USDT', '2025-12-20', '2025-12-25'))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c4d08861",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from dotenv import load_dotenv\n",
"load_dotenv()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3744edd7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Account Balance Report for BTC/USDT\n",
"** Total Equity: $7965.89736959 **\n",
"## USDT (Quote) Details:\n",
"{\n",
" \"spotBorrow\": 0.0,\n",
" \"availableToBorrow\": 0.0,\n",
" \"bonus\": 0.0,\n",
" \"accruedInterest\": 0.0,\n",
" \"availableToWithdraw\": 0.0,\n",
" \"totalOrderIM\": 0.0,\n",
" \"equity\": 5002.44462368,\n",
" \"totalPositionMM\": 0.0,\n",
" \"usdValue\": 4997.1670446,\n",
" \"unrealisedPnl\": 0.0,\n",
" \"collateralSwitch\": 1.0,\n",
" \"spotHedgingQty\": 0.0,\n",
" \"borrowAmount\": 0.0,\n",
" \"totalPositionIM\": 0.0,\n",
" \"walletBalance\": 5002.44462368,\n",
" \"cumRealisedPnl\": -138.82418652,\n",
" \"locked\": 280.0,\n",
" \"marginCollateral\": 1.0\n",
"}\n",
"## BTC (Base) Details:\n",
"{\n",
" \"spotBorrow\": 0.0,\n",
" \"availableToBorrow\": 0.0,\n",
" \"bonus\": 0.0,\n",
" \"accruedInterest\": 0.0,\n",
" \"availableToWithdraw\": 0.0,\n",
" \"totalOrderIM\": 0.0,\n",
" \"equity\": 4e-07,\n",
" \"totalPositionMM\": 0.0,\n",
" \"usdValue\": 0.03615499,\n",
" \"unrealisedPnl\": 0.0,\n",
" \"collateralSwitch\": 0.0,\n",
" \"spotHedgingQty\": 0.0,\n",
" \"borrowAmount\": 0.0,\n",
" \"totalPositionIM\": 0.0,\n",
" \"walletBalance\": 4e-07,\n",
" \"cumRealisedPnl\": -0.00056459,\n",
" \"locked\": 0.0,\n",
" \"marginCollateral\": 1.0\n",
"}\n",
"\n"
]
}
],
"source": [
"print(get_account_balance('BTC/USDT'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4d338e6c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Open Orders for BTCUSDT\n",
"[\n",
" {\n",
" \"symbol\": \"BTCUSDT\",\n",
" \"orderType\": \"Limit\",\n",
" \"orderLinkId\": \"2113891849709292801\",\n",
" \"slLimitPrice\": 27500.0,\n",
" \"orderId\": \"2113891849709292800\",\n",
" \"cancelType\": \"UNKNOWN\",\n",
" \"avgPrice\": 0.0,\n",
" \"stopOrderType\": \"\",\n",
" \"lastPriceOnCreated\": \"\",\n",
" \"orderStatus\": \"New\",\n",
" \"takeProfit\": 35000.0,\n",
" \"cumExecValue\": 0.0,\n",
" \"smpType\": \"None\",\n",
" \"triggerDirection\": 0.0,\n",
" \"blockTradeId\": \"\",\n",
" \"cumFeeDetail\": {},\n",
" \"isLeverage\": 0.0,\n",
" \"rejectReason\": \"EC_NoError\",\n",
" \"price\": 28000.0,\n",
" \"orderIv\": \"\",\n",
" \"createdTime\": \"2025-12-26 06:45:45\",\n",
" \"tpTriggerBy\": \"\",\n",
" \"positionIdx\": 0.0,\n",
" \"trailingPercentage\": 0.0,\n",
" \"timeInForce\": \"PostOnly\",\n",
" \"leavesValue\": 280.0,\n",
" \"basePrice\": 89223.5,\n",
" \"updatedTime\": \"2025-12-26 06:45:45\",\n",
" \"side\": \"Buy\",\n",
" \"smpGroup\": 0.0,\n",
" \"triggerPrice\": 0.0,\n",
" \"tpLimitPrice\": 36000.0,\n",
" \"trailingValue\": 0.0,\n",
" \"cumExecFee\": 0.0,\n",
" \"leavesQty\": 0.01,\n",
" \"slTriggerBy\": \"\",\n",
" \"closeOnTrigger\": 0.0,\n",
" \"placeType\": \"\",\n",
" \"cumExecQty\": 0.0,\n",
" \"reduceOnly\": 0.0,\n",
" \"activationPrice\": 0.0,\n",
" \"qty\": 0.01,\n",
" \"stopLoss\": 27000.0,\n",
" \"marketUnit\": \"\",\n",
" \"smpOrderId\": \"\",\n",
" \"triggerBy\": \"\"\n",
" }\n",
"]\n"
]
}
],
"source": [
"print(get_open_orders('BTC/USDT'))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f2782eb4",
"metadata": {},
"outputs": [],
"source": [
"from tradingagents.dataflows.y_finance import *"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fdd7515f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"## close_10_ema values from 2025-12-15 to 2025-12-25:\n",
"\n",
"2025-12-25: N/A: Not a trading day (weekend or holiday)\n",
"2025-12-24: 273.957107566544\n",
"2025-12-23: 273.9897986794218\n",
"2025-12-22: 274.35197941894614\n",
"2025-12-21: N/A: Not a trading day (weekend or holiday)\n",
"2025-12-20: N/A: Not a trading day (weekend or holiday)\n",
"2025-12-19: 275.1035301296668\n",
"2025-12-18: 275.42208939676294\n",
"2025-12-17: 276.1403309423977\n",
"2025-12-16: 277.0959608545104\n",
"2025-12-15: 277.64839985516545\n",
"\n",
"\n",
"10 EMA: A responsive short-term average. Usage: Capture quick shifts in momentum and potential entry points. Tips: Prone to noise in choppy markets; use alongside longer averages for filtering false signals.\n"
]
}
],
"source": [
"print(get_stock_stats_indicators_window(symbol='AAPL', indicator='close_10_ema', curr_date='2025-12-25', look_back_days=10))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e469bf97",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"## close_200_sma values for BTCUSDT from 2025-12-15 to 2025-12-25:\n",
"\n",
"2025-12-25: 107547.3955\n",
"2025-12-24: 107639.8590\n",
"2025-12-23: 107729.1770\n",
"2025-12-22: 107813.0945\n",
"2025-12-21: 107877.4790\n",
"2025-12-20: 107957.4840\n",
"2025-12-19: 108042.5335\n",
"2025-12-18: 108131.1640\n",
"2025-12-17: 108231.8855\n",
"2025-12-16: 108323.7295\n",
"2025-12-15: 108404.5060\n",
"\n",
"200 SMA: A long-term trend benchmark. Usage: Confirm overall market trend and identify golden/death cross setups. Tips: It reacts slowly; best for strategic trend confirmation rather than frequent trading entries.\n"
]
}
],
"source": [
"print(get_crypto_indicator_window('BTC/USDT', indicator='close_200_sma', curr_date='2025-12-25', look_back_days=10))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "2ec4396d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Technical Indicators Report for BTC/USDT\n",
"\n",
"**Current Date:** 2025-12-25\n",
"**Lookback Days:** 10\n",
"\n",
"## Simple Moving Average (SMA)\n",
"\n",
"**Value:** 89244.9917\n",
"\n",
"*SMA (Simple Moving Average): A basic trend-following indicator that smooths out price data. Usage: Identify trend direction and serve as dynamic support/resistance levels. Tips: Use multiple SMAs for crossover signals; combines well with volume analysis for confirmation.*\n",
"\n",
"---\n",
"\n",
"## Exponential Moving Average (EMA)\n",
"\n",
"**Value:** 90757.8592\n",
"\n",
"*EMA (Exponential Moving Average): A trend-following indicator that gives more weight to recent prices. Usage: More responsive than SMA for trend changes and crossover signals. Tips: Better for short-term trading; reacts faster to price changes than SMA.*\n",
"\n",
"---\n",
"\n",
"\n"
]
}
],
"source": [
"from tradingagents.dataflows.taapi import *\n",
"\n",
"print(get_crypto_stats_indicators(symbol='BTC/USDT', indicators=['sma', 'ema'], curr_date='2025-12-25', look_back_days=10))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "71414822",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'BTCUSDT'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_symbol(\"BTC\", \"USDT\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "3b52bac5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Technical Indicators Report for BTCUSDT\n",
"\n",
"----------------------------------------\n",
"\n",
"## close_50_sma values for BTCUSDT from 2025-12-15 to 2025-12-25:\n",
"\n",
"2025-12-25: 91694.1440\n",
"2025-12-24: 92027.2860\n",
"2025-12-23: 92303.3980\n",
"2025-12-22: 92685.2460\n",
"2025-12-21: 93123.5500\n",
"2025-12-20: 93551.8900\n",
"2025-12-19: 93976.5280\n",
"2025-12-18: 94379.7400\n",
"2025-12-17: 94869.3140\n",
"2025-12-16: 95402.0880\n",
"2025-12-15: 95926.8880\n",
"\n",
"Description: 50 SMA: A medium-term trend indicator. Usage: Identify trend direction and serve as dynamic support/resistance. Tips: It lags price; combine with faster indicators for timely signals.\n",
"----------------------------------------\n",
"\n",
"## close_200_sma values for BTCUSDT from 2025-12-15 to 2025-12-25:\n",
"\n",
"2025-12-25: 107547.3955\n",
"2025-12-24: 107639.8590\n",
"2025-12-23: 107729.1770\n",
"2025-12-22: 107813.0945\n",
"2025-12-21: 107877.4790\n",
"2025-12-20: 107957.4840\n",
"2025-12-19: 108042.5335\n",
"2025-12-18: 108131.1640\n",
"2025-12-17: 108231.8855\n",
"2025-12-16: 108323.7295\n",
"2025-12-15: 108404.5060\n",
"\n",
"Description: 200 SMA: A long-term trend benchmark. Usage: Confirm overall market trend and identify golden/death cross setups. Tips: It reacts slowly; best for strategic trend confirmation rather than frequent trading entries.\n",
"----------------------------------------\n"
]
}
],
"source": [
"print(get_crypto_indicators_bulk(symbol='BTC/USDT', indicators=['close_50_sma', 'close_200_sma'], curr_date='2025-12-25', look_back_days=10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e9206ba",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "tradingagents",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}