forked from QuantFans/quantdigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_data.py
More file actions
41 lines (32 loc) · 1.04 KB
/
import_data.py
File metadata and controls
41 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
import os
import pandas as pd
from quantdigger import locd, set_config
from quantdigger.datasource import import_data
def import_contracts():
""" 从文件导入合约到数据库"""
df = pd.read_csv('./work/contracts.txt')
df['key'] = df['code'] + '.' + df['exchange']
return df
print("import contracts info..")
contracts = import_contracts()
set_config({'source': 'csv'})
locd.import_contracts(contracts)
print("import bars..")
fpaths = []
for path, dirs, files in os.walk('./work'):
for file in files:
filepath = path + os.sep + file
if filepath.endswith(".csv") or filepath.endswith(".CSV"):
fpaths.append(filepath)
import_data(fpaths, locd)
set_config({'source': 'sqlite'})
locd.import_contracts(contracts)
print("import bars..")
fpaths = []
for path, dirs, files in os.walk('./work'):
for file in files:
filepath = path + os.sep + file
if filepath.endswith(".csv") or filepath.endswith(".CSV"):
fpaths.append(filepath)
import_data(fpaths, locd)