Esempio n. 1
0
def PullReddit():
    print("Pulling Reddit subscribers: ", end="", flush=True)

    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "select ss.uri, cc.name, cc.symbol, cc.id, ss.id  from crypto_currencies cc, social_sources ss where cc.id = ss.coin_fk and ss.name = 'reddit' order by cc.id asc"
    )

    rows = cursor.fetchall()

    if cursor.rowcount == 0:
        print("No Reddit sources found")

    redditApi = RedditClient()
    progress = pyprog.progress(len(rows))

    for x, row in enumerate(rows):
        progress.updatePercent(x)
        data_all = redditApi.get_subscriber_count(str(row[0]))

        params = (row[3], row[4], data_all)
        cursor.callproc('refreshpopulation', params)
    cursor.close()
    con.commit()
    con.close()
    progress.close()
Esempio n. 2
0
def main():
    #Gdax has a rate of 3 requests per second.  For safety, send only 2 a second or once ever 0.5 seconds
    gemeniRateSeconds = 1
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'gemeni'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No gemeni exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        time.sleep(gemeniRateSeconds)
        progress.updatePercent(x + 1)
        symbol = responseJson[x]

        #Replace placeholder with actual symbol
        tickerEndpoint = row[3].replace("<symbol>", symbol)

        responseAddl = requests.get(tickerEndpoint).content
        responseAddlJson = json.loads(responseAddl.decode('utf-8'))

        #baseCurrency, quoteCurrency = getAssetsFromSymbol(con, symbol)
        volumeJson = responseAddlJson["volume"]

        i = 0
        for key, value in volumeJson.items():
            i = i + 1
            if i == 1:
                baseCurrency = key
            if i == 2:
                volume = value
                quoteCurrency = key

        params = (row[0], symbol, responseAddlJson["last"], volume,
                  baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 3
0
def main():
    #Bitstamp has a rate of 1 requests per second.  For safety, send only 1 every 1.25 seconds
    bitstampRateSeconds = 1.25
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'bitstamp'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No bitstamp exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        time.sleep(bitstampRateSeconds)
        progress.updatePercent(x + 1)
        symbol = responseJson[x]["url_symbol"]
        name = responseJson[x]["name"].split("/")
        baseCurrency = name[0].strip()
        quoteCurrency = name[1].strip()

        #Replace placeholder with actual symbol
        tickerEndpoint = row[3].replace("<symbol>", symbol)

        responseAddl = requests.get(tickerEndpoint).content
        responseAddlJson = json.loads(responseAddl.decode('utf-8'))

        price = responseAddlJson["last"]
        volume = responseAddlJson["volume"]

        params = (row[0], symbol, price, volume, baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 4
0
def main():
    #okex has a rate of ~10 requests per second.
    okexSendRateSeconds = 0.1
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'okex'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No okex exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))["data"]

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        time.sleep(okexSendRateSeconds)
        progress.updatePercent(x + 1)
        symbol = responseJson[x]["symbol"]

        #No base and quote currency, need to parse from symbol by splitting on underscore _
        symbols = symbol.split('_')
        baseCurrency = symbols[0]
        quoteCurrency = symbols[1]

        #Replace placeholder with symbol
        tickerEndpoint = row[3].replace("<symbol>", symbol)

        responseAddl = requests.get(tickerEndpoint).content
        responseAddlJson = json.loads(responseAddl.decode('utf-8'))["ticker"]

        params = (row[0], symbol, responseAddlJson["last"],
                  responseAddlJson["vol"], baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 5
0
def main():
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'binance'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No binance exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ": ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))['symbols']
    responseAddl = requests.get(str(row[3])).content
    responseAddlJson = json.loads(responseAddl.decode('utf-8'))

    responseLen = len(responseJson)
    responseAddlLen = len(responseAddlJson)

    progress = pyprog.progress(responseAddlLen)

    for x in range(responseAddlLen):
        symbolAddl = responseAddlJson[x]['symbol']
        lastPrice = responseAddlJson[x]['lastPrice']
        volume = responseAddlJson[x]['volume']

        progress.updatePercent(x + 1)

        for y in range(responseLen):
            symbol = responseJson[y]['symbol']
            baseAsset = responseJson[y]['baseAsset']
            quoteAsset = responseJson[y]['quoteAsset']
            if symbol == symbolAddl:
                params = (row[0], symbol, lastPrice, volume, baseAsset,
                          quoteAsset)
                cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 6
0
def main():
    #bitfenix has a rate of 30 per minute so send 1 every 2 seconds to be safe.
    bitfenixRateSeconds = 3
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'bitfenix'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No bitfinex exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ": ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        time.sleep(bitfenixRateSeconds)
        progress.updatePercent(x + 1)
        symbol = responseJson[x]

        #No base and quote currency, need to parse from symbol by checking database for quote currency
        baseCurrency, quoteCurrency = getAssetsFromSymbol(con, symbol)

        #Replace placeholder with symbol
        tickerEndpoint = row[3].replace("<symbol>", symbol)

        responseAddl = requests.get(tickerEndpoint).content
        responseAddlJson = json.loads(responseAddl.decode('utf-8'))

        params = (row[0], symbol, responseAddlJson["last_price"],
                  responseAddlJson["volume"], baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 7
0
def main():
    #Gdax has a rate of 3 requests per second.  For safety, send only 2 a second or once ever 0.5 seconds
    gdaxSendRateSeconds = 0.5
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'gdax'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No gdax exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        time.sleep(gdaxSendRateSeconds)
        progress.updatePercent(x + 1)
        id = responseJson[x]["id"]
        baseCurrency = responseJson[x]["base_currency"]
        quoteCurrency = responseJson[x]["quote_currency"]

        #Replace placeholder with actual product id
        tickerEndpoint = row[3].replace("<product-id>", id)

        responseAddl = requests.get(tickerEndpoint).content
        responseAddlJson = json.loads(responseAddl.decode('utf-8'))

        params = (row[0], id, responseAddlJson["price"],
                  responseAddlJson["volume"], baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 8
0
def main():
	#Kraken has a rate of 1 requests per second.  For safety, send only 1 every 1.25 seconds
	bitstampRateSeconds = 1.25
	dbConfig = loadConfig(r'C:\AppCredentials\CoinTrackerPython\database.config')
	
	con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
	cursor = con.cursor()
	
	cursor.execute("SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'kraken'")
	row = cursor.fetchone()
	
	if cursor.rowcount == 0:
		print("No kraken exchange data found")
		return
		
	print("Refreshing market data for " + str(row[1]) + ":  ", end="", flush=True)
	response = requests.get(str(row[2])).content
	responseJson = json.loads(response.decode('utf-8'))["result"]

	responseLen = len(responseJson)
	progress = pyprog.progress(responseLen)
	x = 0

	for key, value in responseJson.items():
		x = x + 1
		time.sleep(bitstampRateSeconds)
		progress.updatePercent(x)
		symbol = key
		if '.' in symbol:
			continue

		baseCurrency = value["base"]
		quoteCurrency = value["quote"]

		tickerEndpoint = row[3].replace("<symbol>", symbol)
		responseAddl = requests.get(tickerEndpoint).content
		responseAddlJson = json.loads(responseAddl.decode('utf-8'))["result"][symbol]
		price = responseAddlJson["p"][0]
		volume = responseAddlJson["v"][1]

		params = (row[0], symbol, price, volume, baseCurrency, quoteCurrency)
		cursor.callproc('refreshMarketData', params)
		
	cursor.close()
	con.commit()
	con.close()
			
	progress.close()
Esempio n. 9
0
def main():
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'bitrex'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No bitrex exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))["result"]

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        progress.updatePercent(x + 1)

        symbol = responseJson[x]["MarketName"]
        #No base and quote currency, need to parse from symbol by splitting on hyphen -
        symbols = symbol.split('-')
        price = responseJson[x]["Last"]
        volume = responseJson[x]["Volume"]
        baseCurrency = symbols[1]
        quoteCurrency = symbols[0]
        #reverse symbol because bitrex is stupid
        symbol = baseCurrency + "-" + quoteCurrency

        params = (row[0], symbol, price, volume, baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 10
0
def main():
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'kucoin'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No kucoin exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))['data']

    responseLen = len(responseJson)

    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        progress.updatePercent(x + 1)
        coinType = responseJson[x]['coinType']
        lastDealPrice = responseJson[x]['lastDealPrice']
        vol = responseJson[x]['vol']
        coinTypePair = responseJson[x]['coinTypePair']
        symbol = coinType + coinTypePair

        params = (row[0], symbol, lastDealPrice, vol, coinType, coinTypePair)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 11
