def get_price(self):
        price = get_stock_price(self.stock)

        # today, yesterday, current, high, low
        today = float(price[1])
        yesterday = float(price[2])
        current = float(price[3])
        high = float(price[4])
        low = float(price[5])
        turnover = int(float(price[9])/100000000.0)
        name = price[0].split('"')[-1]

        r = str(rate(current, yesterday))[:4]

        if not self.last_price:
            self.forward = '--'
        elif current > self.last_price:
            self.forward = '/\\'
        elif current < self.last_price:
            self.forward = '\/'
        else:
            pass

        self.last_price = current
        return u'{} {} ({}% {}) {} {}'.format(self.name, self.stock, r, current, self.forward, turnover)
Example #2
0
    def get_price(self):
        price = get_stock_price(self.stock)

        # today, yesterday, current, high, low
        today = float(price[1])
        yesterday = float(price[2])
        current = float(price[3])
        high = float(price[4])
        low = float(price[5])
        volume = float(price[8])
        name = price[0].split('"')[-1]

        if today == '0.00':
            return u'{}(0.00)'.format(self.stock)

        r = rate(current, yesterday)

        if not self.available and r < 9.9:
            self.reopen = True

        if r > 9.9:
            self.available = False
        else:
            self.available = True

        if len(self.five_price) == 5:
            self.five_price.pop(0)
        self.five_price.append(r)

        if len(self.five_price) > 1:
            forward = self.five_price[-1] - self.five_price[-2]
        else:
            forward = '0.00'

        r = str(r)[:4]
        forward = str(forward)[:4]

        buy = int(price[10]) + int(price[12]) + int(price[14]) + int(price[16]) + int(price[18])
        sell = int(price[20]) + int(price[22]) + int(price[24]) + int(price[26]) + int(price[28])

        if sell == 0:
            bs = float(buy) / float(1)
            if volume > 0:
                buy_rate = buy /volume
        else:
            bs = float(buy) / float(sell)

        if bs > 1:
            bs = str(bs)[:4]
            return u'{}({} {})({})'.format(self.stock, r, forward, bs)
        else:
            return u''
Example #3
0
def scan(stock):
    # pot1 = get_stock_history_by_date(stock, '2015-10-08')
    # pot2 = get_stock_history_by_date(stock, '2015-10-09')
    pot3 = get_stock_history_by_date(stock, '2015-10-12')
    pot4 = get_stock_history_by_date(stock, '2015-10-13')
    pot5 = get_stock_history_by_date(stock, '2015-10-14')
    pot6 = get_stock_history_by_date(stock, '2015-10-15')

    if pot3 and pot4 and pot5 and pot6:
        if 'rong_all_balance' in pot6 and pot6['close'] != 0.0:
            if i(pot3['rong_all_balance']) > i(pot4['rong_all_balance']) > i(pot5['rong_all_balance']) > i(pot6['rong_all_balance']):
                r = str(rate(i(pot3['rong_all_balance']), i(pot6['rong_all_balance'])))[:5]
                print '{} {}'.format(stock, r)
Example #4
0
def find_rate():
    rank = []

    for stock in stocks:
        try:
            first_open = get_stock_history_by_date(stock, '2015-07-09')['low']
            last_close = get_stock_history_by_date(stock, '2015-07-24')['close']

            r = rate(last_close, first_open)
            rank.append((stock, r))
        except:
            continue

    ranked = sorted(rank, key=lambda r: r[1])
    for rn, rr in ranked:
        name = get_stock_name_from_mongo(rn)
        print u'{} {} {}'.format(name, rn, rr)
Example #5
0
def find_last_week_up_most():
    rank = []
    for stock in stocks:
        if not stock.startswith('002'):
            continue

        try:
            first_open = get_stock_history_by_date(stock, '2015-09-30')['close']
            last_close = get_stock_history_by_date(stock, '2015-11-06')['close']

            r = rate(last_close, first_open)
            rank.append((stock, r))
        except:
            continue

    ranked = sorted(rank, key=lambda r: r[1])
    for rn, rr in ranked:
        print u'{} {}'.format(rn, rr)
Example #6
0
def find():
    count = 0
    rank = []
    for stock in get_all_stock():
        price = get_stock_price(stock)

        # today, yesterday, current, high, low
        today = float(price[1])
        yesterday = float(price[2])
        current = float(price[3])
        high = float(price[4])
        low = float(price[5])
        volume = float(price[8])
        name = price[0].split('"')[-1]

        if today == '0.00':
            continue

        r = rate(current, yesterday)

        buy = int(price[10]) + int(price[12]) + int(price[14]) + int(price[16]) + int(price[18])
        sell = int(price[20]) + int(price[22]) + int(price[24]) + int(price[26]) + int(price[28])

        if sell == 0:
            bs = float(buy) / float(1)
        else:
            bs = float(buy) / float(sell)

        if volume > 0:
            buy_rate = buy / volume

        ###############

        if r > 9.9:
            count += 1
        else:
            if name.find(u'δΈ­') == 0:
                print u'{} {} {}'.format(stock, name, r)

    print count
Example #7
0
def get_rate():
    rate = util.rate()
    return json.dumps({'avg_rate': rate})
# poll_stats.py
# Jonah Smith
# Storytelling with Streaming Data, Spring 2016
#
# This file, in an infinite loop, uses the functions in the util file to
# calculate entropy and rate based on the state of the Redis db. It takes no
# input, and emits a JSON string with the entropy and rate to stdout. These
# messages are monitored by find-anomalies.py to, maybe not surprisingly, find
# anomalies.

import json
from sys import stdout
from time import sleep
# util has our functions for calculating the entropy and rate.
import util

# Repeat the entropy and rate calculations indefinitely.
while 1:
    # Use our utility functions to calculate entropy and rate.
    entropy = util.entropy()
    rate = util.rate()

    # Dump the entropy and rate to stdout and flush the stdout so we don't end
    # up with a buffer.
    print(json.dumps({'entropy': entropy, 'rate': rate}))
    stdout.flush()

    # Rest of one second. This will give us a nice smooth function for the rate
    # and entropy values.
    sleep(1)
Example #9
0
def get_rate():
    rate = util.rate()
    return json.dumps({"avg_rate": rate})