Exemple #1
0
def relation_US_BA(ticker, ticker_ba):
    tck_ba = Ticker(ticker_ba, begin=begin)
    tck = Ticker(ticker, begin=begin)

    tck.get_historical_price_data()
    tck_ba.get_historical_price_data()

    prices = {}
    for price in tck.historical_data['prices']:
        fd = price['formatted_date']
        prices[fd] = price

    prices_ba = {}
    for price in tck_ba.historical_data['prices']:
        fd = price['formatted_date']
        prices_ba[fd] = price

    rel = []
    for pk in prices_ba:
        if pk in prices:
            print({'date': pk, 'price_ba': prices_ba[pk]['adjclose'], 'price': prices[pk]['adjclose']})
            try:
                rel.append(prices[pk]['adjclose']/prices_ba[pk]['adjclose'])
            except Exception as e:
                print(e)


    rel = np.asarray(rel)

    return rel
Exemple #2
0
def test_01():
    tickers = ['^MERV', 'ALUA', 'BMA', 'BBAR', 'BYMA', 'CVH', 'CEPU', 'CRES', 'EDN', 'GGAL', 'VALO', 'SUPV',
               'MIRG', 'PAMP', 'COME', 'TECO2', 'TXAR', 'TRAN', 'TGNO4', 'TGSUD2', 'YPFD', 'TS', 'APBR']

    tickers = ['TEO', 'DESP', 'MELI', 'GLOB', 'BMA', 'BBAR', 'SUPV', 'GGAL', 'TS',
               'TX', 'PAM', 'EDN', 'CEPU', 'YPF', 'PBR', 'TGS', 'LOMA', 'IRS', 'CRESY']

    BA = False

    for ticker in tickers:
        try:
            if BA == True:
                tck = Ticker(ticker + '.BA', begin=begin)
            else:
                tck = Ticker(ticker, begin=begin)

            a, b, c = tck.get_boll()
            tck.get_ma_close()
            tck.get_volume()
            vol = tck.get_volatility(len_ma=20)
            print(ticker, vol.mean())
            print(tck.get_status_ma())
        except Exception as e:
            print(ticker, 'ERROR', e)

    plt.plot(vol)
    plt.show()
Exemple #3
0
	def docMappings(self, connection, indexName=DEFAULT_INDEX): 
		try: 
			connection.indices.put_mapping(index=indexName, doc_type="orderbook", body=Orderbook().orderbookMapping)
			connection.indices.put_mapping(index=indexName, doc_type="ticker", body=Ticker().tickerMapping)
			connection.indices.put_mapping(index=indexName, doc_type="completed_trades", body=Trade().completedTradeMapping)
			connection.indices.put_mapping(index=indexName, doc_type="future_ticker", body=Ticker().futureTickerMapping)
			connection.indices.put_mapping(index=indexName, doc_type="future_price_index", body=FutureIndex().futurePriceIndexMapping) 
			connection.indices.put_mapping(index=indexName, doc_type="kline_candles", body=KlineCandle().klineMapping) 
		except: 
			raise 
		pass
Exemple #4
0
    def __init__(self, zoomFactor=1.05, zoomMargin=.1, dynamicRange=1e9):
        QtWidgets.QWidget.__init__(self)
        self.zoomMargin = zoomMargin
        self.dynamicRange = dynamicRange
        self.zoomFactor = zoomFactor

        self.ticker = Ticker()

        self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
        action = QtWidgets.QAction("V&iew range", self)
        action.setShortcut(QtGui.QKeySequence("CTRL+i"))
        action.setShortcutContext(QtCore.Qt.WidgetShortcut)
        action.triggered.connect(self.viewRange)
        self.addAction(action)
        action = QtWidgets.QAction("Sna&p range", self)
        action.setShortcut(QtGui.QKeySequence("CTRL+p"))
        action.setShortcutContext(QtCore.Qt.WidgetShortcut)
        action.triggered.connect(self.snapRange)
        self.addAction(action)

        qfm = QtGui.QFontMetrics(self.font())
        self._labelSize = QtCore.QSize(
            (self.ticker.precision + 5) * qfm.averageCharWidth(),
            qfm.lineSpacing())

        self._start, self._stop, self._num = None, None, None
        self._axisView = None
        self._offset, self._drag, self._rubber = None, None, None
