Esempio n. 1
0
 static void stopProcesses(string key)
 {
     O.each(O.copy(processes.get(key)), process => {
         if (!process.HasExited)
         {
             LogC.info("killing pid " + process.Id);
             process.Kill();
         }
         processes.get(key).Remove(process);
     });
     LogC.info("all processes killed for " + key);
 }
Esempio n. 2
0
        void populateSlippageCache(Symbol symbol)
        {
            var manager    = new SpudManager();
            var bars       = bars_[symbol];
            var spud       = new BarSpud(manager);
            var calculator = symbol.slippageCalculator(spud);

            each(sort(bars.Keys), date => {
                spud.set(bars[date]);
                slippageCache.get(date)[symbol] = calculator.slippage();
                manager.newBar();
            });
        }
Esempio n. 3
0
 void addTrade(Position position, Trade trade)
 {
     if (position.isEntry(trade))
     {
         positions.Add(position);
         positionsInfo.add(position);
         Action <Bar> onNewBar = bar => positionsInfo.get(position).add(simulator.pnlForPosition(position, 0.0));
         simulator.addNewBarListener(position.symbol, onNewBar);
         position.onPositionClosed += () => {
             simulator.removeNewBarListener(position.symbol, onNewBar);
             positionsInfo.get(position).add(position.pnl(true, simulator.runInNativeCurrency()));
         };
     }
     trades.Add(trade);
 }
Esempio n. 4
0
 void nextBar(DateTime date, Dictionary <Symbol, Bar> current, bool isLive)
 {
     trades.Clear();
     if (!isLive)    // in live mode, we have already filled orders for the bar we just went through (in the tick processing logic)
     {
         bridge.setCurrentSlippage(data.currentSlippages(date));
         LogC.info("filling orders for bar: " + ymdHuman(date));
         fillOrders(current);
     }
     LogC.info("calling onNewBar for bar: " + ymdHuman(date));
     bridge.processBar(current);
     processBarComplete();
     each(current, (symbol, bar) => { var action = newBarListeners.get(symbol); action(bar); });
     dateIndex++;
 }
Esempio n. 5
0
 public LiveWatcher(WatcherGui gui)
 {
     this.gui = gui;
     table    = new QDataTable {
         { "tag", typeof(string) },
         { "symbol", typeof(string) },
         { "tomahawk", typeof(double) },
         { "aim", typeof(double) },
         { "diff", typeof(double) },
         { "symbolHIDDEN", typeof(Symbol) }
     };
     table.filter(row => {
         var visible = true;
         if (filterZeroes)
         {
             visible = (double)row["aim"] != 0 || (double)row["tomahawk"] != 0;
         }
         if (!showHidden_)
         {
             visible &= !isExcludedByTag.get((string)row["tag"]);
         }
         if (!tagFilter.Equals("ALL"))
         {
             visible &= row["tag"].Equals(tagFilter);
         }
         return(visible);
     });
 }
Esempio n. 6
0
        void updateNode(Topic topic, MsivPv liveMarket, LiveMarketNode node)
        {
            var averager = ticksReceived.get(liveMarket);

            if (!topic.has("ticksReceived"))
            {
                return;
            }
            node.ticksReceived = topic.get <int>("ticksReceived");
            node.runningOn     = topic.get <string>("hostname");
            averager.add(node.ticksReceived);
            node.tickRate = (float)averager.movingAverage();
            node.size     = isEqualSizes_ ? 1 : Math.Max(1F, node.tickRate);
            node.tickLag  = ticks.get(liveMarket).tickLag;
            node.color    = node.tickLag - 5000;
            node.isDown   = now().Subtract(date(topic.get <string>("timestamp"))).TotalSeconds < 10;
            var downText = node.isDown ? "" : "DOWN ";

            node.lastTickProcessed = ticks.get(liveMarket).lastTickProcessed();
            node.text =
                downText + liveMarket.market() + "\n" +
                node.tickRate.ToString("n0") + "/min, " + node.tickLag + "ms\n" +
                node.ticksReceived.ToString("n0") + "\n" +
                node.lastTickProcessed.ToString("HH:mm:ss") + "\n" +
                node.runningOn;
        }
