├── requirements.txt ├── README.md ├── utils ├── config.py └── telegram_bot.py ├── get_news.py ├── bot.py ├── .gitignore └── gateio.py /requirements.txt: -------------------------------------------------------------------------------- 1 | ccxt 2 | pandas 3 | lxml 4 | python-telegram-bot -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Listing Trading Bot 2 | Gets the coin listing news from Binance and buys the coin on Gate.io before the pump. -------------------------------------------------------------------------------- /utils/config.py: -------------------------------------------------------------------------------- 1 | GATEIO_API_KEY = 'Your GateIO API key here' 2 | GATEIO_SECRET_KEY = 'Your GateIO Secret API key here' 3 | TOKEN = 'Your Telegram Token here' 4 | CHAT_IDS = ['Your Telegram Chat ID here',] -------------------------------------------------------------------------------- /utils/telegram_bot.py: -------------------------------------------------------------------------------- 1 | """ 2 | * ------------------------------------------------------------ 3 | * "THE BEERWARE LICENSE" (Revision 42): 4 | * Onat Deniz Dogan wrote this code. As long as you retain this 5 | * notice, you can do whatever you want with this stuff. If we 6 | * meet someday, and you think this stuff is worth it, you can 7 | * buy me a beer in return. 8 | * ------------------------------------------------------------ 9 | """ 10 | 11 | import telegram 12 | from . import config 13 | 14 | def post_message(message): 15 | """ 16 | post_message posts the given message on Telegram Bot. 17 | 18 | Args: 19 | message (string): The message to be sent on Telegram 20 | """ 21 | 22 | try: 23 | bot = telegram.Bot(token=config.TOKEN) 24 | for id in config.CHAT_IDS: 25 | bot.send_message(id,message) 26 | except Exception as e: 27 | print(e) 28 | return -------------------------------------------------------------------------------- /get_news.py: -------------------------------------------------------------------------------- 1 | """ 2 | * ------------------------------------------------------------ 3 | * "THE BEERWARE LICENSE" (Revision 42): 4 | * Onat Deniz Dogan wrote this code. As long as you retain this 5 | * notice, you can do whatever you want with this stuff. If we 6 | * meet someday, and you think this stuff is worth it, you can 7 | * buy me a beer in return. 8 | * ------------------------------------------------------------ 9 | """ 10 | 11 | import requests, sys 12 | from lxml import html 13 | 14 | def get_news(url): 15 | try: 16 | response = requests.get(url) 17 | except Exception as e: 18 | print(str(e)) 19 | sys.exit(2) 20 | 21 | if response.status_code != 200: 22 | print('Sorry, invalid response ' + str(response.status_code)) 23 | sys.exit(2) 24 | 25 | tree = html.fromstring(response.text) 26 | 27 | extracteditems = tree.xpath('//a[@class="css-1ej4hfo"]/text()') 28 | 29 | listing_news = [] 30 | 31 | for index, news in enumerate(extracteditems): 32 | if "WILL LIST" in news.upper(): 33 | news = news.upper().split("WILL LIST ", 1)[1] 34 | news = news[news.find('(')+1:news.find(')')] 35 | listing_news.append(news) 36 | 37 | return(listing_news) -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | """ 2 | * ------------------------------------------------------------ 3 | * "THE BEERWARE LICENSE" (Revision 42): 4 | * Onat Deniz Dogan wrote this code. As long as you retain this 5 | * notice, you can do whatever you want with this stuff. If we 6 | * meet someday, and you think this stuff is worth it, you can 7 | * buy me a beer in return. 8 | * ------------------------------------------------------------ 9 | """ 10 | 11 | import gateio, time 12 | from get_news import get_news 13 | from utils.telegram_bot import post_message 14 | 15 | url = "https://www.binance.com/en/support/announcement/c-48?navId=48" 16 | sleep_time = 10 17 | latest_news = 'POLS' 18 | 19 | post_message('Bot started!') 20 | news = get_news(url) 21 | latest_news = news[0] 22 | 23 | while True: 24 | """ 25 | Get the new announcements from Binance all the time. 26 | If a new coin listing is announced, immediately buy the coin on GateIO during pumping. 27 | When the pumping ends, sell the coin and take the profit. 28 | """ 29 | news = get_news(url) 30 | 31 | # If there is no announcements 32 | if len(news) == 0: 33 | time.sleep(sleep_time) 34 | continue 35 | 36 | # If there is a new coin listing! 37 | if news[0] != latest_news: 38 | try: 39 | latest_news = news[0] 40 | message = "News! " + latest_news + " will be listed!" 41 | print(message) 42 | post_message(message) 43 | 44 | symbol = latest_news+'/USDT' 45 | if gateio.symbol_check(symbol): 46 | gateio.buy(symbol) 47 | gateio.sellBearish(symbol) 48 | 49 | except Exception as e: 50 | message = f'Error: {str(e)}' 51 | print(message) 52 | post_message(message) 53 | 54 | time.sleep(sleep_time) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /gateio.py: -------------------------------------------------------------------------------- 1 | """ 2 | * ------------------------------------------------------------ 3 | * "THE BEERWARE LICENSE" (Revision 42): 4 | * Onat Deniz Dogan wrote this code. As long as you retain this 5 | * notice, you can do whatever you want with this stuff. If we 6 | * meet someday, and you think this stuff is worth it, you can 7 | * buy me a beer in return. 8 | * ------------------------------------------------------------ 9 | """ 10 | 11 | import ccxt, time 12 | import utils.config 13 | from utils.telegram_bot import post_message 14 | 15 | # Create the GateIO exchange object using CCXT 16 | exchange = ccxt.gateio({ 17 | 'apiKey': utils.config.GATEIO_API_KEY, 18 | 'secret': utils.config.GATEIO_SECRET_KEY, 19 | }) 20 | 21 | # Get the market and balance data from GateIO 22 | markets = exchange.fetch_markets() 23 | balance = exchange.fetch_total_balance() 24 | 25 | # Get all the available symbols from GateIO 26 | symbols = [symbol for symbol in [market['symbol'] for market in markets]] 27 | 28 | # Placeholder for keeping the price at the time of buying 29 | entryPrice = 0 30 | 31 | def symbol_check(symbol): 32 | if symbol in symbols: 33 | print(f"Good news!, {symbol} exists in Gate.io") 34 | return True 35 | else: 36 | print(f"Sorry, {symbol} does not exist in Gate.io") 37 | return False 38 | 39 | def buy(symbol): 40 | global entryPrice 41 | 42 | # Pick a price more than the last ticker data, to make sure that we can fulfill order 43 | price = exchange.fetch_ticker(symbol)['last'] * 1.01 44 | entryPrice = price 45 | 46 | # Get the current USDT balance in GateIO 47 | balance = exchange.fetch_total_balance() 48 | coin = symbol.split('/')[0] 49 | usdt_balance = balance['USDT'] 50 | 51 | # Calculate the amount of coin that we can buy, apply a small margin for rounding errors in balance 52 | amount = (usdt_balance * 0.999) / (price) 53 | 54 | # Create the limit buy order 55 | exchange.create_limit_buy_order(symbol, amount=amount, price=price) 56 | 57 | # Notify the user both on Telegram and CLI 58 | message = f"You have {usdt_balance} USDT in your account. Buying {amount} {coin} for {price}" 59 | print(message) 60 | post_message(message) 61 | 62 | def sell(symbol): 63 | 64 | # Pick a price less than the last ticker data, to make sure that we can fulfill order 65 | price = exchange.fetch_ticker(symbol)['last'] * 0.99 66 | 67 | # Get the current coin balance in GateIO 68 | balance = exchange.fetch_total_balance() 69 | coin = symbol.split('/')[0] 70 | coin_balance = balance[coin] 71 | 72 | # Create the limit sell order 73 | exchange.create_limit_sell_order(symbol, amount=coin_balance, price=price) 74 | 75 | # Notify the user both on Telegram and CLI 76 | message = f"You have {coin_balance} {coin} in your account. Selling them for {price}" 77 | print(message) 78 | post_message(message) 79 | 80 | 81 | def sellBearish(symbol): 82 | global entryPrice 83 | bestPrice = exchange.fetch_ticker(symbol)['last'] 84 | balance = exchange.fetch_total_balance() 85 | 86 | while True: 87 | price = exchange.fetch_ticker(symbol)['last'] 88 | 89 | # Update the best price if we have a new best price 90 | if price > bestPrice: 91 | bestPrice = price 92 | 93 | # If the price has dropped 3% percent w.r.t. the best price, sell the coins and get the profit 94 | elif price < (0.97 * bestPrice): 95 | coin = symbol.split('/')[0] 96 | coin_balance = balance[coin] 97 | 98 | exchange.create_limit_sell_order(symbol, amount=coin_balance, price=price*0.99) 99 | 100 | # Notify the user both on Telegram and CLI 101 | message = f"You have {coin_balance} {coin} in your account.\nSelling them for {price*0.99}\nYour profit is{price/entryPrice*100}" 102 | print(message) 103 | post_message(message) --------------------------------------------------------------------------------