def process(sub,sort,num):
    curr = main.readSub(sub,sort,num)
    dictionary = {}
    count = 0
    for element in curr:
        tokenize= word_tokenize(element)
        count = 0
        mentions = []
        for item in tokenize:
            if(len(item) > 1 and binarySearch(symbols,item, 0, None) > 0):
                if(item in dictionary):
                    dictionary[item].mentions+=1
                    if(item not in mentions):
                        mentions.append(item)
                else: 
                    dictionary[item] = Ticker(item,1,0)
            elif item in keypos:
                count +=1
            elif item in keyneg:
                count -=1 
        for stuff in mentions:
            if(count>0):
                dictionary[stuff].sentiment+=1
            elif(count <0):
                dictionary[stuff].sentiment-=1
    dictionarySort = OrderedDict(sorted(dictionary.items(), key=lambda i: i[1].mentions, reverse = True))
    return dictionarySort
def findCollision(originalDigest, fileName, zeros=9, bytesQty=1):
    topNumber = getZeroQty(zeros)

    originalFragment = originalDigest[0]

    tick = Ticker()
    end = 0
    attempts = 0

    found = False

    while not found:
        attempts += 1

        number = random.randint(0, topNumber)
        byteNum, digest, fragment = buildData(number)

        if qtyBytesOfCollition(originalDigest, digest, bytesQty):
            found = True
            bFile = struct.pack('q', 0)
            bNumber = struct.pack('q', number)

            end = tick()

            printInfo(originalDigest, bFile, fileName, 'FRAGMENTO A ENCONTRAR',
                      False)
            printInfo(digest, bNumber, number, 'COLISION PARCIAL')
            print('Colisión de', bytesQty, 'byte(s)')
            print("\n> Intentos:", attempts)
            print('> Tiempo: %s seg.' % round(end, 4))
            print('> Collision rate: %s c/s' % round(attempts / end, 4))

            break

    return attempts, round(end, 4), round(attempts / end, 4)
Exemple #7
0
def collect_data_again(batch_id, faults):

    for i, ticker in enumerate(faults):

        try:

            retries = {
                key: key in faults[ticker]
                for key in ['analysis', 'keystats', 'ohlc', 'options'][:2]
            }

            ticker_obj = Ticker(ticker, logger, batch_id, retries,
                                faults[ticker])
            faults[ticker] = ticker_obj.fault_dict
            time.sleep(SLEEP)

            logger.info(f"{ticker},{batch_id},Re-Ticker,Success,")

        except Exception as e:

            logger.warning(f"{ticker},{batch_id},Re-Ticker,Failure,{e}")

        pct = (i + 1) / len(faults)
        pct = np.round(100 * pct, 4)
        logger.info(f"SCRAPER,{batch_id},RE-PROGRESS,{pct}%,")

    return faults
Exemple #8
0
def transform_images(image_sequence,
                     processors_num=None,
                     use_shared_memory=False):

    ticker = Ticker()

    image_sequence["enhanced"] = ('i',
                                  rescale_intensity(
                                      image_sequence["enhanced"][1].astype(
                                          np.double)))
    image_sequence["skeletons"] = ('i',
                                   (image_sequence["skeletons"][1] > 0).astype(
                                       np.uint8))

    ticker.tick("\nTransforming images...")
    transform = ParallelMap(processors_num)
    image_sequence["binaries"] = ('i',
                                  transform.map(transform_binary,
                                                image_sequence["binaries"][1]))
    image_sequence["branching"] = ('i',
                                   transform.map(
                                       transform_distance,
                                       image_sequence["branching"][1]))
    ticker.tock(" Finished.")

    if use_shared_memory:
        ticker.tick("\nMapping to shared memory...")
        image_sequence_shared = to_shared_memory(image_sequence)
        ticker.tock(" Finished.")
        # Return shared memory
        return image_sequence_shared

    return image_sequence
