예제 #1
0
파일: main.py 프로젝트: ewenqua/pqctp3.0
def start():
    user_trade = TraderApiPy(broker_id=BROKER_ID,
                             investor_id=INVESTOR_ID,
                             passwd=PASSWORD,
                             auth_code=AUTH_CODE,
                             app_id=APP_ID)
    user_trade.Create(LOGS_DIR + "_trade")
    user_trade.RegisterFront(ADDR_TRADE)
    user_trade.Init()
    Strategy.setTraderSpi(user_trade)
    #print ('before init strategy')
    InitStrategy()

    user_md = MdApiPy(instruments=inst_strategy.keys(),
                      broker_id=BROKER_ID,
                      investor_id=INVESTOR_ID,
                      passwd=PASSWORD)
    user_md.Create(LOGS_DIR + "_md")
    user_md.RegisterFront(ADDR_MD)
    user_md.Init()

    _date = '19700101'
    while True:
        time.sleep(60)
        _time = time.strftime('%H%M%S')
        hint_time = time.localtime(time.time())
        if hint_time.tm_min % 15 == 0:
            print('The main thread is runing, date = %s, time = %s' %
                  (time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S')))
        if '150000' < _time < '150100' and _date < time.strftime('%Y%m%d'):
            TickController.saveDayBar()
            _date = time.strftime('%Y%m%d')
예제 #2
0
파일: main.py 프로젝트: ewenqua/pyctp
def InitStrategy():
    for i in range(len(inst_strategy)):
        inst = inst_strategy.keys()[i]
        paras = inst_strategy[inst]   # paras = {'strategy':'StrategyFairyFour', 'MA20': 20, ...}
        #strategy = None
        if paras['strategy'] == 'StrategyRBreaker':
            inst_thread[inst] = StrategyRBreaker(inst, volume = paras['volume'])
        elif paras['strategy'] == 'StrategyFairyFour':
            inst_thread[inst] = StrategyFairyFour(inst)
        elif paras['strategy'] == 'StrategyDoubleMA':
            inst_thread[inst] = StrategyDoubleMA(inst,fast = paras['fast'],slow = paras['slow'], volume = paras['volume'])
        # add more strategy
        else:
            print 'The strategy is not found! '
        inst_thread[inst].setDaemon(True)
예제 #3
0
파일: main.py 프로젝트: ewenqua/pqctp3.0
def InitStrategy():
    for i in range(len(inst_strategy)):
        inst = list(inst_strategy.keys())[i]
        paras = inst_strategy[
            inst]  # paras = {'strategy':'StrategyFairyFour', 'MA20': 20, ...}
        #strategy = None
        if paras['strategy'] == 'StrategyRBreaker':
            inst_thread[inst] = StrategyRBreaker(inst, volume=paras['volume'])
        elif paras['strategy'] == 'StrategyFairyFour':
            inst_thread[inst] = StrategyFairyFour(inst)
        elif paras['strategy'] == 'StrategyDoubleMA':
            inst_thread[inst] = StrategyDoubleMA(inst,
                                                 fast=paras['fast'],
                                                 slow=paras['slow'],
                                                 volume=paras['volume'])
        # add more strategy
        else:
            print('The strategy is not found! ')
        inst_thread[inst].setDaemon(True)
예제 #4
0
def start():

    user_trade = TraderDelegate(broker_id=BROKER_ID,
                                investor_id=INVESTOR_ID,
                                passwd=PASSWORD)

    print BROKER_ID, INVESTOR_ID, PASSWORD

    user_trade.Create(LOGS_DIR + "_trader")
    user_trade.RegisterFront(ADDR_TRADE)
    user_trade.Init()

    Strategy.setTraderSpi(user_trade)

    InitStrategy()

    user_md = MdDelegate(instruments=inst_strategy.keys(),
                         broker_id=BROKER_ID,
                         investor_id=INVESTOR_ID,
                         passwd=PASSWORD)
    user_md.Create(LOGS_DIR + "_md")
    user_md.RegisterFront(ADDR_MD)
    user_md.Init()

    _date = '19700101'
    while True:
        time.sleep(60)
        _time = time.strftime('%H%M%S')
        hint_time = time.localtime(time.time())

        #if hint_time.tm_min % 15 == 0:
        if hint_time.tm_min % 3 == 0:
            print 'The main thread is runing, account %s, date = %s, time = %s' % (
                INVESTOR_ID, time.strftime('%Y-%m-%d'),
                time.strftime('%H:%M:%S'))
        if '150000' < _time < '150100' and _date < time.strftime('%Y%m%d'):
            TickController.saveDayBar()
            _date = time.strftime('%Y%m%d')
예제 #5
0
파일: main.py 프로젝트: ewenqua/pyctp
def start():
    user_trade = TraderDelegate(broker_id=BROKER_ID, investor_id=INVESTOR_ID, passwd=PASSWORD)
    user_trade.Create(LOGS_DIR + "_trader")
    user_trade.RegisterFront(ADDR_TRADE)
    user_trade.Init()
    Strategy.setTraderSpi(user_trade)

    InitStrategy()

    user_md = MdDelegate(instruments=inst_strategy.keys(), broker_id=BROKER_ID, investor_id=INVESTOR_ID, passwd=PASSWORD)
    user_md.Create(LOGS_DIR +"_md")
    user_md.RegisterFront(ADDR_MD)
    user_md.Init()

    _date = '19700101'
    while True:
        time.sleep(60)
        _time = time.strftime('%H%M%S')
        hint_time = time.localtime(time.time())
        if hint_time.tm_min % 15 == 0:
            print 'The main thread is runing, date = %s, time = %s' % (time.strftime('%Y-%m-%d'),time.strftime('%H:%M:%S'))
        if '150000'< _time < '150100' and _date < time.strftime('%Y%m%d'):
            TickController.saveDayBar()
            _date = time.strftime('%Y%m%d')
예제 #6
0
파일: SyncDayBar.py 프로젝트: pxctp/pxctp
#-*- coding=utf-8 -*-
from FinalLogger import logger
from Constant import inst_strategy, suffix_list
import urllib
import json
import sqlite3

conn = sqlite3.connect('futures.db3', check_same_thread=False)
for i in inst_strategy.keys():
    daybar_table = i + suffix_list[0]
    cmd = "DROP TABLE IF EXISTS " + daybar_table
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + daybar_table \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, open DOUBLE NULL, high DOUBLE NULL, low DOUBLE NULL, close DOUBLE NULL, volume INTEGER NULL, TradingDay TEXT NULL, time TEXT NULL)"
    conn.execute(cmd)

if __name__ == "__main__":
    # 'http://stock2.finance.sina.com.cn/futures/api/json.php/IndexService.getInnerFuturesDailyKLine?symbol=M1701'
    base_url = 'http://stock2.finance.sina.com.cn/futures/api/json.php/IndexService.getInnerFuturesDailyKLine?symbol='
    for symbol in inst_strategy.keys():
        url = base_url + symbol
        print 'url = ' + url
        results = json.load(urllib.urlopen(url))

        for r in results:
            # r -- ["2016-09-05","2896.000","2916.000","2861.000","2870.000","1677366"]  open, high, low, close
            conn.execute(
                "INSERT INTO %s (inst, open, high, low, close, volume, TradingDay,time) VALUES ('%s', %f, %f, %f, %f, %d, '%s','%s')"
                % (symbol + suffix_list[0], symbol, float(r[1]), float(r[2]),
                   float(r[3]), float(r[4]), int(r[5]), r[0], '15:00:00'))
예제 #7
0
#-*- coding:utf-8 -*-
import sqlite3
import time
from FinalLogger import logger
from Constant import inst_strategy, database_map, suffix_list

conn = sqlite3.connect('futures.db3', check_same_thread=False)
# init database and read data to memory
for i in inst_strategy.keys():
    # create table if not exist
    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[0]\
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, open DOUBLE NULL, high DOUBLE NULL, low DOUBLE NULL, close DOUBLE NULL, volume INTEGER NULL, TradingDay TEXT NULL, time TEXT NULL)"
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[1] \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, OrderRef TEXT NULL, Direction TEXT NULL, OffsetFlag TEXT NULL, Price DOUBLE NULL, Volume INTEGER NULL, TradeDate TEXT NULL, TradeTime TIME NULL )"
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[2] \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, OrderRef TEXT NULL, Direction TEXT NULL, OffsetFlag TEXT NULL, Price DOUBLE NULL, Volume INTEGER NULL, TradeDate TEXT NULL, TradeTime TIME NULL )"
    conn.execute(cmd)

    # [xx_DayBar[], xx_SendOrder[], xx_RtnOrder[]]
    table_list = []

    cursor = conn.execute(
        "SELECT open, high, low, close, volume from %s WHERE inst='%s'" %
        (i + suffix_list[0], i))
    day_bar = cursor.fetchall()
    if day_bar is not None:
        d = list(day_bar)
