当前位置: 首页>>代码示例>>Python>>正文


Python Connections.change_connections方法代码示例

本文整理汇总了Python中lib.dbtools.connections.Connections.change_connections方法的典型用法代码示例。如果您正苦于以下问题:Python Connections.change_connections方法的具体用法?Python Connections.change_connections怎么用?Python Connections.change_connections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.dbtools.connections.Connections的用法示例。


在下文中一共展示了Connections.change_connections方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: top_traded

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
def top_traded():
    map_func = Code ("""function() {
                    if (this.occ_nb_replace == 0){
                        emit(this.cheuvreux_secid, this.turnover * this.rate_to_euro)
                        }
                    }""")
                    
    reduce_func = Code (""" function(sec_id, quantity) {
                        return Array.sum(quantity)
                        }
                        """)
    Connections.change_connections("production")
    db = Connections.getClient("MARS")["Mars"]["AlgoOrders"]
    result = db.map_reduce(map_func, reduce_func, "my_result")
    
    turnover_executed = {}
    for doc in result.find():    
        if doc[u"_id"] is not None and doc[u"value"] > 0: 
            turnover_executed[int(doc[u"_id"])] = int(doc[u"value"])
    
    sorted_x = sorted(turnover_executed.iteritems(), key= lambda x: x[1], reverse = True)
    
    sec_ids = []
    keys = []
    values = []
    for i in range(20):
        sec_ids.append(sorted_x[i][0])
        keys.append(convert_symbol(source = "security_id", dest = "security_name", value = sorted_x[i][0])[0][0])
        values.append(sorted_x[i][1])
        print convert_symbol(source = "security_id", dest = "security_name", value = sorted_x[i][0])
    for i in range(20):
        print sorted_x[i][1]    
    figure, ax = plt.subplots(1, 1)
    ax.bar(range(20), values)
    plt.show()
开发者ID:okrane,项目名称:framework,代码行数:37,代码来源:patricia_most_traded_stocks.py

示例2: ImportIndicators

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
def ImportIndicators(DataBase, l_indicator, perimeter, path):
    
    
    outfile = open('%s/security_indicator_dump.txt' %path,'w')
    Connections.change_connections('production')
    
    cursor, cxn = Connections.getCursor(DataBase)
    
    if perimeter == 'all':
        for indicator_id in l_indicator:
            query = "select ci.indicator_id, cii.name, ci.indicator_value, ci.security_id, ci.trading_destination_id ,erc.EXCHGID " \
            "from MARKET_DATA..ci_security_indicator ci " \
            "left join KGR..EXCHANGEREFCOMPL erc on (erc.EXCHANGE = ci.trading_destination_id) " \
            "left join MARKET_DATA..ci_indicator cii on (cii.indicator_id = ci.indicator_id) " \
            "where (erc.GLOBALZONEID = 1 or erc.GLOBALZONEID is NULL) and ci.indicator_id in (%s) " \
            "and (ci.trading_destination_id > 0 or ci.trading_destination_id is NULL) " \
            "order by ci.indicator_id, ci.security_id, ci.trading_destination_id" %(indicator_id)
    
            cursor.execute(query)
            result = cursor.fetchall()
            
            for line in result:
                if line[5] is None:
                    line[5] = 'AGGR'
                str_line  = ''
                for item in line:
                    str_line = "%s%s;" %(str_line, item)
                str_line = '%s\n' %str_line[:-1]
                outfile.write(str_line)
    
    outfile.close()
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:ImportIndicators.py

示例3: get_data

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
def get_data():
    Connections.change_connections("production")
    
    query = """ select occ.IdOccurence,
        occ.SecurityRateToEuro,
        occ.SecurityId,
        occ.Side,     
        seq.StartTime, 
        seq.EndTime, 
        seq.AutomatonName,         
        occ.OrderDate,
        seq.AutomatonStatTime, 
        seq.AutomatonEndTime, 
        seq.ExecutedAmount, 
        seq.ExecutedQuantity
            
        from dm_algo..Algo_Sequence seq, dm_algo..Algo_Occurence occ
        where occ.OrderDate > '20130101' and occ.OrderDate < '20130201' 
        and occ.IdOccurence = seq.IdOccurence 
        and seq.ExecutedQuantity is not NULL"""
    
    #query = """select top 10 * from dm_algo..Algo_Occurence        """
    
    result = Connections.exec_sql("VEGA", query, as_dict = True)
    print "Fetched", len(result), "lines"
    keys = result[0].keys()
    f = open("C:/st_sim/repository/export_cheuvreux_orders.csv", "w")
    f.writelines(";".join(keys)+"\n")
    for k in result:
        f.writelines(";".join([str(x) for x in k.values()]) + "\n")
    f.close()
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:algo_extract_cheuvreux.py

