示例#1
0
        public void DataProvider()
        {
            Tick t = Tick.NewTrade(s, 10, 700);
            // feature to pass-through ticks to any subscriber
            // this can be connected to tradelink library to allow filtered subscribptions
            // and interapplication communication
            Broker broker = new Broker();
            broker.GotTick += new TickDelegate(broker_GotTick);
            Assert.That((receivedtickDP == null) && (gottickDP == 0));
            broker.Execute(t); // should fire a gotTick
            Assert.That(gottickDP != 0);
            Assert.That((receivedtickDP != null) && (receivedtickDP.trade == t.trade));

        }
示例#2
0
 public void Basics()
 {
     Broker broker = new Broker();
     broker.GotFill += new FillDelegate(broker_GotFill);
     broker.GotOrder += new OrderDelegate(broker_GotOrder);
     broker.GotWarning += new DebugDelegate(broker_GotWarning);
     Order o = new Order();
     uint failsoninvalid= broker.sendOrder(o);
     Assert.That(failsoninvalid==0);
     Assert.That(warn == 1);
     Assert.That(orders == 0);
     Assert.That(fills == 0);
     o = new BuyMarket(s, 100);
     Assert.That(broker.sendOrder(o)>0);
     Assert.That(orders == 1);
     Assert.That(fills == 0);
     Assert.That(broker.Execute(Tick.NewTrade(s,10,200)) == 1);
     Assert.That(fills == 1);
     // no warnings since first warning
     Assert.That(warn == 1);
 }
示例#3
0
 // make sure this box only generates orders when last one has been filled
 public void OneOrderAtTime() 
 {
     Always b = new Always();
     b.AllowMultipleOrders = false; // this is the default, but it's what we're testing
     b.MaxSize = Int32.MaxValue; // lets not restrict our maximum position for this example
     Broker broker = new Broker();
     Tick t;
     Assert.That(b.MinSize == 100);
     int good = 0;
     int i = 0;
     Order o = new Order();
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 0);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 1);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     // lets change this to a limit order, so he doesn't get filled on just any tick
     o.price = 1;
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     // first trade was pre-market 2nd order was never filled so 3rd was ignored... 2 total.
     Assert.That(good == 2);
 }