Exemple #9
0
    def test_display_routine(self, mock_get_config, mock_viewer, mock_joke,
                             mock_coin, mock_details, mock_logo):

        mock_get_config.return_value = {
            'ticker': {
                'tell_jokes': True,
                'crypto': 'btc',
                'vs_currency': 'usd'
            }
        }
        mock_joke.return_value = "FUNNY!"
        mock_coin.return_value = {
            'name': 'Bitcoin',
            'id': 'btc',
            'symbol': 'btc',
            'logo': 'bitcoin_file.jpg'
        }
        mock_logo.return_value = 'bitcoin_file.jpg'
        mock_details.return_value = '$31,000, +10.20%'

        # Don't want to wait on sleep in tests
        time.sleep = mock.MagicMock()
        t = Ticker()
        t.crypto = Crypto()
        t.load_config()
        print(t.config)
        t.display_routine()

        calls = [mock.call('BITCOIN', MessageType.FALLING, 'bitcoin_file.jpg')]
        for j in range(0, 3):
            calls.append(
                mock.call('$31,000, +10.20%',
                          MessageType.BOUNCING,
                          'bitcoin_file.jpg',
                          delay=30))

        calls.append(mock.call('JOKE TIME', MessageType.FALLING, delay=25))
        calls.append(mock.call('FUNNY!', MessageType.SCROLLING))

        t.viewer.display_message.assert_has_calls(calls)

        mock_details.side_effect = ConnectionError()
        t.display_routine()
        t.viewer.display_message.assert_called_with(
            "Error connecting to Price API", MessageType.SCROLLING)

        mock_details.side_effect = None
        mock_joke.side_effect = ConnectionError()
        t.display_routine()
        t.viewer.display_message.assert_called_with(
            "Error connecting to Joke API", MessageType.SCROLLING)

        mock_joke.side_effect = Exception()
        t.display_routine()
        t.viewer.display_message.assert_called_with(
            "Encountered an Unknown Error", MessageType.SCROLLING)
Exemple #10
0
 def addTicker(self, ticker, bought=0, price=0):
     data = yf.download(ticker, period="1d", group_by='ticker')
     if data.empty:
         print("bad ticker")
     else:
         self.tickers.append(
             Ticker(ticker,
                    price=round(data['Close'][0], 2),
                    bought=bought,
                    boughtPrice=price))
Exemple #11
0
def track_individual(input):

    # Initialize global variables
    global Global_Sequence
    global Global_Parameters
    global Global_Lock
    global Output_Folder

    # Initialize ticker
    ticker = Ticker(Global_Lock)

    # Unpack data
    index, data = input
    filename, initial_polyline = data

    ticker.tick(" Started tracking {0}.".format(filename))

    # Reparametrize contour
    new_x, new_y, new_step = reparametrize(initial_polyline[:, 0],
                                           initial_polyline[:, 1],
                                           Global_Parameters.delta, 'linear')

    initial_points = np.dstack([new_x, new_y])[0]
    tracking_result = None

    try:
        # Create tracker
        tracker = Tracker(Global_Sequence, Global_Parameters)

        # Initialize log
        log = ""
        result = tracker.track(initial_points, log)

        ticker.tock("  Finished: " + filename)

        if result is not None:
            if Global_Lock is not None:
                Global_Lock.acquire()
            try:
                zip_path = os.path.join(Output_Folder,
                                        '{0}.zip'.format(filename))
                # Save ZIP
                zip_csv(zip_path, result["snake_trajectory"][:, -1])
            except:
                pass
            if Global_Lock is not None:
                Global_Lock.release()
    except Exception as e:
        print e
        traceback.print_exc()
        ticker.tock("  Failed: " + filename)

    return tracking_result
def run_tracker(): 
    ''' Runs stock tracker with Submissions and ticker instances ''' 
    subreddit = Submissions('pennystocks') 
    stock = Ticker()
    for submission in subreddit.subred.new(limit=1000): 
        stock_iter = stock.find_ticker(subreddit.retrieve_submission('title', submission))
        if stock_iter != False:
            count[stock_iter] += 1
        else:
            continue 
    
    print ('Most common:')
    for company, cnt in count.most_common(5):
        print ('%s: %7d' % (company,cnt))
