Exemplo n.º 1
0
def main(input_file, instrument, granularity, title):
    db = get_database()
    candle_data = load_json(input_file)

    chart = _get_default_chart(instrument, granularity, title)

    candle_size = len(candle_data)

    max_candle_slice = 30000
    print(max_candle_slice, candle_size)
    if candle_size < max_candle_slice:
        chart['candles'] = candle_data
        db.candle_data.insert(chart)
    else:
        target_num_pieces = (candle_size / max_candle_slice) + 1
        for i in range(0, target_num_pieces):
            start_slice = max_candle_slice * i
            end_slice = start_slice + max_candle_slice
            chart['candles'] = candle_data[start_slice:end_slice]
            old_title = chart['title']['text']
            chart['title']['text'] = old_title + '_' + str(i)
            time.sleep(2)
            chart['_id'] = ObjectId()
            print('Start:', start_slice, 'End:', end_slice)
            db.candle_data.insert(chart)
Exemplo n.º 2
0
    def get(self):
        logging.info('AT CandleCharts GET Endpoint')
        db = get_database()
        charts = db.candle_data.find()
        charts = map(transform_son, charts)

        chart_data = {}

        try:
            for chart in charts:
                chart_id = chart['id']
                granularity = chart['granularity']
                candles = chart['candles']
                instrument = chart['instrument']
                start_date, end_date = find_chart_start_end_date(candles)

                num_candles = len(candles)
                chart_data[chart_id] = {
                    'instrument': instrument,
                    'granularity': granularity,
                    'num_candles': num_candles,
                    'start_date': start_date,
                    'end_date': end_date
                }
        except Exception as e:
            logging.error('E %s', e)
            traceback.print_exc(file=sys.stdout)
            return abort(status=500)

        return {'charts': chart_data}
Exemplo n.º 3
0
    def post(self):
        logging.info('At Candle POST Endpoint')
        request_data = request.get_json()
        candle = request_data.get('candle')
        pattern = request_data.get('pattern')
        hours_offset = request_data.get('hours_offset')
        chart_id = request_data.get('chart_id')

        db = get_database()

        try:
            chart_id = ObjectId(chart_id)
            chart_data = transform_son(db.candle_data.find_one({'_id': chart_id}))
            date_id_map = make_date_id_map(chart_data['candles'], hours_offset)
            target_candle = find_target_candle(candle, date_id_map)
            target_candle_id = target_candle['id']

            target_candle['pattern'] = pattern
            query = {'_id': chart_id, 'candles.id': target_candle_id}
            update = {'$set': {'candles.$': target_candle}}

            print(query, update)
            db.candle_data.update(query, update)

        except Exception as e:
            logging.error('E %s', e)
            traceback.print_exc(file=sys.stdout)
            return abort(status=500)

        return ok(202)
Exemplo n.º 4
0
    def get(self):
        print('CLASSIFIER ENDPOINT')
        db = get_database()
        query = {}
        projection = {'classifier': False}
        classifiers = transform_son(db.classifiers.find_one(query, projection))

        return {'classifiers': classifiers}
Exemplo n.º 5
0
    def get(self):
        print('STRATEGIES ENDPOINT')
        db = get_database()
        query = {}
        strategies = list(db.strategies.find(query))

        strategies = map(transform_son, strategies)

        return {'strategies': strategies}
Exemplo n.º 6
0
    def get(self):
        logging.info('At CandlePattern GET Endpoint')
        db = get_database()
        charts = db.candle_data.find()
        charts = map(transform_son, charts)

        marked_candles = find_marked_candles(charts)

        return {'candles': marked_candles}
Exemplo n.º 7
0
    def get(self):
        logging.info('At Candle GET Endpoint')
        try:
            db = get_database()

            chart_id = request.query_string.split('=')[1]
            chart_data = transform_son(db.candle_data.find_one({'_id': ObjectId(chart_id)}))
            title = chart_data['title']
            y_params = chart_data['y_params']
            x_params = chart_data['x_params']
            candles = chart_data['candles']
        except Exception as e:
            logging.info('E %s', e)
            traceback.print_exc(file=sys.stdout)
            return abort(status=500)

        return {'candles': candles, 'chart_id': chart_data['id'], 'title': title, 'y_params': y_params,
                'x_params': x_params}
Exemplo n.º 8
0
 def db(self):
     if self._db is None:
         self._db = get_database()
     return self._db
Exemplo n.º 9
0
Arquivo: base.py Projeto: everysum1/at
 def db(self):
     if self._db is None:
         self._db = get_database()
     return self._db
Exemplo n.º 10
0
    def get(self):
        print('Brokers ENDPOINT')
        db = get_database()
        strategies = list(db.brokers.find({}))

        return {'live_strategies': strategies}