<commit_before>/// <reference path="../common/models.ts" />
/// <reference path="../common/messaging.ts" />
/// <reference path="config.ts" />
/// <reference path="utils.ts" />

import Config = require("./config");
import Models = require("../common/models");
import Messaging = require("../common/messaging");
import Utils = require("./utils");
import Interfaces = require("./interfaces");
import Quoter = require("./quoter");
import Safety = require("./safety");

export class QuotingParametersRepository extends Interfaces.Repository<Models.QuotingParameters> {
    constructor(pub : Messaging.IPublish<Models.QuotingParameters>,
                rec : Messaging.IReceive<Models.QuotingParameters>) {
        super("qpr",
            (p : Models.QuotingParameters) => p.size > 0 || p.width > 0,
            (a : Models.QuotingParameters, b : Models.QuotingParameters) => Math.abs(a.width - b.width) > 1e-4 || Math.abs(a.size - b.size) > 1e-4 || a.mode !== b.mode,
            new Models.QuotingParameters(.5, .01, Models.QuotingMode.Top), rec, pub);

    }
}

export class ActiveRepository extends Interfaces.Repository<boolean> {
    constructor(private _safeties : Safety.SafetySettingsManager,
                pub : Messaging.IPublish<boolean>,
                rec : Messaging.IReceive<boolean>) {
        super("active",
            (p : boolean) => true,
            (a : boolean, b : boolean) => a !== b,
            false, rec, pub);
        _safeties.SafetySettingsViolated.on(() => this.updateParameters(false));
    }
}

class GeneratedQuote {
    constructor(public bidPx : number, public bidSz : number, public askPx : number, public askSz : number) {}
}

enum RecalcRequest { FairValue, Quote, TradingDecision }

// computes a quote based off my quoting parameters
export class QuoteGenerator {
    private _log : Utils.Logger = Utils.log("tribeca:qg");
    public latestFairValue : Models.FairValue = null;
    public latestQuote : Models.TwoSidedQuote = null;

    constructor(private _quoter : Quoter.Quoter,
                private _baseBroker : Interfaces.IBroker,
                private _broker : Interfaces.IMarketDataBroker,
                private _qlParamRepo : QuotingParametersRepository,
                private _safeties : Safety.SafetySettingsManager,
                private _quotePublisher : Messaging.IPublish<Models.TwoSidedQuote>,
                private _fvPublisher : Messaging.IPublish<Models.FairValue>,
                private _activeRepo : ActiveRepository) {
        _broker.MarketData.on(() => this.recalcMarkets(RecalcRequest.FairValue, _broker.currentBook.time));
        _qlParamRepo.NewParameters.on(() => this.recalcMarkets(RecalcRequest.Quote, Utils.date()));
        _quotePublisher.registerSnapshot(() => this.latestQuote === null ? [] : [this.latestQuote]);
        _fvPublisher.registerSnapshot(() => this.latestFairValue === null ? [] : [this.latestFairValue]);
        _activeRepo.NewParameters.on(() => this.recalcMarkets(RecalcRequest.TradingDecision, Utils.date()));
    }

    private filterMarket = (mkts : Models.MarketSide[], s : Models.Side) : Models.MarketSide[] => {
        var rgq = this._quoter.quotesSent(s);
        var rgq_len = rgq.length;

        var i = 0;
        var j = 0;
        while (true) {

        }

        var filteredMkts : Models.MarketSide[] = [];
        for (var i = 0; i < mkts.length; i++) {<commit_msg>Yikes<commit_after>/// <reference path="../common/models.ts" />
/// <reference path="../common/messaging.ts" />
/// <reference path="config.ts" />
/// <reference path="utils.ts" />

import Config = require("./config");
import Models = require("../common/models");
import Messaging = require("../common/messaging");
import Utils = require("./utils");
import Interfaces = require("./interfaces");
import Quoter = require("./quoter");
import Safety = require("./safety");

export class QuotingParametersRepository extends Interfaces.Repository<Models.QuotingParameters> {
    constructor(pub : Messaging.IPublish<Models.QuotingParameters>,
                rec : Messaging.IReceive<Models.QuotingParameters>) {
        super("qpr",
            (p : Models.QuotingParameters) => p.size > 0 || p.width > 0,
            (a : Models.QuotingParameters, b : Models.QuotingParameters) => Math.abs(a.width - b.width) > 1e-4 || Math.abs(a.size - b.size) > 1e-4 || a.mode !== b.mode,
            new Models.QuotingParameters(.5, .01, Models.QuotingMode.Top), rec, pub);

    }
}

export class ActiveRepository extends Interfaces.Repository<boolean> {
    constructor(private _safeties : Safety.SafetySettingsManager,
                pub : Messaging.IPublish<boolean>,
                rec : Messaging.IReceive<boolean>) {
        super("active",
            (p : boolean) => true,
            (a : boolean, b : boolean) => a !== b,
            false, rec, pub);
        _safeties.SafetySettingsViolated.on(() => this.updateParameters(false));
    }
}

class GeneratedQuote {
    constructor(public bidPx : number, public bidSz : number, public askPx : number, public askSz : number) {}
}

enum RecalcRequest { FairValue, Quote, TradingDecision }

// computes a quote based off my quoting parameters
export class QuoteGenerator {
    private _log : Utils.Logger = Utils.log("tribeca:qg");
    public latestFairValue : Models.FairValue = null;
    public latestQuote : Models.TwoSidedQuote = null;

    constructor(private _quoter : Quoter.Quoter,
                private _baseBroker : Interfaces.IBroker,
                private _broker : Interfaces.IMarketDataBroker,
                private _qlParamRepo : QuotingParametersRepository,
                private _safeties : Safety.SafetySettingsManager,
                private _quotePublisher : Messaging.IPublish<Models.TwoSidedQuote>,
                private _fvPublisher : Messaging.IPublish<Models.FairValue>,
                private _activeRepo : ActiveRepository) {
        _broker.MarketData.on(() => this.recalcMarkets(RecalcRequest.FairValue, _broker.currentBook.time));
        _qlParamRepo.NewParameters.on(() => this.recalcMarkets(RecalcRequest.Quote, Utils.date()));
        _quotePublisher.registerSnapshot(() => this.latestQuote === null ? [] : [this.latestQuote]);
        _fvPublisher.registerSnapshot(() => this.latestFairValue === null ? [] : [this.latestFairValue]);
        _activeRepo.NewParameters.on(() => this.recalcMarkets(RecalcRequest.TradingDecision, Utils.date()));
    }

    private filterMarket = (mkts : Models.MarketSide[], s : Models.Side) : Models.MarketSide[] => {
        var rgq = this._quoter.quotesSent(s);
        var rgq_len = rgq.length;

        var filteredMkts : Models.MarketSide[] = [];
        for (var i = 0; i < mkts.length; i++) {
{'fraction_non_alphanumeric': 0.13696590739913653, 'fraction_numerical': 0.003275271698675004, 'mean_word_length': 3.049427365883062, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 57, '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': '7285081', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1917, 'n_words': 402}