Created
December 9, 2020 12:32
-
-
Save avances123/294d14d495e7d5cdb3125a6c1178a1d4 to your computer and use it in GitHub Desktop.
bot para eth/btc cruce de smas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import ccxt | |
from datetime import datetime | |
from telegram import Update | |
from telegram.ext import Updater, CommandHandler, CallbackContext | |
def strategy(context): | |
job = context.job | |
b = ccxt.binance() | |
ohlcv = b.fetch_ohlcv('ETH/BTC', '1d') | |
#ohlcv = b.fetch_ohlcv('BTC/USDT', '1d') | |
df = pd.DataFrame(ohlcv, columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']) | |
df['Time'] = [datetime.fromtimestamp(float(time)/1000) for time in df['Time']] | |
df.set_index('Time', inplace=True) | |
# medias | |
df['10sma'] = df.Close.rolling(10).mean() | |
df['20sma'] = df.Close.rolling(20).mean() | |
if (df['10sma'][-1] > df['20sma'][-1]) and (df['10sma'][-2] < df['20sma'][-2]): | |
print ("COMPRAR") | |
context.bot.send_message(job.context, text='COMPRAR') | |
elif (df['10sma'][-1] < df['20sma'][-1]) and (df['10sma'][-2] > df['20sma'][-2]): | |
print ("VENDER") | |
context.bot.send_message(job.context, text='VENDER') | |
else: | |
print ("NO CAMBIA") | |
#context.bot.send_message(job.context, text='NO CAMBIA') | |
def start(update, context) -> None: | |
chat_id = update.message.chat_id | |
context.job_queue.run_repeating(strategy,interval=60*60*24, first=0, context=chat_id, name=str(chat_id)) | |
updater = Updater('1478654904:AAGV_Z1JHnkW0b6__2d6oWdtfc7p8YWZ7gU', use_context=True) | |
dispatcher = updater.dispatcher | |
dispatcher.add_handler(CommandHandler("start", start)) | |
updater.start_polling() | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment