vericek
binance bnb verisi cekmeneron
plain_text
a year ago
3.5 kB
14
Indexable
import ccxt
import numpy as np
import pandas as pd
import pandas_ta as ta
# Binance borsasına bağlanın
exchange = ccxt.binanceusdm()
# İşlem yapacağınız sembolleri liste olarak tanımlayın
symbols = ['BNB/USDT']
timeframe = '3m' # Zaman dilimi
limit = 100 # Kaç veri noktası almak istediğinizi belirleyin
ma_period = 10 # Hareketli ortalama süresi
for symbol in symbols:
# Veri alın
ohlcv = exchange.fetch_ohlcv(symbol, timeframe, limit=limit)
# Veriyi DataFrame'e dönüştürün
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
# Sembol bilgisi ekleyin
df['symbol'] = symbol
# Timestamp'i okunabilir bir formata dönüştürün
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
# RSI hesaplaması
df['rsi'] = ta.rsi(df['close'], length=14)
# Bollinger Band hesaplamaları
bbands = ta.bbands(df['close'], length=20, std=2)
df['bb_upper'] = bbands['BBU_20_2.0']
df['bb_middle'] = bbands['BBM_20_2.0']
df['bb_lower'] = bbands['BBL_20_2.0']
# Bollinger Band sinyali
df['bollinger_flag'] = np.where(df['close'] > df['bb_upper'], 1,
np.where(df['close'] < df['bb_lower'], -1, 0))
# Stochastic Oscillator hesaplamaları
stoch = ta.stoch(df['high'], df['low'], df['close'], k=14, d=3)
df['stoch_k'] = stoch['STOCHk_14_3_3']
df['stochastic_flag'] = np.where(df['stoch_k'] < 20, -1,
np.where(df['stoch_k'] > 80, 1, 0))
# MACD hesaplamaları
macd = ta.macd(df['close'], fast=12, slow=26, signal=9)
df['macd_line'] = macd['MACD_12_26_9']
df['macd_signal_line'] = macd['MACDs_12_26_9']
df['macd_hist'] = macd['MACDh_12_26_9']
# MACD sinyali
df['macd_signal'] = np.where((df['macd_line'].shift(1) < df['macd_signal_line'].shift(1)) &
(df['macd_line'] > df['macd_signal_line']), 1,
np.where((df['macd_line'].shift(1) > df['macd_signal_line'].shift(1)) &
(df['macd_line'] < df['macd_signal_line']), -1, 0))
# Hareketli Ortalama (MA) hesaplaması
df['ma'] = ta.sma(df['close'], length=ma_period)
df['ma_flag'] = np.where(df['close'] > df['ma'], 1, 0)
# Mumun büyüklüğü (body size) hesaplaması
df['body_size'] = np.abs(df['close'] - df['open']).round(2)
# Kapanış fiyatı farkı (unit difference) ve yüzdesel fark (percentage difference) hesaplaması
df['unit_diff'] = df['close'].diff().round(2)
df['percent_diff'] = (df['unit_diff'] / df['close'].shift(1) * 100).round(2)
# Yüksek ve düşük fiyat farklarını hesaplama (açılış fiyatına göre yüzdelik fark)
df['percent_high_diff'] = ((df['high'] - df['open']) / df['open'] * 100).round(2)
df['percent_low_diff'] = ((df['low'] - df['open']) / df['open'] * 100).round(2)
# CSV dosyasına kaydedin, sembol adına göre dosya adını belirleyin
filename = f'{symbol.replace("/", "_")}_veri.csv'
df.to_csv(filename, index=False)
print(f'{symbol} için veri başarıyla kaydedildi.')
print(df[['timestamp', 'symbol', 'close', 'rsi', 'bollinger_flag', 'stochastic_flag',
'macd_signal', 'ma_flag', 'body_size', 'volume', 'unit_diff',
'percent_diff', 'percent_high_diff', 'percent_low_diff']].head(25))
Editor is loading...
Leave a Comment