def stop_sync_helper(t):
    t = int(t)
    if not ManagedProcess.is_process_existed(IB_SYNC_PROCESS_NAME % t):
        return {'status': 1}

    ManagedProcess.remove_process(IB_SYNC_PROCESS_NAME % t)
    return {'status': 0}
def start_sync_helper(t):
    t = int(t)
    symbols = list(db.get_ib_sync_symbols())
    if not symbols:
        return {'status': 2}

    existed = ManagedProcess.is_process_existed(IB_SYNC_PROCESS_NAME % t)
    if existed:
        return {'status': 1}

    contracts = [utils.make_contract(
        symbol['symbol'], 'SMART') for symbol in symbols]
    ManagedProcess.create_process(
        IB_SYNC_PROCESS_NAME % t, _inner_start_sync_helper, (t, contracts))
    return {'status': 0}
Example #3
0
def stop_sync():
    """
    Stop syncing.

    :return:
    {
        "success": true  // 当前接口是否成功
        "data": {
            "status": 0|1|  //0:正在同步,已经关闭,1: 已经关闭
        }
    }
    """
    try:
        is_td_process_existed = ManagedProcess.is_process_existed(
            TD_SYNC_PROCESS_NAME)
        if not is_td_process_existed:
            return parse_resp({'status': 1})

        ManagedProcess.remove_process(TD_SYNC_PROCESS_NAME)
        return parse_resp({'status': 0})
    except Exception as e:
        return parse_resp({'message': str(e)}, False)
Example #4
0
def start_sync():
    """
    Start syncing td stock data.

    :return:
    {
        "success": true  // 当前接口是否成功
        "data": {
            "status": 0|1|  //0:当前数据同步成功开启,1:当前数据同步已经开启,不需要再开启
        }
    }
    """
    try:
        symbols = StockUtils.get_stock_symbols()
        is_td_process_existed = ManagedProcess.is_process_existed(
            TD_SYNC_PROCESS_NAME)
        if is_td_process_existed:
            return parse_resp({'status': 1})

        ManagedProcess.create_process(TD_SYNC_PROCESS_NAME, start_sync_helper,
                                      (symbols, ))
        return parse_resp({'status': 0})
    except Exception as e:
        return parse_resp({'message': str(e)}, False)
Example #5
0
def sync_status():
    """
    Current sync status indicating if the server is syncing.

    :return:
    {
        "success": true  // 当前接口是否成功
        "data": {
            "status": 0|1|  //0:当前服务器没有同步数据,1:当前服务器正在同步数据
        }
    }
    """
    try:
        return parse_resp({
            'status':
            int(ManagedProcess.is_process_existed(TD_SYNC_PROCESS_NAME))
        })
    except Exception as e:
        return parse_resp({'message': str(e)}, False)
Example #6
0
def get_sync_progress():
    """
    Get syncing progress.

    :return:
    {
        "success": true  // 当前接口是否成功
        "data": {
            "lastSyncStocks": [  // 最新同步的25条股票数据
                "symbol": "HUYA",
                "frequency": "1M",
                "syncDateTime": "2018-08-14 11:10:00"  // 我们所有的时间都是New York Region时间
            ]  // 最新的同步的股票数据
            "currentProgress": "0.223",  // 表示当前同步的进度比例为22.3%
            "isSyncing": true,  // 表示当前股票是否在同步,如果出现异常则为false,并且进程就会关闭
            "eta": "3600"  //表示当前股票还需3600s=1h的时间才能同步完毕.
            "syncedSymbol": 200  // 表示有200支股票已经是最新状态.
        }
    }
    """
    try:
        data_map = {
            'isSyncing':
            bool(int(ManagedProcess.is_process_existed(TD_SYNC_PROCESS_NAME))),
            'lastSyncStocks':
            SyncProcessHelper.get_sync_records(),
            'currentProgress':
            SyncProcessHelper.get_sync_progress(),
            'syncedSymbol':
            SyncProcessHelper.get_synced_symbols_count(),
            'eta':
            SyncProcessHelper.get_sync_progress_eta()
        }
        return parse_resp({'data': data_map})
    except Exception as e:
        return parse_resp({'message': str(e)}, False)
def get_sync_status_helper(t):
    return {'status': int(ManagedProcess.is_process_existed(IB_SYNC_PROCESS_NAME % t))}