<commit_before>"use strict";

var util = require("util"),
    config = require("../util/config"),
    orderUtil = require("../util/order"),
    strategy = require("../strategy/dc");

module.exports = ontick;

var SETUP = {
    threshold: 0.003, // 0.3%
    units: 100,
    trailingStop: 20,

    lastFX: {
        "EUR_USD": {},
        "USD_JPY": {},
        "GBP_USD": {},
        "EUR_GBP": {},
        "EUR_JPY": {},
        "USD_CAD": {},
        "AUD_USD": {},
        "GBP_JPY": {}
    }
};

function ontick(tick) {
    var time = tick.time,
        instrument = tick.instrument,
        o = SETUP.lastFX[instrument],
        bid = tick.bid,
        ask = tick.ask,
        pip = config.pips[instrument],
        countDecimals = pip.split(".")[1].length,
        mid = ((bid + ask) / 2).toFixed(countDecimals),
        spread = ((ask - bid) / pip).toFixed(1),
        dc,
        side;

    if (!SETUP.lastFX.hasOwnProperty(instrument)) {
        return;
    }

    o.time = time;
    o.mid = mid;

    dc = strategy.directionalChange(o.mid, SETUP.threshold);
    o.trend = dc.trend;

    if (o.lastTrend === 1 && o.trend === -1) {
        side = "sell";
    }

    if (o.lastTrend === -1 && o.trend === 1) {
        side = "buy";
    }

    util.log(time, instrument, mid, spread, o.lastTrend, o.trend, side);

    o.lastTrend = o.trend;

    if (side && spread < 9) {
        orderUtil.fillOrder({
            instrument: instrument,
            type: "market",
            side: side,
            units: SETUP.units,
            trailingStop: SETUP.trailingStop
        }, function (err, trade) {
            if (!err) {
                util.log(trade.time, instrument, side, trade.price);
            } else {
                util.log(err);
            }
        });
    }
}<commit_msg>chore(ontick): pass instrument to strategy<commit_after>"use strict";

var util = require("util"),
    config = require("../util/config"),
    orderUtil = require("../util/order"),
    strategy = require("../strategy/dc");

module.exports = ontick;

var SETUP = {
    threshold: 0.003, // 0.3%
    units: 100,
    trailingStop: 20,

    lastFX: {
        "EUR_USD": {},
        "USD_JPY": {},
        "GBP_USD": {},
        "EUR_GBP": {},
        "EUR_JPY": {},
        "USD_CAD": {},
        "AUD_USD": {},
        "GBP_JPY": {}
    }
};

function ontick(tick) {
    var time = tick.time,
        instrument = tick.instrument,
        o = SETUP.lastFX[instrument],
        bid = tick.bid,
        ask = tick.ask,
        pip = config.pips[instrument],
        countDecimals = pip.split(".")[1].length,
        mid = ((bid + ask) / 2).toFixed(countDecimals),
        spread = ((ask - bid) / pip).toFixed(1),
        dc,
        side;

    if (!SETUP.lastFX.hasOwnProperty(instrument)) {
        return;
    }

    o.time = time;
    o.mid = mid;

    dc = strategy.directionalChange(instrument, o.mid, SETUP.threshold);
    o.trend = dc.trend;

    if (o.lastTrend === 1 && o.trend === -1) {
        side = "sell";
    }

    if (o.lastTrend === -1 && o.trend === 1) {
        side = "buy";
    }

    if (o.lastTrend !== 0) {
        util.log(time, instrument, mid, spread, o.lastTrend, o.trend);
    }

    o.lastTrend = o.trend;

    if (side && spread < 9) {
        orderUtil.fillOrder({
            instrument: instrument,
            type: "market",
            side: side,
            units: SETUP.units,
            trailingStop: SETUP.trailingStop
        }, function (err, trade) {
            if (!err) {
                util.log(trade.time, instrument, side, trade.price);
            } else {
                util.log(err);
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.1693020719738277, 'fraction_numerical': 0.010632497273718648, 'mean_word_length': 1.7097488921713442, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 3, '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': '1315915', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1235, 'n_words': 245}