Skip to content

Commit

Permalink
removing check_coins from connections
Browse files Browse the repository at this point in the history
  • Loading branch information
lockefox committed Nov 2, 2017
1 parent 0b76268 commit e0018df
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions prosper_bots/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,53 +176,3 @@ def cooldown(
})

return False

COINS_COLLECTION = 'coins'
def check_coins(
ticker,
db_conn,
cache_buster=False,
cache_age=86400,
coins_collection=COINS_COLLECTION,
logger=api_config.LOGGER
):
"""checks if ticker is a crypto-coin
Args:
ticker (str): name of product to check
db_conn (:obj:`tinymongo.TinyMongoDatabase`): database to use
cache_buster (bool, optional): skip cache
logger (:obj:`logging.logger`, optional): logging handle
Returns:
(bool): coin or not
"""
cache_time = time.time()

logger.info('--checking cache for %s', ticker)
cached_data = list(db_conn[coins_collection].find(
{'cache_time': {'$gt': cache_time - cache_age}}
))

coins_list = []
if not cached_data or cache_buster:
## Refresh cache ##
logger.info('--fetching coin info')
coins_list = info.supported_symbol_info('commodity')
coins_df = pd.DataFrame(coins_list, columns=['coin_ticker'])
coins_df['cache_time'] = cache_time
coin_cache = list(coins_df.to_dict(orient='records'))

logger.info('--clearing cache')
db_conn[coins_collection].delete_many({})

logger.info('--rebuilding cache')
db_conn[coins_collection].insert_many(coin_cache)

else:
logger.info('--reading cached values')
coins_df = pd.DataFrame(cached_data)
coins_list = list(coins_df['coin_ticker'])

return ticker in coins_list

0 comments on commit e0018df

Please sign in to comment.