def get_historical_price(self, crypto, fiat, at_time):
<EOL>interval = datetime.timedelta(hours=<NUM_LIT>)<EOL>crypto = crypto.lower()<EOL>fiat = fiat.lower()<EOL>at_time = arrow.get(at_time).datetime<EOL>data = crypto_data[crypto]<EOL>name, date_created = data['<STR_LIT:name>'], data['<STR_LIT>']<EOL>if date_created.replace(tzinfo=pytz.utc) > at_time:<EOL><INDENT>raise Exception("<STR_LIT>" % (name, crypto, at_time))<EOL><DEDENT>if crypto == '<STR_LIT>':<EOL><INDENT>if fiat == '<STR_LIT>':<EOL><INDENT>if at_time < datetime.datetime(<NUM_LIT>, <NUM_LIT:2>, <NUM_LIT:1>, tzinfo=pytz.utc):<EOL><INDENT>exchange = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>exchange = "<STR_LIT>"<EOL><DEDENT><DEDENT>else:<EOL><INDENT>exchange = quandl_exchange_btc_to_fiat[fiat.upper()]<EOL><DEDENT>source = "<STR_LIT>" % (exchange.upper(), fiat.upper())<EOL>price_index = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>if fiat != '<STR_LIT>':<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>if crypto == '<STR_LIT>':<EOL><INDENT>source, price_index = ['<STR_LIT>', <NUM_LIT:4>]<EOL><DEDENT>else:<EOL><INDENT>source, price_index = ['<STR_LIT>' + crypto.upper(), <NUM_LIT:1>]<EOL><DEDENT><DEDENT>url = "<STR_LIT>" % source<EOL>trim = "<STR_LIT>".format(<EOL>at_time - interval, at_time + interval<EOL>)<EOL>response = self.get_url(url + trim).json()<EOL>closest_distance = interval<EOL>best_price = None<EOL>for line in response['<STR_LIT:data>']:<EOL><INDENT>date = line[<NUM_LIT:0>]<EOL>price = line[price_index]<EOL>tick_date = arrow.get(date).datetime<EOL>distance = at_time - tick_date<EOL>if distance.total_seconds() == <NUM_LIT:0>:<EOL><INDENT>return price, source, tick_date<EOL><DEDENT>if distance < closest_distance:<EOL><INDENT>closest_distance = distance<EOL>best_price = price<EOL>best_date = tick_date<EOL><DEDENT><DEDENT>if not best_price:<EOL><INDENT>msg = "<STR_LIT>" % (<EOL>crypto, fiat, at_time<EOL>)<EOL>raise NoData(msg)<EOL><DEDENT>return best_price, source, best_date<EOL>
Using the quandl.com API, get the historical price (by day).
The CRYPTOCHART source claims to be from multiple exchange sources
for price (they say best exchange is most volume).