0
def AnalyzeTwitter():
    print("Analyzing Twitter Sentiment: ", end="", flush=True)

    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "select  cc.id, cc.name, cc.symbol, ss.id from crypto_currencies cc, social_sources ss where ss.name = 'twitter' and cc.id = ss.coin_fk order by cc.id asc limit 150"
    )
    rows = cursor.fetchall()

    if cursor.rowcount == 0:
        print("No records returned")
        return

    config = loadConfig(r'C:\AppCredentials\CoinTrackerPython\twitter.config')

    consumer_key = config[0]["consumer_key"]
    consumer_secret = config[0]["consumer_secret"]
    access_token = config[0]["access_token"]
    access_token_secret = config[0]["access_token_secret"]

    twitterApi = twitter.Client(consumer_key, consumer_secret, access_token,
                                access_token_secret)
    progress = pyprog.progress(len(rows))

    for x, row in enumerate(rows):
        progress.updatePercent(x)
        sentiment = twitterApi.analyzeSentiment(str(row[0]))

        params = (row[0], row[3], sentiment.volume, sentiment.sentiment,
                  sentiment.positive, sentiment.negative, sentiment.neutral)
        cursor.callproc('refreshSentiment', params)
    cursor.close()
    con.commit()
    con.close()
    progress.close()
