Skip to content

Commit 194ac4d

Browse files
committed
fixed creating price tables
1 parent fa50a07 commit 194ac4d

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

.bettercodehub.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
component_depth: 1
2+
languages:
3+
- python

.circleci/config.yml

Whitespace-only changes.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![Code Health](https://landscape.io/github/sirfoga/pyhodl/master/landscape.svg?style=flat)](https://landscape.io/github/sirfoga/pyhodl/master) [![BCH compliance](https://bettercodehub.com/edge/badge/sirfoga/pyhodl?branch=master)](https://bettercodehub.com/) [![Code Climate](https://lima.codeclimate.com/github/sirfoga/pyhodl/badges/gpa.svg)](https://codeclimate.com/github/sirfoga/pyhodl)
66

7-
[![Build Status](https://travis-ci.org/sirfoga/pyhodl.svg?branch=master)](https://travis-ci.org/sirfoga/pyhodl)
7+
[![Build Status](https://travis-ci.org/sirfoga/pyhodl.svg?branch=master)](https://travis-ci.org/sirfoga/pyhodl) [![CircleCI](https://circleci.com/gh/sirfoga/pyhodl.png)](https://circleci.com/gh/sirfoga/pyhodl)
88

99
![Python version](https://img.shields.io/badge/Python-3.5.2-blue.svg) ![pylint Score](https://mperlet.de/pybadge/badges/9.14.svg)
1010

install.sh

100644100755
+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717

1818

1919
pip3 install . --upgrade --force-reinstall
20-
pip3 install six==1.10.0 # gdax requires these dependencies
21-
pip3 install requests==2.13.0
20+
python3 setup.py test

pyhodl/config.py

+11
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@
6161
FIAT_COINS = [Coin("USD"), Coin("EUR")] # supported fiat coins
6262
DEFAULT_FIAT = "USD"
6363
CRYPTO_COINS = CoinsNamesTable(COINS_DATABASE).get_coins()
64+
65+
66+
def get_coin_historical_data_file(currency):
67+
"""
68+
:param currency: str
69+
Currency to get
70+
:return: str
71+
Path to file containing currency historical data
72+
"""
73+
74+
return os.path.join(HISTORICAL_DATA_FOLDER, currency.lower() + ".json")

pyhodl/data/tables.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from hal.files.parsers import JSONParser
2525

2626
from pyhodl.config import HISTORICAL_DATA_FOLDER, DATE_TIME_KEY, VALUE_KEY, \
27-
INFINITY
27+
INFINITY, get_coin_historical_data_file
2828
from pyhodl.utils import parse_datetime
2929

3030

@@ -47,9 +47,14 @@ def __init__(self, input_file, max_error_search):
4747
for item in self.get_content()
4848
} # date -> raw dict
4949
self.dates = sorted(self.content.keys()) # sorted list of all dates
50-
5150
self.max_error = float(max_error_search) # seconds
5251

52+
def get_content(self):
53+
if os.path.exists(self.path):
54+
return super().get_content()
55+
56+
return {}
57+
5358
def get_values_on(self, date_time):
5459
"""
5560
:param date_time: datetime
@@ -112,10 +117,10 @@ def get_value_on(self, date_time):
112117
class CoinPricesTable(DatetimeTable):
113118
""" Parse market data files """
114119

115-
def __init__(self, currency="USD"):
120+
def __init__(self, currency):
116121
DatetimeTable.__init__(
117122
self,
118-
os.path.join(HISTORICAL_DATA_FOLDER, currency.lower() + ".json"),
123+
get_coin_historical_data_file(currency),
119124
24 * 60 * 60 # a day
120125
)
121126

@@ -141,7 +146,7 @@ def get_value_on(self, coin, date_time):
141146
return None
142147

143148

144-
COINS_PRICES_TABLE = CoinPricesTable()
149+
COINS_PRICES_TABLE = CoinPricesTable("USD")
145150

146151

147152
def get_coin_prices_table(currency="USD"):

0 commit comments

Comments
 (0)