Exemplo n.º 1
0
def from_string_to_security(st):
    if ',' not in st:
        print(__name__ +
              '::from_string_to_security: EXIT, format is not correct')
        exit()
    stList = st.split(',')
    secType = stList[0].strip()
    if secType in ['CASH', 'STK']:
        primaryExchange = stList[1].strip()
        exchange = stList[2].strip()
        ticker = stList[3].strip()
        currency = stList[4].strip()
        return Security(secType=secType,
                        symbol=ticker,
                        currency=currency,
                        exchange=exchange,
                        primaryExchange=primaryExchange,
                        symbolStatus=SymbolStatus.STRING_CONVERTED)

    elif secType in ['FUT', 'BOND']:
        primaryExchange = stList[1].strip()
        exchange = stList[2].strip()
        ticker = stList[3].strip()
        currency = stList[4].strip()
        expiry = stList[5].strip()
        return Security(secType=secType,
                        symbol=ticker,
                        currency=currency,
                        exchange=exchange,
                        primaryExchange=primaryExchange,
                        expiry=expiry,
                        symbolStatus=SymbolStatus.STRING_CONVERTED)
    else:
        primaryExchange = stList[1].strip()
        exchange = stList[2].strip()
        ticker = stList[3].strip()
        currency = stList[4].strip()
        expiry = stList[5].strip()
        strike = float(stList[6].strip())
        right = stList[7].strip()
        multiplier = stList[8].strip()
        return Security(secType=secType,
                        symbol=ticker,
                        currency=currency,
                        exchange=exchange,
                        primaryExchange=primaryExchange,
                        expiry=expiry,
                        strike=strike,
                        right=right,
                        multiplier=multiplier,
                        symbolStatus=SymbolStatus.STRING_CONVERTED)
Exemplo n.º 2
0
def superSymbol(secType=None,
                ticker=None,
                currency='USD',
                exchange='',
                primaryExchange='',
                expiry='',
                strike=0.0,
                right='',
                multiplier='',
                includeExpired=False):
    return Security(secType=secType, symbol=ticker, currency=currency, exchange=exchange,
                    primaryExchange=primaryExchange, expiry=expiry, strike=strike, right=right,
                    multiplier=multiplier, includeExpired=includeExpired, symbolStatus=SymbolStatus.SUPER_SYMBOL)
Exemplo n.º 3
0
def from_symbol_to_security(s1):
    if ',' not in s1:
        s1 = 'STK,%s,USD' % (s1, )

    secType = s1.split(',')[0].strip()
    ticker = s1.split(',')[1].strip()
    currency = s1.split(',')[2].strip()
    if secType in ['CASH', 'STK']:
        return Security(secType=secType, symbol=ticker, currency=currency)
    else:
        print('Definition of %s is not clear!' % (s1, ))
        print('Please use superSymbol to define a str_security')
        print(r'http://www.ibridgepy.com/ibridgepy-documentation/#superSymbol')
        exit()
Exemplo n.º 4
0
def superSymbol(secType=None,
                symbol=None,
                currency='USD',
                exchange='',
                primaryExchange='',
                localSymbol='',
                expiry='',
                strike=0.0,
                right='',
                multiplier='',
                includeExpired=False):
    if not isinstance(strike, float):
        print(__name__ + '::superSymbol: EXIT, strike must be a float!')
        exit()
    if not isinstance(expiry, str):
        print(__name__ + '::superSymbol: EXIT, expiry must be a string!')
        exit()
    if not isinstance(localSymbol, str):
        print(__name__ + '::superSymbol: EXIT, localSymbol must be a string!')
        exit()
    if not isinstance(multiplier, str):
        print(__name__ + '::superSymbol: EXIT, multiplier must be a string!')
        exit()
    if secType in ['FUT', 'OPT']:
        assert (len(expiry) == 8)
    return Security(secType=secType,
                    symbol=symbol,
                    currency=currency,
                    exchange=exchange,
                    localSymbol=localSymbol,
                    primaryExchange=primaryExchange,
                    expiry=expiry,
                    strike=strike,
                    right=right,
                    multiplier=multiplier,
                    includeExpired=includeExpired,
                    symbolStatus=SymbolStatus.SUPER_SYMBOL)