Exemplo n.º 1
0
def getapis():
    '''some RESTful APIS'''
    mk = ManageKeys()
    key = mk.getKey('av')
    return (EXAMPLES['api1'].format(key=key), EXAMPLES['api2'].format(key=key),
            EXAMPLES['api3'].format(key=key), EXAMPLES['api4'].format(key=key),
            EXAMPLES['api5'].format(key=key))
Exemplo n.º 2
0
    def __init__(self, settings, db=None):
        super().__init__()

        self.apiset = settings
        self.mk = ManageKeys(db=db)

        ui = SapiDlg()
        ui.setupUi(self)
        self.ui = ui

        checkForIbapi()

        self.setWindowIcon(QIcon('structjour/images/ZSLogo.png'))

        self.ui.ibRealCb.clicked.connect(self.ibClicked)
        self.ui.ibPaperCb.clicked.connect(self.ibPaperclicked)
        self.ui.ibRealPort.editingFinished.connect(self.setIbRealPort)
        self.ui.ibRealId.editingFinished.connect(self.setIbRealId)
        self.ui.ibPaperPort.editingFinished.connect(self.setIbPaperPort)
        self.ui.ibPaperId.editingFinished.connect(self.setIbPaperId)

        self.ui.tgoCb.clicked.connect(self.setTgoCb)
        self.ui.tgoKey.editingFinished.connect(self.setTgoKey)

        self.ui.bcCb.clicked.connect(self.setBcCb)
        self.ui.bcKey.editingFinished.connect(self.setBcKey)

        self.ui.avCb.clicked.connect(self.setAvCb)
        self.ui.avKey.editingFinished.connect(self.setAvKey)

        self.ui.fhCb.clicked.connect(self.setFhCb)
        self.ui.fhKey.editingFinished.connect(self.setFhKey)

        self.ui.APIPref.textChanged.connect(self.colorApis)
        self.ui.APIPref.editingFinished.connect(self.orderApis)

        self.ui.okBtn.pressed.connect(self.okPressed)

        self.ui.APIPref.setStyleSheet('color: black;')

        v = QIntValidator()
        self.ui.ibRealPort.setValidator(v)
        self.ui.ibRealId.setValidator(v)
        self.ui.ibPaperPort.setValidator(v)
        self.ui.ibPaperId.setValidator(v)

        self.initFromSettings()
        self.gotibapi = checkForIbapi()
        # self.sortIt(None)
        # self.orderApis()

        self.show()
Exemplo n.º 3
0
    def __init__(self, apiset, orprefs=None, keydict={}):
        '''
        The currenly supported apis are barchart, alphavantage, finnhub and ibapi
        These are represented by the tokens bc, av, fh, and ib
        :params apiset: QSettings with key 'APIPref'
        :params orprefs: List: Override the api prefs in settings
        '''
        self.apiset = apiset
        self.orprefs = orprefs
        self.preferences = self.getPreferences()
        self.api = self.preferences[0]
        self.keydict = keydict
        if len(self.keydict) == 0:
            mk = ManageKeys()

            self.keydict = mk.getKeyDict()
Exemplo n.º 4
0
def getKey():
    mk = ManageKeys()
    return mk.getKey('av')
Exemplo n.º 5
0
def getApiKey():
    mk = ManageKeys()
    key = mk.getKey('tgo')
    return key
Exemplo n.º 6
0
def getApiKey():
    '''Returns the key for the barchart API
    '''
    mk = ManageKeys()
    return mk.getKey('bc')