Exemple #13
0
    def on_execute(self):
        if self.on_init() == False:
            self._running = False

        pygame.mixer.init()
        pygame.mixer.music.load(
            os.path.join(os.path.dirname(__file__), "..\sound\\Pixelland.wav"))

        pygame.mixer.music.play(-1)

        tmx_loader = TmxLoader()
        map = tmx_loader.load_map("game_map")

        sprite_handler = SpriteHandler()
        entity_handler = EntityHandler(tmx_loader)
        map = Map(map)
        player = Player(Location.Spawn, ID.Player, "Engineer",
                        Sprite_ID.Player_d4, map)
        inv = Inv(None)
        entity_handler.add_entity(player)

        renderer = Renderer(entity_handler, sprite_handler, self._display_surf)
        ticker = Ticker(entity_handler, self, inv)

        time_next_tick = 0
        time_next_render = 0
        tick = 0
        render = 0
        nextsecond = 0
        while (self._running):
            time_now = pygame.time.get_ticks()

            if (time_now > time_next_tick):
                ticker.tick()
                time_next_tick = time_now + 1000 / self.tps
                tick += 1

            if (time_now > time_next_render):
                renderer.render(entity_handler, map, inv)
                time_next_render = time_now + 1000 / self.fps
                render += 1

            if (nextsecond < time_now):
                print("TPS: " + str(tick) + " FPS: " + str(render))
                tick, render = 0, 0
                nextsecond = time_now + 1000

        self.on_cleanup()
Exemple #14
0
    def test_load_config(self, mock_get_config, mock_viewer, mock_crypto):
        # Don't want to wait on sleep in tests
        time.sleep = mock.MagicMock()
        t = Ticker()

        mock_get_config.return_value = "CONFIG!"
        t.load_config()
        self.assertEqual(t.config, 'CONFIG!')

        mock_get_config.side_effect = Exception()
        t.load_config()
        t.viewer.display_message.assert_called_with("Could not load config :(",
                                                    MessageType.STATIC)

        mock_get_config.side_effect = FileNotFoundError()
        t.load_config()
        t.viewer.display_message.assert_called_with("Config file not found.",
                                                    MessageType.STATIC)
Exemple #15
0
def collect_data(batch_id, tickers):

    for i, ticker in enumerate(tickers):

        try:

            Ticker(ticker, logger, batch_id)
            time.sleep(SLEEP)

            logger.info(f"{ticker},{batch_id},Ticker,Success,")

        except Exception as e:

            logger.warning(f"{ticker},{batch_id},Ticker,Failure,{e}")

        pct = (i + 1) / len(tickers)
        pct = np.round(100 * pct, 4)
        logger.info(f"SCRAPER,{batch_id},PROGRESS,{pct}%,")
Exemple #16
0
    def get_ticker_cotation(self, coin: str) -> Ticker:

        try:
            url = "/".join((self.base_url, self.request_path, coin, 'ticker'))
            response = requests.get(url)

            if response.status_code not in range(200, 299):
                self.logger.error(
                    "Ticker request not in range between 200 and 299")
                raise Exception(
                    "Ticker request not in range between 200 and 299")

            results = response.json()['ticker']

            return Ticker(results)

        except Exception as e:
            self.logger.error(e)
            raise
Exemple #17
0
    def __init__(self, config, core):
        super(LCDFrontend, self).__init__()

        self.lcd = RPi_I2C_driver.lcd()

        if config['lcd']['display_temperature']:
            bus = SMBus(config['lcd']['bme280_i2c_bus'])
            self.bme280 = BME280(i2c_dev=bus)
        else:
            self.bme280 = None

        self.ticker = Ticker(self.actor_ref, LCDFrontend.TICK_INTERVAL)
        self.ticker.start()

        self.stream_title = ""
        self.st_pos = 0
        self.lifetime = 0
        self.lcd_on = True
        self.volume = 0
Exemple #18
0
def upload_sequence(path, processors_num=None, use_shared_memory=False):

    filenames = [
        'enhanced.tif',
        'skeletons.tif',
        'binaries.tif',
        'branching.tif',  # check if we really need this one
        'gvf_magnitude.tif',
        'gvf_angle.tif',
        'branching_coords.zip'
    ]

    ticker = Ticker()

    ticker.tick("\nLoading image sequence...")
    image_sequence = ImageSequence.load(path, filenames)
    ticker.tock(" Finished.")

    return transform_images(image_sequence, processors_num, use_shared_memory)