示例4: any

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
                
            #-- ciupdatesecurityindicator_all : day before
            if out and any((data['jobname'] == 'ciupdatesecurityindicator_ost') & (data['date'] >= dt.datetime.strptime(date_s,'%Y%m%d'))):
                out = any(data[(data['jobname'] == 'ciupdatesecurityindicator_ost') & (data['date'] >= dt.datetime.strptime(date_s,'%Y%m%d'))]['status'].values == 'O')                
                
            if not out:
                logging.warning('Indicator database has not been update properly for date : ' + date_s)
               
    except:
        logging.error('error in check_db_update func')
    
    return out


if __name__ == "__main__":
    
    Connections.change_connections('production_copy')
    
    check_db_update(dt.datetime.now())
    
    GPATH = 'W:\\Global_Research\\Quant_research\\projets\\export_sym'
    
    security_ref = pd.read_csv(os.path.join(GPATH,'test','TRANSCOSYMBOLCHEUVREUX.csv'),sep = ';')
    security_ref = security_ref[['cheuvreux_secid', 'ticker', 'tickerAG']]
    
    export_symdata(data_security_referential = security_ref,
                       path_export = os.path.join(GPATH, 'test'), 
                       filename_export = 'symdata',
                       indicators2export = [1,86])

    
开发者ID:okrane,项目名称:framework,代码行数:31,代码来源:indicator.py

示例5: get_traceback

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
                        self.client[self.database]['AlgoOrders'].update({"p_cl_ord_id" : p_cl_ord_id}, 
                                                                        {"$set" : {"ExcludeAuction" : d["ExcludeAuction"]}})
                        i = i + 1
                    except IndexError:
                        pass
                    except KeyError:
                        pass
                    except :
                        get_traceback()
                logging.info('Update %d data '% i)
            ssh.close()
                
    
if __name__ == '__main__':
    from lib.dbtools.connections import Connections
    Connections.change_connections("dev")    
    
    database_server     = 'MARS'
    database            = 'Mars'
    environment         = 'dr'
    source              = 'CLNT1'
    date                = last_business_day(datetime.now())
    limit               = datetime(year = 2013, month = 10, day = 8)
    dates               = []
    l_date              = []
    
    while date > limit:
        dates.append(datetime.strftime(date, "%Y%m%d"))
        date = last_business_day(date)

#    dates               = [date]
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:patch.py

示例6:

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
# -*- coding: utf-8 -*-
"""
Created on Wed May 08 09:34:59 2013

@author: svlasceanu
"""
"""
import pymssql
#conn = pymssql.connect(host='LUIDBC01', user='KEPLERCM\svlasceanu', password='asa', database='KGR')
#conn = pymssql.connect(host='172.29.100.64', user='python_ro', password='python4ever!!', database='KGR')
conn = pymssql.connect(host='172.29.0.24', user='greg', password='greggreg', database='master')
cur = conn.cursor()
cur.callproc('SP_WHO', ())
#cur.execute('select * from sysobjects')
print cur.fetchall()
#conn.close()
"""
"""
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=172.29.100.64;DATABASE=KGR;UID=python_ro;PWD=python4ever!!')
cursor = cnxn.cursor()
cursor.execute('select * from KGR..security_market where security_id = 276')
print cursor.fetchall()
"""

from lib.dbtools.connections import Connections
Connections.change_connections('dev')
a = Connections.exec_sql('KGR', 'select top 10 * from SECURITY', as_dataframe = True)
print a

开发者ID:okrane,项目名称:framework,代码行数:31,代码来源:test_pymssql.py

示例7: sum

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
        
        xlabel                  = 'Nbr Occ/Algo'
        total_all               = sum(nbr_all_occ)
        total_dma               = sum(nbr_dma_occ)
        title  = 'From ' + self.start_date_str + ' To '+ self.end_date_str + '\nTotal Occurrence: ' + str(int(total_all))  + ' \n DMA Occurrence: ' + str(int(total_dma))
        return self.plot_algo_dma_vs_all(title, nbr_dma_occ, nbr_all_occ, nbr_all_occ.index, xlabel)
    
    
class AdvancedPlotEngine(PlotEngine):
    pass 

      
if __name__=='__main__':
    from lib.dbtools.connections import Connections
    Connections.change_connections("production")
    
    
#     day = datetime(year=2013, month=8, day=21)
    day = datetime.now() - timedelta(days=1)
    
#     daily = PlotEngine(start_date = day - timedelta(days=56), end_date = day  , filter = {'Account': {'$regex' : 'AKO.*'}})
#     
#     # One DAY
#     daily = PlotEngine(start_date = day, end_date = day)
#     daily.plot_basic_stats()
#     daily.plot_intraday_exec_curve()
#     plt.show()
#     
#     # Weekly
#     weekly = PlotEngine(start_date = day - timedelta(days=7), end_date = day )
开发者ID:okrane,项目名称:framework,代码行数:32,代码来源:wrapper.py

示例8: __connect

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
 def __connect(self):
     if not self.is_connected:
         Connections.change_connections(self.env)
         self.client = Connections.getClient(self.database_server)
         self.is_connected = True
开发者ID:okrane,项目名称:framework,代码行数:7,代码来源:algodatabaseplug.py

示例9: MARKET

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
                                             #-- MARKET (daily) 
                                             'occ_m_d_volume_lit','occ_m_d_volume_lit_main','occ_m_d_volume_auction_main','occ_m_d_vol_gk_bp','occ_m_d_nb_trades_lit_cont',
                                             'occ_m_d_open_price','occ_m_d_close_price','occ_m_d_spread_bp',
                                             #-- EXEC computed  (2)
                                             'occ_exec_vwap','occ_bench_duration_min',
                                             #-- OCC FE : COMPUTED
                                             'occ_fe_turnover','occ_fe_volume','occ_fe_vwap','occ_fe_arrival_price',
                                             'occ_fe_slippage_vwap_constr_bp','occ_fe_slippage_is_bp',
                                             #-- PERF : COMPUTED
                                             'occ_slippage_vwap_bp','occ_slippage_vwap_constr_bp','occ_slippage_is_bp',
                                             #-- EXEC computed (3)
                                             'occ_spread_bp' , 'occ_plr_lit','occ_dlr_lit',
                                             #-- PERF COMPOUNDED: COMPUTED
                                             'occ_compperf_vwap_bp','occ_compperf_vwap_constr_bp','occ_compperf_is_bp',
                                             ]}}
    Connections.change_connections(ENV)
    
    t1 = AlgoDatabasePlug(start_date = SDATE, 
                          end_date = EDATE , 
                          filter = FILTER,
                          push_compute_stats_mode = COMPUTE_STATS_MODE,
                          env = ENV , 
                          push_params = PUSH_PARAMS)
    
    #-----  test push_algostats
    t1.push_algostats()
    #t1.send_email()
    print t1.push_enrichment
    print t1.push_missing_errorpush
    
#     #-----  erase what has been pushed (all database !)
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:algodatabaseplug.py

示例10: send_email

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
    # ---
    send_email(_to = email_list, 
               _from = '[email protected]',
               _subject = "[SymServer] Export Files ",
               _message = html_message , 
               _files = [os.path.join( pathexport , 'email_log.txt')])





if __name__ == "__main__":
    
    logging.info("EXPORT SYMSERVER : START")
    
    Connections.change_connections('production')
    
    
    date = dt.datetime.now()
    day = dt.datetime.strftime(date, format= '%Y%m%d')
    
    #############################################################################
    #- GLOBAL VARS + TEST
    #############################################################################
    
    force_generate = True
    
    # -- path
    if os.name == 'nt':
        GPATH = 'W:\\Global_Research\\Quant_research\\projets\\export_sym'
    else:
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:export_all_files.py

示例11: datetime

# 需要导入模块: from lib.dbtools.connections import Connections [as 别名]
# 或者: from lib.dbtools.connections.Connections import change_connections [as 别名]
# -*- coding: utf-8 -*-

from lib.dbtools.read_dataset import *
from datetime import datetime, timedelta
from lib.dbtools.connections import Connections
import matplotlib.pyplot as plt
import numpy as np
from numpy import arange,array,ones,linalg
import pandas as pd

start_date = datetime(2013, 01, 10)
end_date = datetime(2013, 06, 01)

"""
Connections.change_connections('production')

query = "select * from trading_daily where security_id = 110 and trading_destination_id = 1 and date > CONVERT(datetime, '%s')" % (datetime.strftime(start_date, '%Y-%m-%d'))
print query

data = Connections.exec_sql('MKTDATA', query, as_dict = True)
rand = []
volume = []

for i in range(1, len(data)):
    rand.append(np.abs(data[i]['close_prc'] - data[i-1]['close_prc']))
    volume.append(data[i]['close_volume'])

print volume
    
plt.plot(rand, volume, '.', color = 'r')
plt.show()
开发者ID:okrane,项目名称:framework,代码行数:33,代码来源:backtest_close_volume.py


注:本文中的lib.dbtools.connections.Connections.change_connections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。