コード例 #1
0
ファイル: api.py プロジェクト: drplums/morieto-finance
def get_stock_stream(symbol, params={}):
    """ gets stream of messages for given symbol
    """
    all_params = ST_BASE_PARAMS.copy()
    for k, v in params.iteritems():
        all_params[k] = v
    return R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol), params=all_params)
コード例 #2
0
ファイル: api.py プロジェクト: drplums/morieto-finance
def get_message_stream(wl_id, params={}):
    """ Gets up to 30 messages from Watchlist (wl_id) according to additional params
    """
    all_params = ST_BASE_PARAMS.copy()
    for k, v in params.iteritems():
        all_params[k] = v
    return R.get_json(ST_BASE_URL + 'streams/watchlist/{}.json'.format(wl_id), params=all_params)
コード例 #3
0
def get_stock_stream(symbol, params={}):
    """ gets stream of messages for given symbol
        copied from api.py (found on GitHub)
    """
    all_params = ST_BASE_PARAMS.copy()
    return R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol),
                      params=all_params)
コード例 #4
0
def get_message_stream(wl_id, params={}):
    """ Gets up to 30 messages from Watchlist (wl_id) according to additional params
    """
    all_params = ST_BASE_PARAMS.copy()
    for k, v in params.iteritems():
        all_params[k] = v
    return R.get_json(ST_BASE_URL + 'streams/watchlist/{}.json'.format(wl_id), params=all_params)
コード例 #5
0
ファイル: api.py プロジェクト: deiv1992/PhD
def get_stock_stream(symbol, params={}):
    """ gets stream of messages for given symbol
    """
    all_params = ST_BASE_PARAMS.copy()
    for k, v in params.iteritems():
        all_params[k] = v
    return R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol),
                      params=all_params)
コード例 #6
0
ファイル: api.py プロジェクト: drplums/morieto-finance
def delete_from_watchlist(symbol, wl_id):
    """ removes a single "symbols" (str) from watchlist.  Returns True on success, False on failure
    """
    params = ST_BASE_PARAMS.copy()
    params['symbols'] = symbol
    resp = R.post_json(ST_BASE_URL + 'watchlists/{}/symbols/destroy.json'.format(wl_id), params=params)
    if resp['response']['status'] == 200:
        return True
    else:
        return False
コード例 #7
0
def delete_from_watchlist(symbol, wl_id):
    """ removes a single "symbols" (str) from watchlist.  Returns True on success, False on failure
    """
    params = ST_BASE_PARAMS.copy()
    params['symbols'] = symbol
    resp = R.post_json(ST_BASE_URL + 'watchlists/{}/symbols/destroy.json'.format(wl_id), params=params)
    if resp['response']['status'] == 200:
        return True
    else:
        return False
コード例 #8
0
def get_stock_stream(symbol, params={}):
    """ gets stream of messages for given symbol
    """
    #Adding creation of requestors instance
    #R = Requests()
    #end addition
    all_params = ST_BASE_PARAMS.copy()
    '''for k, v in params.iteritems():
        all_params[k] = v
        '''
    return R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol), params=all_params)
コード例 #9
0
ファイル: api.py プロジェクト: drplums/morieto-finance
def add_to_watchlist(symbols, wl_id):
    """ Adds list of symbols to our StockTwits watchlist.  Returns list of new symbols added
    """
    deadline = 30 * len(symbols)
    symbols = ','.join(symbols)  # must be a csv list
    params = ST_BASE_PARAMS.copy()
    params['symbols'] = symbols
    resp = R.post_json(ST_BASE_URL + 'watchlists/{}/symbols/create.json'.format(wl_id), params=params, deadline=deadline)
    if resp['response']['status'] == 200:
        return [s['symbol'] for s in resp['symbols']]
    else:
        return []
コード例 #10
0
def add_to_watchlist(symbols, wl_id):
    """ Adds list of symbols to our StockTwits watchlist.  Returns list of new symbols added
    """
    deadline = 30 * len(symbols)
    symbols = ','.join(symbols)  # must be a csv list
    params = ST_BASE_PARAMS.copy()
    params['symbols'] = symbols
    resp = R.post_json(ST_BASE_URL + 'watchlists/{}/symbols/create.json'.format(wl_id), params=params, deadline=deadline)
    if resp['response']['status'] == 200:
        return [s['symbol'] for s in resp['symbols']]
    else:
        return []
コード例 #11
0
def get_stock_stream(symbol, output_filename, params={}):
    """ gets stream of messages for given symbol
    """
    print("printing stock stream")
    all_params = ST_BASE_PARAMS.copy()
    for k, v in params.items():
        all_params[k] = v
    result = R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol),
                        params=all_params)

    if os.path.isfile(output_filename):
        f = open(output_filename, "a+")
    else:
        f = open(output_filename, "w")

    #    result = R.get_json(ST_BASE_URL + 'streams/symbol/{}.json'.format(symbol))
    f.write(json.dumps(result))

    return result