Exemple #19
0
def main():
    bot = commands.Bot(command_prefix=commands.when_mentioned_or("!!"))

    env = os.getenv("BENSONBOT_ENV_TYPE")
    if env.upper() == "MAIN":
        from duty_manager import DutyManager
        from memeail import ProblemOfTheDay
        from shitposter import Shitposter
        from ticker import Ticker
        from timers import CSE107Timer, CSE113Timer
        from message_scheduler import MessageScheduler

        bot.add_cog(CSE113Timer(bot))
        bot.add_cog(CSE107Timer(bot))
        bot.add_cog(DutyManager(bot))
        bot.add_cog(MessageScheduler(bot))

        bot.add_cog(ProblemOfTheDay(bot))

        bot.add_cog(Shitposter(bot))
        bot.add_cog(Ticker(bot))

    elif env.upper() == "PLAYGROUND":
        from playground import Playground

        bot.add_cog(Playground(bot))

    elif env.upper() == "TESTING":
        from scoreboard import Scoreboard
        from shitposter import Shitposter

        bot.add_cog(Scoreboard(bot))
        bot.add_cog(Shitposter(bot))

    else:
        print("Unknown environment ({})".format(env))
        return

    print("Starting with env {}".format(env))
    bot.run(os.getenv("BENSONBOT_DISCORD_TOKEN"))
def selectChannel(name):
    global ticker
    import uwebsockets.client as uwc
    lcd.clear()
    lcd.text(lcd.CENTER, 40, 'joining')
    lcd.text(lcd.CENTER, 60, 'chat')
    lcd.font(lcd.FONT_UNICODE)
    if tcfg['tickers']:
        ticker = Ticker([''] * 9,
                        0xffffff,
                        rotation=0,
                        sliding=False,
                        speed=16,
                        delay=10,
                        x=2,
                        multiline=True)

    exitChat = False
    with uwc.connect('wss://irc-ws.chat.twitch.tv') as ws:
        ws.send('NICK justinfan123')
        #ws.send('CAP REQ :twitch.tv/tags')
        ws.send('JOIN  #' + name)
        msg = ws.recv()
        i = 0
        while msg.find('/NAMES') == -1:
            msg = ws.recv()
        msg = ws.recv()
        while not exitChat:
            if msg != '':
                #gc.collect()
                parseChatMsg(msg)
            msg = ws.recv()
            while btnB.isPressed():
                exitChat = True
        if tcfg['tickers']:
            ticker.stop()
            del ticker
    return mainMenu
Exemple #21
0
    def test_setup_connection(self, setup_wifi, mock_has_internet_connection,
                              mock_viewer):
        mock_has_internet_connection.return_value = True
        t = Ticker()
        t.setup_connection()

        setup_wifi.assert_not_called()

        mock_has_internet_connection.return_value = False
        setup_wifi.return_value = "DID IT BOYS"

        t.setup_connection()
        setup_call = mock.call("SETUP", MessageType.STATIC)
        connect_call = mock.call("Successfully connected to DID IT BOYS",
                                 MessageType.SCROLLING)
        t.viewer.display_message.assert_has_calls([setup_call, connect_call])
        setup_wifi.assert_called()

        setup_wifi.side_effect = [Exception(), "DID IT BOYS"]
        t.setup_connection()
        error_call = mock.call("Error connecting to Wi-Fi. Please try again.",
                               MessageType.SCROLLING)
        t.viewer.display_message.assert_has_calls([setup_call, error_call])
