Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Open a command shell (powershell on windows) and run the command lines below
> pip install -e .
```
### Package configuration
Some environment variables must ne setup for proper package usage. If working in a local environment create a .env file in the root folder of your project and add the following lines:
Some environment variables must be setup for proper package usage. If working in a local environment create a .env file in the root folder of your project and add the following lines:
```
FMPAD_API_KEY=somerandomkeyfromFFPAD
DB_SQL_LIMIT = 1000 # 0 no limits applied to SQL Requests
Expand Down
19 changes: 7 additions & 12 deletions hobbytrader/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def generate_ID(prices_df):
prices_df['ID'] = prices_df.ID + prices_df.Symbol
return prices_df

def create_db_and_table(db_file) -> sqlite3.Connection:
def create_db_and_table(db_file: str) -> sqlite3.Connection:
if not isinstance(db_file, str):
raise TypeError('Parameter not a string.')
# Special function to create a database with a primary key that will ignore insert of an existing key
sql_create_prices_table = """ CREATE TABLE IF NOT EXISTS prices (
ID text PRIMARY KEY ON CONFLICT IGNORE,
Expand All @@ -55,21 +57,14 @@ def create_db_and_table(db_file) -> sqlite3.Connection:
Open real,
Volume real
); """

if not isinstance(db_file, str):
raise TypeError('Parameter not a string.')
conn = None
os.makedirs(os.path.dirname(db_file), exist_ok=True)
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
if not os.path.isfile(db_file):
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
cursor.execute(sql_create_prices_table)
return conn
else:
#raise ValueError(f'Database already exists: {db_file}')
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
print(f'Database already exists, using file: {db_file}')
return conn
return conn

#
# Save to specific file formats
Expand Down