Skip to content

Instantly share code, notes, and snippets.

@thecodingrobot
Created May 9, 2018 18:06
Show Gist options
  • Save thecodingrobot/1f8a7ac9e4c70be48d94772ba2b6e098 to your computer and use it in GitHub Desktop.
Save thecodingrobot/1f8a7ac9e4c70be48d94772ba2b6e098 to your computer and use it in GitHub Desktop.
shitcoin scanner
import asyncio
import ccxt.async as ccxt
import logging
import pandas as pd
from pyti.simple_moving_average import simple_moving_average as sma
logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger = logging.getLogger('scanner')
whitelist = ['poloniex', 'binance', 'bittrex']
# whitelist = ['poloniex', 'bittrex']
async def is_coin_any_good(exchange, ticker):
ohlcvs = await exchange.fetch_ohlcv(ticker, '1d')
df = pd.DataFrame(ohlcvs, columns=['time', 'o', 'h', 'l', 'c', 'price'])
df['sma20'] = sma(df['price'], 20)
df['sma40'] = sma(df['price'], 40)
df['sma60'] = sma(df['price'], 60)
# df['sma200'] = sma(df['price'], 200)
df['ok'] = df['price'] > df['sma60']
# first = ohlcvs[0]
# last = ohlcvs[-1]
# print('First candle epoch', first[0], exchange.iso8601(first[0]), first)
# print('Last candle epoch', last[0], exchange.iso8601(last[0]), last)
return df.iloc[-1]['ok'].tolist()
async def scan_markets(exchanges):
for id, exchange in exchanges.items():
markets = await exchange.load_markets()
markets = {k: v for k, v in markets.items() if 'btc' in k.lower()}
for m in markets.values():
ticker = m['symbol']
logger.info('{}: {}'.format(id, ticker))
yield id, ticker, await is_coin_any_good(exchange, ticker)
break
break
def load_exchanges():
for id in ccxt.exchanges:
if id not in whitelist:
continue
exchange = getattr(ccxt, id)()
exchange.timeout = 30000
if exchange.has['fetchOHLCV'] == True:
yield id, exchange
async def scan():
exchanges = dict(load_exchanges()) # a placeholder for your instances
try:
async for exchange, ticker, is_good in scan_markets(exchanges):
if is_good:
print(exchange, ticker)
finally:
for id, e in exchanges.items():
await e.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(scan())
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment