Example #1
0
 def __init__(self, eventEngine, gatewayName='IB'):
     """Constructor"""
     super(IbGateway, self).__init__(eventEngine, gatewayName)
     
     self.host = EMPTY_STRING        # 连接地址
     self.port = EMPTY_INT           # 连接端口
     self.clientId = EMPTY_INT       # 用户编号
     self.accountCode = EMPTY_STRING # 账户编号
     
     self.tickerId = 0               # 订阅行情时的代码编号    
     self.tickDict = {}              # tick快照字典,key为tickerId,value为VtTickData对象
     self.tickProductDict = {}       # tick对应的产品类型字典,key为tickerId,value为产品类型
     
     self.orderId  = 0               # 订单编号
     self.orderDict = {}             # 报单字典,key为orderId,value为VtOrderData对象
     
     self.accountDict = {}           # 账户字典
     
     self.contractDict = {}          # 合约字典
     
     self.subscribeReqDict = {}      # 用来保存订阅请求的字典 
     
     self.connected = False          # 连接状态
     
     self.api = IbWrapper(self)      # API接口
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #2
0
 def __init__(self, eventEngine, gatewayName='LBANK'):
     """Constructor"""
     super(LbankGateway, self).__init__(eventEngine, gatewayName)
     
     self.api = LbankApi(self)
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #3
0
    def __init__(self, eventEngine, gatewayName='BithumbGateway'):
        super(BithumbGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = RestApi(self)  # type: RestApi

        self.qryEnabled = False

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #4
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(BitfinexGateay, self).__init__(eventEngine, gatewayName)

        self.api = GatewayApi(self)

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #5
0
    def __init__(self,
                 eventEngine,
                 gatewayName='',
                 config_dict=None,
                 symbol=''):
        """Constructor"""
        super(FcoinGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = RestApi(self)
        self.wsApi = WebsocketApi(self)
        self.symbol = symbol

        self.qryEnabled = False  # 是否要启动循环查询

        if config_dict == None:
            self.fileName = self.gatewayName + '_' + self.symbol + '_connect.json'
            self.filePath = getJsonPath(self.fileName, __file__)
        else:
            self.fileName = config_dict['file_name']
            self.filePath = getJsonPath(self.fileName, __file__)
Example #6
0
 def __init__(self, eventengine, gatewayName='TKPRO'):
     """Constructor"""
     super(TkproGateway, self).__init__(eventengine, gatewayName)
     
     self.dataApi = TkproDataApi(self)      # 行情
     self.tradeApi = TkproTradeApi(self)    # 交易
     
     self.qryEnabled = False         # 是否要启动循环查询
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)          
Example #7
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(CoinbaseGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = RestApi(self)
        self.wsApi = WebsocketApi(self)

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #8
0
 def __init__(self, eventEngine, gatewayName='HUOBI'):
     """Constructor"""
     super(HuobiGateway, self).__init__(eventEngine, gatewayName)
     
     self.market = 'cny'
     
     self.tradeApi = HuobiTradeApi(self)
     self.dataApi = HuobiDataApi(self)
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #9
0
    def __init__(self, eventEngine, gatewayName='OKCOIN'):
        """Constructor"""
        super(OkcoinGateway, self).__init__(eventEngine, gatewayName)

        self.api = Api(self)

        self.leverage = 0
        self.connected = False

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
def getSymbolMapping(): 
    symbolMap = {}
    dataContent = ""
    settingFileName = 'DR_mapping.json'
    settingfilePath = getJsonPath(settingFileName, __file__)      
    with open(settingfilePath, 'r') as fileObj:
        #print(f.read())
        dataContent = fileObj.read()
        #print(dataContent)
    symbolMap = json.loads(dataContent)   
    return symbolMap     
Example #11
0
    def __init__(self, eventEngine, gatewayName='HUOBI'):
        """Constructor"""
        super(HuobiGateway, self).__init__(eventEngine, gatewayName)

        self.market = 'cny'

        self.tradeApi = HuobiTradeApi(self)
        self.dataApi = HuobiDataApi(self)

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #12
0
    def __init__(self, eventEngine, gatewayName='OANDA'):
        """Constructor"""
        super(OandaGateway, self).__init__(eventEngine, gatewayName)

        self.api = Api(self)
        self.pricePusher = OandaPricePusher(self.api)

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #13
0
    def __init__(self, eventengine, gatewayName='TKPRO'):
        """Constructor"""
        super(TkproGateway, self).__init__(eventengine, gatewayName)

        self.dataApi = TkproDataApi(self)  # 行情
        self.tradeApi = TkproTradeApi(self)  # 交易

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #14
0
 def __init__(self, eventEngine, gatewayName='OKCOIN'):
     """Constructor"""
     super(OkcoinGateway, self).__init__(eventEngine, gatewayName)
     
     self.api = Api(self)     
     
     self.leverage = 0
     self.connected = False
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #15
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(FcoinGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = RestApi(self)
        self.wsApi = WebsocketApi(self)

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #16
0
    def __init__(self, eventEngine, gatewayName='Geya'):
        """Constructor"""
        super(GeyaGateway, self).__init__(eventEngine, gatewayName)

        self.qryEnabled = False  # 循环查询

        self.api = GeyaApi(self)
        self.rmiIp = EMPTY_STRING
        self.rmiPort = EMPTY_STRING

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #17
0
    def __init__(self, mainEngine, eventEngine):
        try:
            self.mainEngine = mainEngine
            self.eventEngine = eventEngine

            self.configFileName = 'option_selector_config.json'
            self.configFile = getJsonPath(self.configFileName, __file__)

            self.optionDict = {}

        except:
            traceback.print_exc()
Example #18
0
 def __init__(self, eventEngine, gatewayName='OKEX'):
     """Constructor"""
     super(OkexGateway, self).__init__(eventEngine, gatewayName)
     
     self.spotApi = SpotApi(self)     
     # self.api_contract = Api_contract(self)
     
     self.leverage = 0
     self.connected = False
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)     
Example #19
0
    def __init__(self, eventEngine, gatewayName='OKEX'):
        """Constructor"""
        super(OkexGateway, self).__init__(eventEngine, gatewayName)

        self.spotApi = SpotApi(self)
        # self.api_contract = Api_contract(self)

        self.leverage = 0
        self.connected = False

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #20
0
    def __init__(self, eventEngine, gatewayName='KSGOLD'):
        """Constructor"""
        super(KsgoldGateway, self).__init__(eventEngine, gatewayName)

        self.tdApi = KsgoldTdApi(self)  # 黄金接口只有交易API
        self.tdConnected = False  # 交易API连接状态
        self.qryEnabled = False  # 是否要启动循环查询

        self.orderInited = False  # 委托初始化查询
        self.tradeInited = False  # 成交初始化查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #21
0
 def get_strategy_config(self, name):
     timestamp = int(time.time())
     config = {"name": name, "version": timestamp}
     config["ip"] = self.get_ip() or self.get_ip2()
     settings = {}
     # find cta settings
     if name in self.ctaEngine.strategyDict:
         strategy = self.ctaEngine.strategyDict[name]
         cta_setting_file = getJsonPath(CTA_SETTING_FILE,
                                        CTA_SETTING_MODULE_FILE)
         with open(cta_setting_file) as f:
             strategy_settings = json.load(f)
         strategy_settings = {
             item["name"]: item
             for item in strategy_settings
         }
         if name in strategy_settings:
             cta_setting = strategy_settings[name]
             cta_setting["symbolList"] = cta_setting.get(
                 "symbolList", None) or strategy.symbolList
             settings[CTA_SETTING_FILE] = [cta_setting]
         else:
             return None
     # find gateway setting
     symbolList = cta_setting["symbolList"]
     for vtSymbol in symbolList:
         gatewayName = vtSymbol.split(":")[-1]
         fileName = gatewayName + GATEWAY_SETTING_SUFFIX
         gateway = self.ctaEngine.getGateway(gatewayName)
         module = importlib.import_module(gateway.__module__)
         filePath = getJsonPath(fileName, module.__file__)
         with open(filePath) as f:
             settings[fileName] = json.load(f)
     # find rpcservice settings
     rs_setting_file = getJsonPath(RS_SETTING_FILE, RS_SETTING_MODULE_FILE)
     with open(rs_setting_file) as f:
         settings[RS_SETTING_FILE] = json.load(f)
     config["settings"] = settings
     return config
Example #22
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(OkexfGateway, self).__init__(eventEngine, gatewayName)
        
        self.qryEnabled = False     # 是否要启动循环查询
        self.localRemoteDict = {}   # localID:remoteID
        self.orderDict = {}         # remoteID:order

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
        
        self.restApi = OkexfRestApi(self)
        self.wsApi = OkexfWebsocketApi(self)        
Example #23
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(BitmexGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = BitmexRestApi(self)
        self.wsApi = BitmexWebsocketApi(self)

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
        
        self.exchange = constant.EXCHANGE_BITMEX
Example #24
0
    def __init__(self, eventEngine, gatewayName="KORBIT"):
        """Constructor"""
        super(korbitGateway, self).__init__(eventEngine, gatewayName)

        self.tradeApi = KorbitTradeApi(self)
        self.dataApi = KorbitDataApi(self)

        self.fileName = self.gatewayName + "_connect.json"
        self.filePath = getJsonPath(self.fileName, __file__)
        self.accountID = "NONE"

        self.total_count = 0
        self.delayTime = 3
Example #25
0
    def __init__(self, eventEngine, gatewayName='KSGOLD'):
        """Constructor"""
        super(KsgoldGateway, self).__init__(eventEngine, gatewayName)

        self.tdApi = KsgoldTdApi(self)  # 黄金接口只有交易API
        self.tdConnected = False        # 交易API连接状态
        self.qryEnabled = False         # 是否要启动循环查询
        
        self.orderInited = False        # 委托初始化查询
        self.tradeInited = False        # 成交初始化查询
        
        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)             
Example #26
0
    def __init__(self, mainEngine, eventEngine):
        try:
            self.mainEngine = mainEngine
            self.eventEngine = eventEngine

            self.configFileName = 'catch_limit_up.json'
            self.configFile = getJsonPath(self.configFileName, __file__)

            self.strategyDict = {}
            self.symbolStrategyDict = {}

        except:
            traceback.print_exc()
Example #27
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""

        super(BitfinexGateay, self).__init__(eventEngine, gatewayName)
        self.api = GatewayApi(self)

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        self.connected = False
        self.count = 0
    def __init__(self, eventEngine, gatewayName='COINCHECK'):
        """Constructor"""
        super(CoincheckGateway, self).__init__(eventEngine, gatewayName)

        self.tradeApi = CoincheckTradeApi(self)
        #self.dataApi = CoincheckDataApi(self)
        self.dataApi = CoincheckSocketDataApi(self)

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        self.total_count = 0
        self.delayTime = 3
Example #29
0
    def __init__(self, eventEngine, gatewayName='Tushare'):
        """Constructor"""
        super(TushareGateway, self).__init__(eventEngine, gatewayName)

        self.mdConnected = False  # 行情API连接状态,登录完成后为True
        self.tdConnected = False  # 交易API连接状态

        self.qryEnabled = False  # 循环查询

        self.subSymbolList = []

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #30
0
    def __init__(self, eventEngine, gatewayName = "KORBIT"):
        """Constructor"""
        super(korbitGateway , self).__init__(eventEngine, gatewayName)

        self.tradeApi = KorbitTradeApi(self)
        self.dataApi = KorbitDataApi(self)

        self.fileName = self.gatewayName + "_connect.json"
        self.filePath = getJsonPath(self.fileName, __file__)       
        self.accountID = "NONE"

        self.total_count = 0
        self.delayTime = 3
Example #31
0
    def __init__(self, eventEngine, gatewayName=''):
        """Constructor"""
        super(BitmexGateway, self).__init__(eventEngine, gatewayName)

        self.restApi = BitmexRestApi(self)
        self.wsApi = BitmexWebsocketApi(self)

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
        
        self.exchange = constant.EXCHANGE_BITMEX
Example #32
0
    def __init__(self, eventEngine, gatewayName='HUOBI'):
        """Constructor"""
        super(HuobiGateway, self).__init__(eventEngine, gatewayName)

        self.dataApi = HuobiDataApi(self)       # 行情API
        self.tradeApi = HuobiTradeApi(self)     # 交易API

        self.mdConnected = False        # 行情API连接状态,登录完成后为True
        self.tdConnected = False        # 交易API连接状态

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #33
0
    def __init__(self, eventEngine, gatewayName='COINCHECK'):
        """Constructor"""
        super(CoincheckGateway, self).__init__(eventEngine, gatewayName)
        
        
        self.tradeApi = CoincheckTradeApi(self)
        #self.dataApi = CoincheckDataApi(self)
        self.dataApi = CoincheckSocketDataApi(self)
        
        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)       

        self.total_count = 0
        self.delayTime = 3
Example #34
0
 def __init__(self, eventEngine, gatewayName='QDP'):
     """Constructor"""
     super(QdpGateway, self).__init__(eventEngine, gatewayName)
     
     self.mdApi = QdpMdApi(self)     # 行情API
     self.tdApi = QdpTdApi(self)     # 交易API
     
     self.mdConnected = False        # 行情API连接状态,登录完成后为True
     self.tdConnected = False        # 交易API连接状态
     
     self.qryEnabled = False         # 是否要启动循环查询
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #35
0
    def __init__(self, eventEngine, gatewayName='XSPEED'):
        """Constructor"""
        super(XspeedGateway, self).__init__(eventEngine, gatewayName)

        self.mdApi = XspeedMdApi(self)  # 行情API
        self.tdApi = XspeedTdApi(self)  # 交易API

        self.mdConnected = False  # 行情API连接状态,登录完成后为True
        self.tdConnected = False  # 交易API连接状态

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #36
0
    def __init__(self, eventEngine, gatewayName='HUOBI'):
        """Constructor"""
        super(HuobiGateway, self).__init__(eventEngine, gatewayName)

        self.dataApi = HuobiDataApi(self)       # 行情API
        self.tradeApi = HuobiTradeApi(self)     # 交易API

        self.mdConnected = False        # 行情API连接状态,登录完成后为True
        self.tdConnected = False        # 交易API连接状态

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #37
0
    def __init__(self, eventEngine, gatewayName='BINANCE'):
        """Constructor"""
        super(BinanceGateway, self).__init__(eventEngine, gatewayName)

        self.dataApi = BinanceDataApi(self)  # 行情API
        self.tradeApi = BinanceTradeApi(self, self.dataApi)  # 交易API

        self.mdConnected = False  # 行情API连接状态,登录完成后为True
        self.tdConnected = False  # 交易API连接状态

        self.qryEnabled = False  # 是否要启动循环查询
        self.listenKey = None

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #38
0
    def __init__(self, eventEngine, gatewayName='CTP'):
        """Constructor"""
        # print "%s.%s.%s" % (__name__, self.__class__.__name__, get_current_function_name())
        super(CtpGateway, self).__init__(eventEngine, gatewayName)

        self.mdApi = CtpMdApi(self)  # 行情API
        self.tdApi = CtpTdApi(self)  # 交易API

        self.mdConnected = False  # 行情API连接状态,登录完成后为True
        self.tdConnected = False  # 交易API连接状态

        self.qryEnabled = False  # 循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #39
0
    def __init__(self,
                 eventEngine,
                 gatewayName='HUOBI',
                 config_dict=None,
                 symbol=''):
        """Constructor"""
        super(HuobiGateway, self).__init__(eventEngine, gatewayName)

        self.dataApi = HuobiDataApi(self)  # 行情API
        self.tradeApi = HuobiTradeApi(self)  # 交易API

        self.mdConnected = False  # 行情API连接状态,登录完成后为True
        self.tdConnected = False  # 交易API连接状态

        self.qryEnabled = False  # 是否要启动循环查询

        self.symbol = symbol

        if config_dict == None:
            self.fileName = self.gatewayName + '_' + self.symbol + '_connect.json'
            self.filePath = getJsonPath(self.fileName, __file__)
        else:
            self.fileName = config_dict['file_name']
            self.filePath = getJsonPath(self.fileName, __file__)
Example #40
0
 def __init__(self, eventEngine, gatewayName='LTS'):
     """Constructor"""
     super(LtsGateway, self).__init__(eventEngine, gatewayName)
     
     self.mdApi = LtsMdApi(self)
     self.tdApi = LtsTdApi(self)
     self.qryApi = LtsQryApi(self)
     
     self.mdConnected = False
     self.tdConnected = False
     self.qryConnected = False
     
     self.qryEnabled = False         # 是否要启动循环查询
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)             
Example #41
0
    def init_client(self):
        fileName = globalSetting.get('gateway_name', '') + '_connect.json'
        filePath = getJsonPath(fileName, __file__)
        try:
            with open(filePath, 'r') as f:
                # 解析json文件
                setting = json.load(f)
                apiKey = setting.get('accessKey',None)
                secretKey = setting.get('secretKey',None)

                if apiKey is not None and secretKey is not None:
                    self.client = Client(apiKey, secretKey)

        except IOError:
            self.strategy.writeCtaError(u'BINANCE读取连接配置{}出错,请检查'.format(filePath))
            return
Example #42
0
    def __init__(self, eventEngine, gatewayName='LTS'):
        """Constructor"""
        super(LtsGateway, self).__init__(eventEngine, gatewayName)

        self.mdApi = LtsMdApi(self)
        self.tdApi = LtsTdApi(self)
        self.qryApi = LtsQryApi(self)

        self.mdConnected = False
        self.tdConnected = False
        self.qryConnected = False

        self.qryEnabled = False  # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #43
0
    def __init__(self, eventEngine, gatewayName='IB'):
        """Constructor"""
        super(IbGateway, self).__init__(eventEngine, gatewayName)

        self.host = EMPTY_STRING  # 连接地址
        self.port = EMPTY_INT  # 连接端口
        self.clientId = EMPTY_INT  # 用户编号
        self.accountCode = EMPTY_STRING  # 账户编号

        self.tickerId = 0  # 订阅行情时的代码编号
        self.tickDict = {}  # tick快照字典,key为tickerId,value为VtTickData对象
        self.tickProductDict = {}  # tick对应的产品类型字典,key为tickerId,value为产品类型

        self.orderId = 0  # 订单编号
        self.orderDict = {}  # 报单字典,key为orderId,value为VtOrderData对象

        self.accountDict = {}  # 账户字典

        self.contractDict = {}  # 合约字典

        self.subscribeReqDict = {}  # 用来保存订阅请求的字典

        self.connected = False  # 连接状态

        self.api = IbWrapper(self)  # API接口

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        self.qryEnabled = True  # 循环查询

        fileName = 'param.json'
        try:
            f = file(fileName)
        except IOError:
            print('读取param参数配置出错,请检查')
        # 解析json文件-----------------------------------------------------
        mysetting = json.load(f)
        redisHost = str(mysetting['redisHost'])
        redisPort = str(mysetting['redisPort'])
        self.r = redis.Redis(host=redisHost, port=int(redisPort),
                             db=8)  # zls添加,用于传持仓信息
        self.r.set('usposition', 0)  # 初始化美油仓位 0

        # redis订阅
        my_thread = threading.Thread(target=self.redisSub)
        my_thread.start()
Example #44
0
    def __init__(self, mainEngine, eventEngine):
        try:
            self.mainEngine = mainEngine
            self.eventEngine = eventEngine

            self.configFileName = 'option_sprites_config.json'
            self.configFile = getJsonPath(self.configFileName, __file__)
            self.config = {}

            self.workingOptionDict = {}
            self.optionTick = {}

            # 用于从正股找到option
            self.ownerToOption = {}

        except:
            traceback.print_exc()
    def __init__(self, eventEngine, gatewayName='QuantOS'):
        """Constructor"""
        super(QuantosGateway, self).__init__(eventEngine, gatewayName)

        self.qryEnabled = False  # 循环查询开关
        self.qsqApi = None  # 行情API
        self.qstApi = None  # 交易API
        self.setting = []  # API配置
        self.user_info = {}  # 交易账号信息
        self.strategyID = EMPTY_INT  # 策略编号

        # API配置文件
        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        # 获取配置信息
        self.getConfig()
Example #46
0
    def init_client(self):
        fileName = globalSetting.get('gateway_name', '') + '_connect.json'
        filePath = getJsonPath(fileName, __file__)
        try:
            with open(filePath, 'r') as f:
                # 解析json文件
                setting = json.load(f)
                apiKey = setting.get('accessKey', None)
                secretKey = setting.get('secretKey', None)

                if apiKey is not None and secretKey is not None:
                    self.client = Client(apiKey, secretKey)

        except IOError:
            self.strategy.writeCtaError(
                u'BINANCE读取连接配置{}出错,请检查'.format(filePath))
            return
Example #47
0
def testTrade():
    """测试交易"""
    filePath = getJsonPath('BINANCE_connect.json', __file__)
    f = file(filePath)
    setting = json.load(f)

    accessKey = str(setting['accessKey'])
    secretKey = str(setting['secretKey'])

    # 创建API对象并初始化
    api = TradeApi()

    api.init(accessKey, secretKey)
    api.start()

    # 查询
    # api.getListenKey()
    # res = api.getSymbols()
    # api.getTimestamp()
    # api.placeTestOrder('ETHUSDT', 'BUY', 1, 200)
    # res = api.getAccount()
    # res = api.getMyTrades('ETHUSDT')
    for i in range(50000):
        # res = api.getCurrentOpenOrders()
        res = api.getOrder('ETHUSDT',
                           origClientOrderId='BINANCE_152528_200067')
        time.sleep(5)

    # accountid = ''
    # symbol = 'aaceth'

    #api.getAccounts()
    #api.getAccountBalance(accountid)
    #api.getOrders(symbol, 'pre-submitted,submitted,partial-filled,partial-canceled,filled,canceled')
    #api.getOrders(symbol, 'filled')
    #api.getMatchResults(symbol)

    # api.getOrder('2440401255')
    # api.getMatchResult('2440401255')

    #api.placeOrder(accountid, '2', symbol, 'sell-market', source='api')
    #api.cancelOrder('2440451757')
    #api.batchCancel(['2440538580', '2440537853', '2440536765'])
    # print 'res:%s' % res
    input()
Example #48
0
    def __init__(self, eventEngine , gatewayName='BINANCE'):
        """Constructor"""
        super(BinanceGateway, self).__init__(eventEngine, gatewayName)
        self.api_spot = BinanceApi(self)

        self.connected = False
        self.qryEnabled = True

        self.interval = 30
        self.accountID = "None"
        self.total_count = 0

        # gateway 配置文件
        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        # 消息调试
        self.log_message = False
    def __init__(self, eventEngine, gatewayName='TradeDllAShare'):
        """Constructor"""
        super(TradeDllAShareGateway, self).__init__(eventEngine, gatewayName)

        self.ipPort = None
        self.markets = []
        self.accountId = None
        self.env = 1  # 默认仿真交易
        self.clientId = self.INVALID_CLIENT_ID

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)

        self.tickDict = {}
        self.tradeSet = set()  # 保存成交编号的集合,防止重复推送

        self.qryEnabled = True
        self.qryThread = Thread(target=self.qryData)
Example #50
0
 def readConfig(self):
     """
     从json文件中读取设置,并将其内容返回为一个dict
     :一个一个return:
     """
     fileName = self.gatewayName + '_connect.json'
     filePath = getJsonPath(fileName, __file__)
 
     try:
         with open(filePath, 'rt') as f:
             return json.load(f)
     except IOError:
         log = VtLogData()
         log.gatewayName = self.gatewayName
         log.logContent = u'读取连接配置出错,请检查'
         # todo: pop a message box is better
         self.onLog(log)
         return None