Exemple #22
0
    def __init__(self):
        """
        Set up the IOManager thread and start it.
        """

        super(_IOManager, self).__init__()
        self.__poll = iopoll.IOPoll()
        self.__et = self.__poll.set_edge_triggered(True)
        self.__wrappers = {}
        self.__disconnected_wrappers = []
        self.__running = True

        self.__wrapper_lock = threading.RLock()
        self.__poll_lock = threading.RLock()
        self.__logger = logging.getLogger('Borg.Brain.Util.IOManager')
        self.__logger.addHandler(nullhandler.NullHandler())
        self.__empty_time = time.time() + 10
        self.__next_tick = time.time() + 0.1
        self.__parent_thread = threading.current_thread()

        self.__read_list = set([])
        self.__write_list = set([])

        self.__ticker = Ticker(10)
        self.__saved_time = 0

        # Set up wake up pipe in non-blocking mode
        self.__wakeup_read, self.__wakeup_write = os.pipe()
        fl = fcntl.fcntl(self.__wakeup_read, fcntl.F_GETFL)
        fcntl.fcntl(self.__wakeup_read, fcntl.F_SETFL, fl | os.O_NONBLOCK)
        fl = fcntl.fcntl(self.__wakeup_write, fcntl.F_GETFL)
        fcntl.fcntl(self.__wakeup_write, fcntl.F_SETFL, fl | os.O_NONBLOCK)
        self.__poll.register(self.__wakeup_read, True, False, True)

        # Start IOManager thread
        self.start()
            print "Loading %s..." % filename
            img = cv.LoadImage(filename)
            images.append(img)

        print "Loaded %d images" % len(images)

    # Start the BinarySocket
    comp = True if not server else False
    sock = BinarySocket(host,
                        port,
                        server=server,
                        bufsize=1024 * 256,
                        compress=comp,
                        compress_level=9)
    client = sock if not server else None
    ticker = Ticker(5)

    # Keep running until user interrupts
    while True:
        ticker.tick()
        if not client:
            client = sock.wait_connect(0.5)

        if not client:
            continue

        if not client.connected() and server:
            # If a client disconnected, wait for a new connection
            client = None
            continue
Exemple #24
0
import director
import database
import numpy
from ticker import Ticker
import trader
import time
sortedDict = director.process("stocks", "hot", 50)
database.uploadData(sortedDict, "stocks", "10-20")
tickers = []
symbols = list(sortedDict.keys())
mentions = [a.mentions for a in sortedDict.values()]
sentiment = [a.sentiment for a in sortedDict.values()]
for i in range(len(symbols)):
    tickers.append(Ticker(str(symbols[i]), mentions[i], sentiment[i]))
stdMentions = numpy.std(mentions)
stdSentiment = numpy.std(sentiment)
sum = 0
for i in mentions:
    sum += i
avg1 = sum / len(mentions)
sum = 0
for i in sentiment:
    sum += i
avg2 = sum / len(sentiment)
for tick in tickers:
    z1 = (tick.mentions - avg1) / stdMentions
    z2 = (tick.sentiment - avg2) / stdSentiment
    tick.setZScore((z1 + z2) / 2)
tickers.sort(key=lambda x: x.zscore, reverse=True)
staged = []
for i in range(len(symbols)):
Exemple #25
0
import sys
import os
import numpy as np

dir_base = os.path.abspath('../')
sys.path.append(dir_base)

from ticker import Ticker

from matplotlib import pyplot as plt

if __name__ == '__main__':
    tck = Ticker('YPF')
    a, b, c = tck.get_boll()
    tck.get_close()
    tck.get_volume()
    vol = tck.get_volatility()
    tck.get_ma_close()
    print(vol.mean())
    print(tck.get_status_ma())
    vol_osc = tck.get_vol_osc()
    # http://pyhogs.github.io/plot-aspect-ratio.html
    plt.figure(figsize=(12.5, 3))
    plt.bar(np.arange(vol_osc.size), vol_osc)
    plt.plot(vol_osc)
    plt.show()

    a, b, c = tck.get_lineal_macd()

    plt.figure(figsize=(12.5, 3))
    plt.plot(a[30:])
import sys
import time

from poloniex import Poloniex
import requests
from ticker import Ticker

config_path = '../../config/config.ini'

logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

if __name__ == '__main__':
    config = configparser.ConfigParser()
    config.read(config_path)

    api = config['poloniex']['api']
    secret = config['poloniex']['secret']

    polo = Poloniex()

    ticker = Ticker('mongodb://192.168.1.179:27017/')

    while (True):
        print(
            ticker('BTC_STR')['last'],
            polo.returnTicker()['BTC_STR']['last'])

        time.sleep(1)