Esempio n. 7
0
 public override double fxRate(Symbol symbol)
 {
     if (arguments().runInNativeCurrency)
     {
         return(1);
     }
     return(symbol.currency().isUSD() ? 1 : fxRates.get(symbol)[0].close);
 }
Esempio n. 8
0
        public List <QNode> nodes()
        {
            var bySystem = new LazyDictionary <string, List <LiveSystem> > (system => new List <LiveSystem>());

            each(systems, liveSystem => bySystem.get(liveSystem.siv().system()).Add(liveSystem));
            var result = list(convert(bySystem.keys(), system => {
                var liveSystems = bySystem.get(system);
                var systemNode  = new QNode(system, liveSystems.Count, 0);
                each(liveSystems, liveSystem => {
                    var liveSystemNode = systemNode.add(new LiveSystemNode(liveSystem, 1, 0));
                    var liveMarkets    = list <MsivPv>(liveSystem.liveMarkets());
                    each(liveMarkets, liveMarket => {
                        try {
                            var symbol         = new Symbol(liveMarket.market());
                            var liveMarketNode = new LiveMarketNode(symbol, 1, 0);
                            liveSystemNode.add(liveMarketNode);
                            var topic = new Topic(liveSystem.topicName(OrderTable.prefix, symbol.name + "." + SystemHeartbeat.SUFFIX));
                            topic.subscribeIfNeeded();
                            updateModelNodes += () => updateNode(topic, liveMarket, liveMarketNode);
                            symbol.subscribe(bar => recordMarketDataTickReceived(liveMarket, bar.time));
                            topic.subscribe(fields => {
                                var tickTime = fields.time("lastTickProcessed");
                                ticks.get(liveMarket).systemProcessed(date(tickTime));
                            });
                        } catch (Exception ex) {
                            LogC.err("exception caught subscribing to tick data for " + liveMarket + ", " + system, ex);
                            gui.alertUser("exception caught susbcribing to data for " + liveMarket + ", " + system + ".\nSkipping... see log for details.");
                        }
                    });
                    updateModelNodes += () => updateNode(liveSystem, liveSystemNode);
                });
                updateModelNodes += () => updateNode(systemNode);
                return(systemNode);
            }));

            timerManager().everyMillis(1000, updateModelNodes, out timer);
            LiveLauncher.subscribeHeartbeat(gui.launcherAvailable);
            LogC.ignore(timer);
            return(result);
        }
Esempio n. 9
0
        public void addToFerret(Fields fields, OrderSubmitter submitter)
        {
            fields.put("SYMBOL", symbol.name);
            details.addToFerret(fields);
            duration.addToFerret(fields);
            ferretSubmission = new OrderSubmission();
            ferretSubmission.addToFerretOrderSubmit(fields);
            fields.put("SIDE", direction.longShort("BUY", "SELL"));
            fields.put("QUANTITY", size);
            var config = configs.get(symbol.type());

            fields.put("PLATFORM", config.platform());
            fields.put("ROUTE", config.route());
            fields.put("SECURITYTYPE", symbol.type().Equals("Future") ? "FUTURES" : "EQUITY");
            fields.put("STATUS", "NEW");
            fields.put("MESSAGETYPE", "NewOrder");
        }
Esempio n. 10
0
        public void initialize()
        {
            each(StatusTracker.allLiveSystems(), liveSystem => {
                var tag       = liveSystem.bloombergTag();
                var tagTotals = tags.get(tag);
                each(list <MsivPv>(liveSystem.liveMarkets()), liveMarket => {
                    var symbol = new Symbol(new Market(liveMarket.market()));
                    if (!tagTotals.has(symbol))
                    {
                        var myRow             = addRow(tag, nameString(symbol), rowKey(tag, symbol));
                        myRow["symbolHIDDEN"] = symbol;
                    }
                    var symbolTotals         = tagTotals.get(symbol);
                    symbolTotals[liveSystem] = 0;

                    new Topic(liveSystem.topicName("TOMAHAWK", symbol.name + ".optimalPosition")).subscribe(fields => {
                        lock (symbolTotals) {
                            symbolTotals[liveSystem]            = fields.numeric("liveValue");
                            lastUpdateTime.get(tag)[liveMarket] = date(fields.time("liveTimestamp"));
                            var total = sum(symbolTotals.Values);
                            gui.runOnGuiThread(() => {
                                var myRow         = row(tag, symbol);
                                myRow["tomahawk"] = total;
                                update(myRow);
                            });
                        }
                    });
                });
            });
            new Topic("Positions.QMF.>", positionsBroker_).subscribe(fields => {
                var tag    = fields.text("level1TagName");
                var ticker = fields.text("ticker");
                if (isEmpty(ticker))
                {
                    ticker = fields.text("securityId");
                }
                var yellowKey = Strings.javaClassify(fields.text("yellowKey").ToLower());
                gui.runOnGuiThread(() => {
                    var myRow    = row(tag, ticker, yellowKey);
                    myRow["aim"] = fields.numeric("currentPosition");
                    update(myRow);
                });
            });
        }