예제 #8
0
파일: SyncDayBar.py 프로젝트: ewenqua/pyctp
#-*- coding=utf-8 -*-
from FinalLogger import logger
from Constant import inst_strategy, suffix_list
import urllib
import json
import sqlite3

conn = sqlite3.connect('futures.db3', check_same_thread = False)
for i in inst_strategy.keys() :
    daybar_table = i + suffix_list[0]
    cmd = "DROP TABLE IF EXISTS " + daybar_table
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + daybar_table \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, open DOUBLE NULL, high DOUBLE NULL, low DOUBLE NULL, close DOUBLE NULL, volume INTEGER NULL, TradingDay TEXT NULL, time TEXT NULL)"
    conn.execute(cmd)

if __name__=="__main__":
    # 'http://stock2.finance.sina.com.cn/futures/api/json.php/IndexService.getInnerFuturesDailyKLine?symbol=M1701'
    base_url = 'http://stock2.finance.sina.com.cn/futures/api/json.php/IndexService.getInnerFuturesDailyKLine?symbol='
    for symbol in inst_strategy.keys():
        url = base_url + symbol
        print 'url = ' + url
        results = json.load(urllib.urlopen(url))

        for r in results:
            # r -- ["2016-09-05","2896.000","2916.000","2861.000","2870.000","1677366"]  open, high, low, close
            conn.execute(
                "INSERT INTO %s (inst, open, high, low, close, volume, TradingDay,time) VALUES ('%s', %f, %f, %f, %f, %d, '%s','%s')"
                % (symbol + suffix_list[0], symbol, float(r[1]), float(r[2]), float(r[3]), float(r[4]), int(r[5]), r[0], '15:00:00'))
            conn.commit()
