commit
3b0b17c04e
@ -0,0 +1,10 @@
|
||||
*.json
|
||||
tmp*
|
||||
*.csv
|
||||
.ipynb*
|
||||
.DS_Store
|
||||
tmp*
|
||||
data/
|
||||
output/
|
||||
logs/
|
||||
*.pyc
|
@ -0,0 +1,86 @@
|
||||
import dolphindb as ddb
|
||||
import dolphindb.settings as keys
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
# from loguru import logger
|
||||
|
||||
class DDBfm():
|
||||
|
||||
ddb_config_servers = {
|
||||
'local':
|
||||
{'host' : '192.168.64.3',
|
||||
'username' : 'admin',
|
||||
'password' : '123456'},
|
||||
'dev':
|
||||
{'host' : '192.168.1.88',
|
||||
'username' : 'admin',
|
||||
'password' : '123456'},
|
||||
'prd':
|
||||
{'host' : '192.168.1.7',
|
||||
'username' : 'admin',
|
||||
'password' : '123456'}
|
||||
}
|
||||
|
||||
# len: 71
|
||||
all_fm_init=['sc', 'v', 'TS', 'MA', 'AP', 'jm', 'bc', 'bb', 'fu', 'IM', 'IF', 'a', 'lu', 'FG', 'cu', 'al', 'IH', 'RS', 'pg', 'CF', 'SF', 'ni', 'hc', 'UR', 'm', 'SR', 'j', 'PF', 'RM', 'T', 'c', 'JR', 'l', 'p', 'sp', 'CY', 'pb', 'TF', 'b', 'eg', 'rb', 'PK', 'sn', 'nr', 'pp', 'CJ', 'eb', 'SA', 'y', 'RI', 'lh', 'jd', 'OI', 'WH', 'ss', 'ru', 'zn', 'fb', 'rr', 'PM', 'au', 'TA', 'ZC', 'IC', 'bu', 'SM', 'wr', 'cs', 'LR', 'ag', 'i']
|
||||
|
||||
|
||||
ddb_daily_path = "dfs://daily_futuremarket_ts"
|
||||
ddb_daily_dbname = "db_daily_fm"
|
||||
|
||||
ddb_hft_path="dfs://hft_futuremarket_ts"
|
||||
|
||||
ddb_hft_tick_dbname="Tick"
|
||||
ddf_hft_tick_tbname="TickPartitioned"
|
||||
|
||||
ddb_hft_mink_dbname="MinKline"
|
||||
ddf_hft_mink_tbname="MinKlinePartitioned"
|
||||
|
||||
|
||||
def __init__(self, which_server='local', **kwargs):
|
||||
|
||||
self.ddb_config = self.ddb_config_servers[which_server]
|
||||
|
||||
self.sess = ddb.session(self.ddb_config['host'], 8848)
|
||||
self.sess.login(self.ddb_config['username'], self.ddb_config['password'])
|
||||
|
||||
def drop_dbpath(self,dbPath):
|
||||
if self.sess.existsDatabase(dbPath):
|
||||
self.sess.dropDatabase(dbPath)
|
||||
|
||||
def create_ddb_database(self,dbPath,dbName):
|
||||
db_init = self.sess.database(dbName='db_init', partitionType=keys.VALUE, partitions=self.all_fm_init, dbPath='')
|
||||
|
||||
months=np.array(pd.date_range(start='2000-01', end='2050-12', freq="M"), dtype="datetime64[M]")
|
||||
# print(months)
|
||||
db_date = self.sess.database('db_date', partitionType=keys.VALUE, partitions=months, dbPath='')
|
||||
|
||||
if self.sess.existsDatabase(dbPath):
|
||||
self.sess.dropDatabase(dbPath)
|
||||
db = self.sess.database(dbName=dbName, partitionType=keys.COMPO, partitions=[db_date, db_init], dbPath=dbPath, engine='OLAP')
|
||||
# todo: engine=TSDB
|
||||
|
||||
return db
|
||||
|
||||
def add_new_hft_table(self, db, tbName, df):
|
||||
t = self.sess.table(data=df,tableAliasName=tbName)
|
||||
pt =db.createPartitionedTable(table=t, tableName=tbName, partitionColumns=['m_nDate', 'code_init'])
|
||||
pt.append(t)
|
||||
|
||||
|
||||
def append_hft_table(self, dbPath, tbName, df):
|
||||
# load table to check? time&date&code
|
||||
appender = ddb.tableAppender(tableName=tbName, ddbSession=self.sess,dbPath=dbPath)
|
||||
appender.append(df)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
ddb = DDBfm()
|
||||
ddb.create_ddb_database()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in new issue