Hopper1394 commited on
Commit
0644d54
·
verified ·
1 Parent(s): 3927613

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +143 -0
Dockerfile CHANGED
@@ -1,2 +1,145 @@
1
  FROM huggingface/autotrain-advanced:latest
2
  CMD pip uninstall -y autotrain-advanced && pip install -U autotrain-advanced && autotrain app --host 0.0.0.0 --port 7860 --workers 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM huggingface/autotrain-advanced:latest
2
  CMD pip uninstall -y autotrain-advanced && pip install -U autotrain-advanced && autotrain app --host 0.0.0.0 --port 7860 --workers 1
3
+ # config.py
4
+ BINANCE_API_KEY = 'your_binance_api_key'
5
+ ALPHA_VANTAGE_API_KEY = 'your_alpha_vantage_api_key'
6
+ YAHOO_FINANCE_API_KEY = 'your_yahoo_finance_api_key'
7
+ TRADING_VIEW_API_KEY = 'your_trading_view_api_key'
8
+ BINOMO_API_KEY = 'your_binomo_api_key'
9
+ TELEGRAM_BOT_API_KEY = 'your_telegram_bot_api_key'
10
+
11
+ # data_acquisition.py
12
+ import requests
13
+ import pandas as pd
14
+ import numpy as np
15
+ from sklearn.preprocessing import StandardScaler
16
+ from tensorflow.keras.models import Sequential
17
+ from tensorflow.keras.layers import LSTM, Dense, Dropout
18
+ from telegram.ext import Updater, CommandHandler
19
+
20
+ def fetch_binance_data(pair):
21
+ url = f"https://api.binance.com/api/v3/klines?symbol={pair}&interval=1h"
22
+ response = requests.get(url)
23
+ data = response.json()
24
+ df = pd.DataFrame(data, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume', 'close_time', 'quote_asset_volume', 'number_of_trades', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume', 'ignore'])
25
+ df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
26
+ return df[['timestamp', 'open', 'high', 'low', 'close', 'volume']]
27
+
28
+ def fetch_alpha_vantage_data(pair):
29
+ symbol = pair.split("USDT")[0] # Assuming pair like BTCUSDT
30
+ url = f"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=60min&apikey={ALPHA_VANTAGE_API_KEY}"
31
+ response = requests.get(url)
32
+ data = response.json()
33
+ time_series_key = 'Time Series (60min)'
34
+ if time_series_key not in data:
35
+ raise ValueError(f"Error fetching data from Alpha Vantage: {data}")
36
+ df = pd.DataFrame(data[time_series_key]).T
37
+ df.columns = ['open', 'high', 'low', 'close', 'volume']
38
+ df.index = pd.to_datetime(df.index)
39
+ return df.reset_index().rename(columns={'index': 'timestamp'})
40
+
41
+ def fetch_yahoo_finance_data(pair):
42
+ url = f"https://yfapi.net/v8/finance/chart/{pair}?interval=60m"
43
+ headers = {'x-api-key': YAHOO_FINANCE_API_KEY}
44
+ response = requests.get(url, headers=headers)
45
+ data = response.json()
46
+ timestamps = data['chart']['result'][0]['timestamp']
47
+ ohlc = data['chart']['result'][0]['indicators']['quote'][0]
48
+ df = pd.DataFrame({
49
+ 'timestamp': pd.to_datetime(timestamps, unit='s'),
50
+ 'open': ohlc['open'],
51
+ 'high': ohlc['high'],
52
+ 'low': ohlc['low'],
53
+ 'close': ohlc['close'],
54
+ 'volume': ohlc['volume']
55
+ })
56
+ return df
57
+
58
+ def fetch_trading_view_data(pair):
59
+ # Placeholder for TradingView API data fetching
60
+ raise NotImplementedError("TradingView API integration not implemented.")
61
+
62
+ def fetch_binomo_data(pair):
63
+ # Placeholder for Binomo API data fetching
64
+ raise NotImplementedError("Binomo API integration not implemented.")
65
+
66
+ def get_combined_data(pair):
67
+ df_binance = fetch_binance_data(pair)
68
+ df_alpha = fetch_alpha_vantage_data(pair)
69
+ df_yahoo = fetch_yahoo_finance_data(pair)
70
+ # Merge dataframes on timestamp
71
+ df = pd.merge(df_binance, df_alpha, on='timestamp', suffixes=('_binance', '_alpha'))
72
+ df = pd.merge(df, df_yahoo, on='timestamp', suffixes=('', '_yahoo'))
73
+ # Drop any redundant columns or handle conflicts
74
+ return df
75
+
76
+ def preprocess_data(df):
77
+ df = df.dropna()
78
+ scaler = StandardScaler()
79
+ scaled_data = scaler.fit_transform(df[['open', 'high', 'low', 'close', 'volume']])
80
+ return scaled_data, scaler
81
+
82
+ def create_dataset(data, time_step=60):
83
+ X, Y = [], []
84
+ for i in range(len(data) - time_step - 1):
85
+ a = data[i:(i + time_step), :]
86
+ X.append(a)
87
+ Y.append(data[i + time_step, 3]) # Assuming 'close' price is the target
88
+ return np.array(X), np.array(Y)
89
+
90
+ def build_model(input_shape):
91
+ model = Sequential()
92
+ model.add(LSTM(50, return_sequences=True, input_shape=input_shape))
93
+ model.add(LSTM(50, return_sequences=False))
94
+ model.add(Dropout(0.2))
95
+ model.add(Dense(25))
96
+ model.add(Dense(1))
97
+ model.compile(optimizer='adam', loss='mean_squared_error')
98
+ return model
99
+
100
+ def train_model(df):
101
+ data, scaler = preprocess_data(df)
102
+ X, Y = create_dataset(data)
103
+ X_train, Y_train = X[:int(len(X) * 0.8)], Y[:int(len(Y) * 0.8)]
104
+ X_val, Y_val = X[int(len(X) * 0.8):], Y[int(len(Y) * 0.8):]
105
+ model = build_model((X_train.shape[1], X_train.shape[2]))
106
+ model.fit(X_train, Y_train, validation_data=(X_val, Y_val), epochs=20, batch_size=32)
107
+ return model, scaler
108
+
109
+ def generate_signal(pair):
110
+ df = get_combined_data(pair)
111
+ model, scaler = train_model(df)
112
+ recent_data = df.tail(60).drop(columns=['timestamp'])
113
+ scaled_recent_data = scaler.transform(recent_data)
114
+ prediction = model.predict(np.expand_dims(scaled_recent_data, axis=0))
115
+ last_close = df['close'].iloc[-1]
116
+ if prediction > last_close:
117
+ return "Buy"
118
+ else:
119
+ return "Sell"
120
+
121
+ def start(update, context):
122
+ context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a trading bot, how can I help you today?")
123
+
124
+ def signal(update, context):
125
+ pair = context.args[0] if context.args else 'BTCUSDT'
126
+ try:
127
+ trade_signal = generate_signal(pair)
128
+ context.bot.send_message(chat_id=update.effective_chat.id, text=f"Trade Signal for {pair}: {trade_signal}")
129
+ except Exception as e:
130
+ context.bot.send_message(chat_id=update.effective_chat.id, text=f"Error: {e}")
131
+
132
+ def main():
133
+ updater = Updater(token=TELEGRAM_BOT_API_KEY, use_context=True)
134
+ dispatcher = updater.dispatcher
135
+
136
+ start_handler = CommandHandler('start', start)
137
+ signal_handler = CommandHandler('signal', signal)
138
+
139
+ dispatcher.add_handler(start_handler)
140
+ dispatcher.add_handler(signal_handler)
141
+
142
+ updater.start_polling()
143
+
144
+ if __name__ == '__main__':
145
+ main()