Update README.md
Browse filesHow It Works:
Data Fetching:
Historical data for ETH/USDT is fetched via Binance API.
Data Preparation:
Past price windows are converted into Llama documents for indexing.
LlamaIndex Integration:
Using the SimpleKeywordTableIndex from LlamaIndex, documents are indexed and a simple prompt is queried to simulate market prediction or pattern detection.
Response Interpretation:
The language model's response provides insights or possible trends based on indexed price data.
Prerequisites:
Install the required libraries:
bash
Kodu kopyala
pip install pandas numpy llama-index requests
Sample Prompt Result:
A sample response might look like:
vbnet
Kodu kopyala
Prediction response from LlamaIndex:
Based on the trend from 2023-10-01 12:00 to 2023-10-01 17:00, the next price is expected to be $12
123---license: llama3.3---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384---license: llama3.3datasets:- HuggingFaceTB/finemathbase_model:- Datou1111/shou_xin---from llama_index import SimpleKeywordTableIndex, Documentfrom datetime import datetime, timedeltaimport requestsimport numpy as npimport pandas as pd# Fetch historical price datadef fetch_price_data(symbol="ETHUSDT", interval="1h", limit=500):"""Fetch historical price data from Binance API."""url = f"https://api.binance.com/api/v3/klines?symbol={symbol}&interval={interval}&limit={limit}"response = requests.get(url)data = response.json()# Parse to DataFramedf = pd.DataFrame(data, columns=["timestamp", "open", "high", "low", "close", "volume", "close_time","quote_asset_volume", "number_of_trades", "taker_buy_base","taker_buy_quote", "ignore"])df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")df["close"] = df["close"].astype(float)return df[["timestamp", "close"]]# Prepare price history as documentsdef prepare_documents(df, window_size=5):"""Convert sliding price windows into Llama documents."""prices = df["close"].valuestimestamps = df["timestamp"].valuesdocuments = []for i in range(len(prices) - window_size):time_range = f"{timestamps[i]} to {timestamps[i + window_size]}"price_window = prices[i:i + window_size]content = f"Price trend from {time_range}: {price_window.tolist()}"documents.append(Document(content))return documents# LlamaIndex-based predictive taskdef train_with_llama_index(documents):"""Create a Simple Keyword Table Index to simulate trend prediction using LlamaIndex."""index = SimpleKeywordTableIndex.from_documents(documents)# Simulating a market predictionprompt = ("Based on historical trends, what might be the next ETH/USDT price, ""assuming consistent linear progression? Focus on patterns.")response = index.query(prompt)return response# Main pipelinedef main():# Step 1: Fetch historical datasymbol = "ETHUSDT"df = fetch_price_data(symbol)print("Fetched historical data:")print(df.head())# Step 2: Prepare documents for LlamaIndexwindow_size = 5documents = prepare_documents(df, window_size)# Step 3: Train a Simple Keyword Table Index and predict trendsprediction_response = train_with_llama_index(documents)# Step 4: Display responseprint(f"\nPrediction response from LlamaIndex:\n{prediction_response}")# Entry pointif __name__ == "__main__":main()