<commit_before>import React, { PureComponent } from 'react';
import { BinaryChart } from 'binary-charts';
import { isMobile, nowAsEpoch } from 'binary-utils';
import { helpers } from 'binary-live-api';
import { chartApi, api as CoreApi } from '../_data/LiveData';
import { chartToDataType, getDataWithErrorHandling } from '../_chart-utils/Utils';

type Props = {
    contract: Contract,
    pipSize: number,
};

export default class ContractChart extends PureComponent {

    static contextTypes = {
        theme: true,
    };

    props: Props;

    constructor(props: Props) {
        super(props);
        this.state = {
            chartType: 'area',
            dataType: 'ticks',
            ticks: [],
            candles: [],
            noData: false,
        };
        this.api = chartApi(0);
        this.hasTick = true;
        this.contractEnd = undefined;       // used to know when to unsubscribe
    }

    componentWillMount() {
        this.api.events.on('tick', data => {
            if (!this.hasTick) throw new Error('Not supposed to have tick stream!');

            this.ticksId = data.tick.id;            // problematic, sometimes it will both be ohlc stream, and screw u !!

            const old = this.state.ticks;
            const newTick = {
                epoch: +data.tick.epoch,
                quote: +data.tick.quote,
            };
            this.setState({ ticks: old.concat([newTick]) });
<commit_msg>Print contract when exception happens (#565)<commit_after>import React, { PureComponent } from 'react';
import { BinaryChart } from 'binary-charts';
import { isMobile, nowAsEpoch } from 'binary-utils';
import { helpers } from 'binary-live-api';
import { chartApi, api as CoreApi } from '../_data/LiveData';
import { chartToDataType, getDataWithErrorHandling } from '../_chart-utils/Utils';

type Props = {
    contract: Contract,
    pipSize: number,
};

export default class ContractChart extends PureComponent {

    static contextTypes = {
        theme: true,
    };

    props: Props;

    constructor(props: Props) {
        super(props);
        this.state = {
            chartType: 'area',
            dataType: 'ticks',
            ticks: [],
            candles: [],
            noData: false,
        };
        this.api = chartApi(0);
        this.hasTick = true;
        this.contractEnd = undefined;       // used to know when to unsubscribe
    }

    componentWillMount() {
        this.api.events.on('tick', data => {
            if (!this.hasTick) {
                this.api.events.ignoreAll('tick');
                const { contract } = this.props;
                throw new Error(`Not supposed to have tick stream! Contract: ${JSON.stringify(contract)}`);
            }

            this.ticksId = data.tick.id;            // problematic, sometimes it will both be ohlc stream, and screw u !!

            const old = this.state.ticks;
            const newTick = {
                epoch: +data.tick.epoch,
                quote: +data.tick.quote,
            };
            this.setState({ ticks: old.concat([newTick]) });

{'fraction_non_alphanumeric': 0.12139851084493364, 'fraction_numerical': 0.0016186468112657818, 'mean_word_length': 2.0116959064327484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3731537', 'n_tokens_mistral': 879, 'n_tokens_neox': 854, 'n_words': 231}