Exemplo n.º 7
0
    def apiChooserList(self, start, end, api=None):
        '''
        Given the current list of apis as av, bc, wtd, fh and ib, determine if the given api will
            likely return data for the given times.
        :params start: A datetime object or time stamp indicating the intended start of the chart.
        :params end: A datetime object or time stamp indicating the intended end of the chart.
        :params api: Param must be one of mav, bc, fh, wtd or ib. If given, the return value in
            (api, x, x)[0] will reflect the bool result of the api
        :return: (bool, rulesviolated, suggestedStocks) The first entry is only valid if api is
            an argument.

        '''
        start = pd.Timestamp(start)
        end = pd.Timestamp(end)

        # Need a naive time showing NewYorkTime right now
        ne = pd.Timestamp.now("US/Eastern")
        n = pd.Timestamp(ne.year, ne.month, ne.day, ne.hour, ne.minute,
                         ne.second)

        violatedRules = []
        suggestedApis = self.getPreferences()
        if len(suggestedApis) == 0:
            self.api = None
            return (False, ['No stock Api is selected'], [])
        # nopen = dt.datetime(n.year, n.month, n.day, 9, 30)
        nclose = dt.datetime(n.year, n.month, n.day, 16, 30)

        # Rule 1 Barchart will not return todays data till 16:30
        # Rule 1a Barchart will not return yesterdays data after 12 till 1630
        tradeday = pd.Timestamp(start.year, start.month, start.day)
        todayday = pd.Timestamp(n.year, n.month, n.day)
        yday = todayday - pd.Timedelta(days=1)
        y = pd.Timestamp(yday.year, yday.month, yday.day, 11, 59)
        if tradeday == todayday and n < nclose and 'bc' in suggestedApis:
            suggestedApis.remove('bc')
            violatedRules.append(
                'Barchart free data will not return todays data till 16:30')
        if tradeday == yday and end > y and n < nclose and 'bc' in suggestedApis:
            suggestedApis.remove('bc')
            violatedRules.append(
                'Barchart free data will not yesterdays data after 12 till today at  16:30'
            )

        # Rule 2 No support any charts greater than 7 days prior to today for Alphavantage
        # Rule 2 No support any charts greated than 7 days prior to tody for World Trade Data
        # Rule 2 No support any charts greater than 30 days for Barchart
        if n > start:
            delt = n - start
            if delt.days > 31 and 'bc' in suggestedApis:
                suggestedApis.remove('bc')
                lastday = n - pd.Timedelta(days=31)
                violatedRules.append(
                    'Barchart data before {} is unavailable.'.format(
                        lastday.strftime("%b %d")))
            if delt.days > 6 and 'av' in suggestedApis:
                suggestedApis.remove('av')
                lastday = n - pd.Timedelta(days=6)
                violatedRules.append(
                    'AlphaVantage data before {} is unavailable.'.format(
                        lastday.strftime("%b %d")))
            if delt.days > 6 and 'wtd' in suggestedApis:
                suggestedApis.remove('wtd')
                lastday = n - pd.Timedelta(days=6)
                violatedRules.append(
                    'WorldTradeData data before {} is unavailable in 1 minute candles.'
                    .format(lastday.strftime("%b %d")))

        # Rule 3 Don't call ib if the library is not installed
        # Rule 4 Don't call ib if its not connected
        if self.apiset.value('gotibapi', type=bool):
            if 'ib' in suggestedApis and not ib.isConnected():
                suggestedApis.remove('ib')
                violatedRules.append('IBAPI is not connected.')
        elif 'ib' in suggestedApis:
            suggestedApis.remove('ib')
            violatedRules.append('IBAPI is not installed')

        # Rule 5 No data is available for the future
        if start > n:
            suggestedApis = []
            violatedRules.append('No data is available for the future.')
        # Rule No 6 Don't call barchart if there is no apikey in settings
        # Rule No 6 Don't call WorldTradeDate if there is no apikey in settings
        # Rule No 6 Don't call alphavantage if there is no apikey in settings
        # Rule No 6 Don't call finnhub if there is no api key in settings
        mk = ManageKeys()
        bc_key = mk.getKey('bc')
        av_key = mk.getKey('av')
        wtd_key = mk.getKey('wtd')
        fh_key = mk.getKey('fh')
        if not bc_key and 'bc' in suggestedApis:
            suggestedApis.remove('bc')
            violatedRules.append(
                'There is no apikey in the database for barchart')
        if not av_key and 'av' in suggestedApis:
            suggestedApis.remove('av')
            violatedRules.append(
                'There is no apikey in the database for alphavantage')

        if not wtd_key and 'wtd' in suggestedApis:
            suggestedApis.remove('wtd')
            violatedRules.append(
                'There is no apikey in the database for WorldTradeData')
        if not fh_key and 'fh' in suggestedApis:
            suggestedApis.remove('fh')
            violatedRules.append(
                'There is no apikey in the database for finnhub')

        # Rule No 7 API limit has been reached [bc, av, fh, wtd]
        deleteme = []
        for token in suggestedApis:
            if token == 'ib':
                continue
            if getLimitReached(token, self.apiset):
                deleteme.append(token)
                violatedRules.append(
                    f'You have reached your quota for {token}')
        for token in deleteme:
            suggestedApis.remove(token)
        api = api in suggestedApis if api else False

        self.api = suggestedApis[0] if suggestedApis else None
        self.violatedRules = violatedRules

        return (api, violatedRules, suggestedApis)