예제 #9
0
#-*- coding:utf-8 -*-
import sqlite3
import time
from FinalLogger import logger
from Constant import inst_strategy, database_map, suffix_list

conn = sqlite3.connect('futures.db3', check_same_thread=False)
# init database and read data to memory
tab_list = ['j1805', 'rb1805', 'rb1810']
for i in list(inst_strategy.keys()):
    # for i in tab_list:

    # create table if not exist
    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[0]\
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, open DOUBLE NULL, high DOUBLE NULL, low DOUBLE NULL, close DOUBLE NULL, volume INTEGER NULL, TradingDay TEXT NULL, time TEXT NULL)"
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[1] \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, OrderRef TEXT NULL, Direction TEXT NULL, OffsetFlag TEXT NULL, Price DOUBLE NULL, Volume INTEGER NULL, TradeDate TEXT NULL, TradeTime TIME NULL )"
    conn.execute(cmd)

    cmd = "CREATE TABLE IF NOT EXISTS " + i + suffix_list[2] \
          + " (id INTEGER PRIMARY KEY NULL, inst TEXT NULL, OrderRef TEXT NULL, Direction TEXT NULL, OffsetFlag TEXT NULL, Price DOUBLE NULL, Volume INTEGER NULL, TradeDate TEXT NULL, TradeTime TIME NULL )"
    conn.execute(cmd)

    # [xx_DayBar[], xx_SendOrder[], xx_RtnOrder[]]
    table_list = []

    cursor = conn.execute(
        "SELECT open, high, low, close, volume from %s WHERE inst='%s'" %
        (i + suffix_list[0], i))