Esempio n. 12
0
def main():
    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "SELECT id, name, endpoint, addl_endpoint FROM crypto_exchanges where name = 'hitbtc'"
    )
    row = cursor.fetchone()

    if cursor.rowcount == 0:
        print("No hitbtc exchange data found")
        return

    print("Refreshing market data for " + str(row[1]) + ":  ",
          end="",
          flush=True)
    response = requests.get(str(row[2])).content
    responseJson = json.loads(response.decode('utf-8'))

    responseLen = len(responseJson)
    progress = pyprog.progress(responseLen)

    for x in range(responseLen):
        progress.updatePercent(x + 1)
        symbol = responseJson[x]["symbol"]
        price = responseJson[x]["last"]
        volume = responseJson[x]["volume"]
        baseCurrency, quoteCurrency = getAssetsFromSymbol(con, symbol)

        params = (row[0], symbol, price, volume, baseCurrency, quoteCurrency)
        cursor.callproc('refreshMarketData', params)

    cursor.close()
    con.commit()
    con.close()

    progress.close()
Esempio n. 13
0
def AnalyzeReddit():
    print("Analyzing Reddit Sentiment: ", end="", flush=True)

    dbConfig = loadConfig(
        r'C:\AppCredentials\CoinTrackerPython\database.config')

    con = psycopg2.connect(dbConfig[0]["postgresql_conn"])
    cursor = con.cursor()

    cursor.execute(
        "select ss.uri, cc.name, cc.symbol, cc.id, ss.id  from crypto_currencies cc, social_sources ss where cc.id = ss.coin_fk and ss.name = 'reddit' order by cc.id asc"
    )

    rows = cursor.fetchall()

    if cursor.rowcount == 0:
        print("No Reddit sources found")
        return

    redditApi = reddit.Client('/u/mmiller3')

    progress = pyprog.progress(len(rows))

    for x, row in enumerate(rows):
        try:
            progress.updatePercent(x)
            sentiment = redditApi.analyzeSentiment(str(row[0]))

            params = (row[3], row[4], sentiment.volume, sentiment.sentiment,
                      sentiment.positive, sentiment.negative,
                      sentiment.neutral)
            cursor.callproc('refreshSentiment', params)
        except Exception:
            print("Error analyzing subreddit: " + str(row[0]))

    cursor.close()
    con.commit()
    con.close()
    progress.close()