Esempio n. 1
0
def get_trades(asset_symbol, timedelta=datetime.timedelta(minutes=10), start=False, end=False, time_offset=datetime.timedelta(hours=5)):
    
    if not start or not end: # create default start and end times if not given
        end = datetime.datetime.now() + time_offset
        start = end - timedelta
    else:
        start += time_offset
        end += time_offset
    
    # create unix versions of the start and end times
    end_unix = int(time.mktime(end.timetuple()))
    start_unix = int(time.mktime(start.timetuple()))
    
    # get raw trade data from poloniex
    trades_data = p.returnMarketTradeHistory('BTC_'+asset_symbol,start=start_unix,end=end_unix)
    
    if len(trades_data) > 0: # create a data frame with all the trades
        trades_df = pd.DataFrame(trades_data)
        trades_df[['amount','rate','total']] = trades_df[['amount','rate','total']].astype(float)
        trades_df['date'] = pd.to_datetime(trades_df.date)
        trades_df['symbol'] = asset_symbol

        return trades_df
    else:
        return false
Esempio n. 2
0
def get_cmc_markets(asset_name):
    
    # get the markets data from coinmarketcap
    base_url = 'http://coinmarketcap.com/currencies/'
    web_page = BeautifulSoup(requests.get(base_url+asset_name).text)
    markets_section = web_page.select('div#markets')[0]
    market_table_rows = markets_section.find('table').find_all('tr')[1:]

    markets = [] # store each market instance in an array
    for market in market_table_rows:
        markets.append([td.text for td in market.find_all('td')])
    
    # create data frame with each markets data
    columns = ['ranking','exchange','currency_pair','volume', 'price', 'market_share','update_time']
    markets_df = pd.DataFrame(markets, columns=columns)
    markets_df.index = markets_df.ranking.values
    markets_df['volume'] = markets_df.volume.apply(lambda v: int(''.join([c for c in v if c.isdigit()])))
    markets_df['price'] = markets_df.price.apply(lambda p: float(p.split(' ')[1]))
    markets_df['market_share'] = markets_df.market_share.apply(lambda s: float(s.split(' ')[0]) / 100.)
    markets_df['recently_updated'] = markets_df.update_time.apply(lambda u: 1 if u == 'Recently' else 0)
    markets_df = markets_df.drop(['ranking', 'update_time'],1)
    
    return markets_df