Exemple #27
0
    def initializeData(self, fileName):
        """Loads and initializes data from a csv file.

        Args:
            filename: The csv data file
        """

        fileCopy = []

        # Printing out each row in order to show what is there
        with open(fileName, 'rU') as csvfile:
            reader = csv.reader(csvfile, delimiter=',', dialect=csv.excel_tab)
            for row in reader:
                fileCopy.append(row)

        csvfile.close()

        tickerNamesCounter = 0

        # Isolate the ticker names into the tickerNames list
        for x in fileCopy[0]:
            if x == '':
                pass
            else:
                self.tickerNames.append(x)

        print "The tickers that you have listed within your file include:"
        for x in self.tickerNames:
            print x

        # Associate performance data with each ticker via a dictionary
        # Dictionary will map datetime objects (for the date) to floats (for performance)

        # enumerate gives you an index value for each ticker in tickerNames, so we can know both
        #   the index and name of the ticker
        for index, ticker in enumerate(self.tickerNames):
            # a temporary map to hold a ticker's date/performance data
            performance_data_dict = {}

            # For each ticker, we go through the file checking the appropriate columns
            # You'll notice that corresponding columns of data for each ticker in the tickerNames list
            # is just
            #   Date: 3*(index of ticker name in tickerNames)
            #   Performance: 3*(index of ticker name in tickerNames) + 1
            #
            # Math is a beautiful thing
            for line in fileCopy[2:]:
                date_string = line[3 * index]
                if date_string == '':
                    continue
                #create a datetime object out of the datestring in the csv file
                date = datetime.strptime(date_string, '%m/%d/%y')
                performance = float(line[3 * index + 1])

                # add the date and performance to the dictionary
                performance_data_dict[date] = performance

            # create a new ticker object, and store it in the tickerObjects dictionary which maps
            # ticker names (which are strings) to ticker objects (which are instances of the Ticker class)
            ticker_obj = Ticker(ticker, performance_data_dict)
            self.tickerObjects[ticker] = ticker_obj
Exemple #28
0
def main():

    ticker = Ticker()
    ticker.tick("Started filament generation...")

    input_dir = os.path.join("..", "..", "output", "preprocessing")
    output_dir = os.path.join("..", "..", "output", "generator")

    # Read configuration
    common_config = Config(os.path.join("..", "..", "config", "common.config"))

    # Read filaments generator configuration
    generator_config = Config(
        os.path.join("..", "..", "config", "generator.config"))

    folder_name = common_config["Output"]["Folder"]
    sequence_path = os.path.join(common_config["Image Sequence"]["Path"],
                                 common_config["Image Sequence"]["Filename"])

    # Generate filaments
    filaments_original, filaments_filtered = generator.generate(
        input_dir, folder_name, generator_config)

    directory = os.path.join(output_dir, folder_name)
    # Make folder
    try:
        os.mkdir(directory)
    except:
        pass

    # Output path
    current_date = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
    output_path = os.path.join(
        directory, "__".join([current_date,
                              str(len(filaments_filtered))]))

    try:
        os.mkdir(output_path)
    except:
        pass

    # Get colors
    colors = get_random_colors(len(filaments_filtered))

    # Get background image
    image_sequence = imread(sequence_path)

    background = np.squeeze(image_sequence)[0].astype(np.float32)
    background /= background.max()

    # Save filaments
    save_filaments(filaments_filtered, output_path, background, colors)

    # Plot sequence
    if __PLOT_OVERLAY__:
        plot_filaments(filaments_original, background, None,
                       "Original filaments")
        plot_filaments(filaments_filtered, background, colors,
                       "Filtered filaments", True)

    ticker.tock(" Generation finished.")