Esempio n. 11
0
 void runSystem(Producer <SystemRunInfo> info, bool goLive)
 {
     try {
         gui.disableRunButton();
         runInfo   = info();
         simulator = runInfo.newSimulator((symbol, definition) => plots.get(symbol).Add(definition));
         each(simulator.symbols, symbol => simulator.addCollectible(symbol));
         simulator.addNewTradeListener(addTrade);
         simulator.processBars();
     } catch (Exception e) {
         gui.logAndAlert("failed during simulation run", e);
         return;
     } finally {
         runThread = null;
         gui.enableRunButton();
     }
     gui.reportResults(this);
     if (goLive)
     {
         simulator.goLive();
     }
 }
Esempio n. 12
0
 public Currency currency(Symbol symbol)
 {
     return(Bomb.ifNull(currencies.get(symbol), () => "can't get currency for " + symbol));
 }
Esempio n. 13
0
 public virtual void cancelOrder(Order o)
 {
     o.cancel();
     orders_.get(o.symbol).Remove(o);
 }
Esempio n. 14
0
 public virtual List <Position> positions(Symbol symbol)
 {
     return(positions_.get(symbol));
 }
Esempio n. 15
0
 public List <MarketPeriod> activePeriods(Symbol symbol)
 {
     return(activePeriods_.get(symbol));
 }
Esempio n. 16
0
 protected void addSystem(T key, S system)
 {
     systems_[key] = system;
     each(key.symbols(), symbol => systemsBySymbol.get(symbol).Add(system));
 }
Esempio n. 17
0
 public object this[int index] {
     get { return(cache.get(runs()[index])); }
     set { throw new NotImplementedException(); }
 }
Esempio n. 18
0
 public MarketSession session(Symbol symbol, string name)
 {
     return(sessions.get(symbol).get(name));
 }
Esempio n. 19
0
 public Dictionary <Symbol, Bar> currentBars(DateTime date)
 {
     return(dictionary(symbols, s => bars.get(s)[0]));
 }
Esempio n. 20
0
 Type slippageCalculator(Symbol symbol)
 {
     return(slippageCalculators.get(symbol));
 }
Esempio n. 21
0
 public FakeBarLoader(IEnumerable <Symbol> symbols)
 {
     this.symbols        = symbols;
     bars                = new LazyDictionary <Symbol, BarSpud>(s => barSpud());
     slippageCalculators = new LazyDictionary <Symbol, SlippageCalculator>(s => s.slippageCalculator(bars.get(s)));
 }
Esempio n. 22
0
 public string bloombergTicker(Symbol symbol)
 {
     return(bloombergTickers.get(symbol));
 }
Esempio n. 23
0
 public Dictionary <Symbol, double> currentSlippages(DateTime date)
 {
     return(dictionary(symbols, s => slippageCalculators.get(s).slippage()));
 }
Esempio n. 24
0
 public string type(Symbol symbol)
 {
     return(types.get(symbol));
 }
Esempio n. 25
0
 public void subscribe(Symbol symbol, TickListener listener)
 {
     tickListeners.get(symbol).add(listener);
 }
Esempio n. 26
0
 public void subscribe(Symbol symbol, ObservationListener listener)
 {
     observationListeners.get(symbol).add(listener);
 }
Esempio n. 27
0
 public void addTo(LazyDictionary <Symbol, List <Pair> > dictionary)
 {
     dictionary.get(left).Add(this);
     dictionary.get(right).Add(this);
 }
Esempio n. 28
0
 public override double slippage()
 {
     return(fixedSlippages.get(symbol));
 }