Example #51
0
    def __init__(self, eventEngine, gatewayName='HUOBI'):
        """Constructor"""
        super(HuobiGateway, self).__init__(eventEngine, gatewayName)

        self.localID = 10000
        
        self.accountDict = {}
        self.orderDict = {}
        self.localOrderDict = {}
        self.orderLocalDict = {}

        self.restApi = HuobiRestApi(self)                   
        self.tradeWsApi = HuobiTradeWebsocketApi(self)      
        self.marketWsApi = HuobiMarketWebsocketApi(self)    

        self.qryEnabled = False         # 是否要启动循环查询

        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)
Example #52
0
    def __init__(self, eventEngine, gatewayName='ZB'):
        """Constructor"""
        super(zbGateway, self).__init__(eventEngine, gatewayName)
        
        self.api_spot = ZB_API_Spot(self)     
        
        self.connected = False
        
        self.fileName = self.gatewayName + '_connect.json'
        self.filePath = getJsonPath(self.fileName, __file__)     


        self.qryEnabled = True

        self.countTimer = 0
        self.localTimeDelay = 3

        # 启动查询
        self.initQuery()
        self.startQuery()
Example #53
0
 def __init__(self, eventEngine, gatewayName='FUTU'):
     """Constructor"""
     super(FutuGateway, self).__init__(eventEngine, gatewayName)
     
     self.quoteCtx = None
     self.tradeCtx = None
     
     self.host = ''
     self.ip = 0
     self.market = ''
     self.password = ''
     self.env = 1        # 默认仿真交易
     
     self.fileName = self.gatewayName + '_connect.json'
     self.filePath = getJsonPath(self.fileName, __file__)
     
     self.tickDict = {}
     self.tradeSet = set()      # 保存成交编号的集合,防止重复推送
     
     self.qryEnabled = True
     self.qryThread = Thread(target=self.qryData)