Exemple #29
0
	def consumer(self, marketData): 
		connection = elasticsearch.Elasticsearch(self.esHost) 
		self.ensure(connection) 
		self.docMappings(connection) 
		dataSet = json.loads(marketData) 
		item = {}
		for infoPoint in dataSet: 
			try: 
				channel = str(infoPoint["channel"])
				regex = "ok_sub_(spotusd|futureusd)_(b|l)tc_(.[A-Za-z0-9_]+)"
				search = re.search(regex, channel) 
				if search.group(1) == "futureusd": 
					isFuture = True
				else: 
					isFuture = False 
				currencyPair = str(search.group(2)) + "tc_usd"
				self.count = self.count + 1
				if self.count % 100 == 0: 
					print ("PROCESSED " + str(self.count) + " DATA POINTS SO FAR...") 
				if search.group(3) == "index": 
					myindex = FutureIndex()
					dto = myindex.getFutureIndexDto(infoPoint, currencyPair)
					dto["exchange"] = "OKCOIN"
					self.postDto(dto, connection, "future_price_index")
				elif "depth" in channel: 
					mybook = Orderbook()
					dto = mybook.getDepthDtoList(infoPoint, currencyPair, isFuture)
					for item in dto: 
						item["websocket_name"] = channel
						item["is_future"] = isFuture
						if isFuture == True: 
							check = re.search("depth_(this_week|next_week|quarter)_(20|60)", search.group(3).strip())
							item["contract_type"] = str(check.group(1))
							item["depth"] = str(check.group(2))
						else: 
							item["contract_type"] = "spot"
							depthSearch = re.search("depth_(20|60)", search.group(3).strip()) 
							item["depth"] = depthSearch.group(1) 
						item["exchange"] = "OKCOIN"	
						self.postDto(item, connection, "orderbook")
				elif "ticker" in channel and "data" in infoPoint: 
					myticker = Ticker() 
					if isFuture == False: 
						dto = myticker.getTickerDto(infoPoint, currencyPair) 
						self.postDto(dto, connection, "ticker")
					elif isFuture == True: 
						dto = myticker.getFutureTickerDto(infoPoint, channel, currencyPair)
						dto["exchange"] = "OKCOIN"
						self.postDto(dto, connection, "future_ticker") 
				elif "trade" in channel: 
					mytrade = Trade() 
					if "data" in infoPoint: 
						dtoList = mytrade.getCompletedTradeDtoList(infoPoint, currencyPair)
						for item in dtoList: 
							item["is_future"] = "futureusd" in channel
							item["websocket_name"] = channel 	
							item["exchange"] = "OKCOIN" 	
							self.postDto(item, connection, "completed_trades") 
				elif "kline" in channel: 
					myklein = KlineCandle() 
					if "data" in infoPoint: 
						if len(infoPoint["data"]) > 1: 
							for klineData in infoPoint["data"]: 
								if type(klineData) is list: 
									klineDto = myklein.getKlineDto(klineData, currencyPair, channel) 
									klineDto["exchange"] = "OKCOIN" 
									klineDto["is_future"] = isFuture 
									klineDto["websocket_name"] = channel
								else: 
									klineDto = myklein.getKlineDto(infoPoint["data"], currencyPair, channel) 
							self.postDto(klineDto, connection, "kline_candles")
			except: 
				raise
Exemple #30
0
def main():

    # Read configuration
    common_config = Config(os.path.join('..', '..', 'config', 'common.config'))

    # Read image preprocessing configuration
    tracker_config = Config(
        os.path.join('..', '..', 'config', 'tracker.config'))

    # Get output folder
    output_folder = common_config['Output']['Folder']

    # Use multiprocessing
    is_parallel = tracker_config['Parallel Computing']['Enabled_b']

    # Read preprocessed data
    image_sequence = upload_sequence(os.path.join('..', '..', 'output',
                                                  'preprocessing',
                                                  output_folder),
                                     use_shared_memory=is_parallel)

    try:
        init_path = tracker_config['Initialization']['Path']
        if init_path == '':
            raise Exception("Empty Path")
    except:
        sequence_path = os.path.join('../../output/generator', output_folder)
        try:
            input_folder = get_latest_folder(sequence_path)
            init_path = os.path.join(sequence_path, input_folder,
                                     "filaments.zip")
        except:
            return

    ticker = Ticker()
    ticker.tick("\nReading initial filaments...")
    initialization = upload_initialization(init_path)
    ticker.tock(" Finished.")

    sequence_output = os.path.join("../../output/tracking", output_folder)
    try:
        os.mkdir(sequence_output)
    except:
        pass

    run_output = os.path.join(sequence_output,
                              datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
    try:
        os.mkdir(run_output)
    except:
        pass

    try:
        shutil.copy2(os.path.join(sequence_path, input_folder, 'colors.csv'),
                     run_output)
    except:
        pass

    # Track all filaments
    ticker.tick("\nStarting tracking...")
    track_all(initialization, image_sequence, tracker_config, run_output)
    ticker.tock(" Tracking completed!")