You need to enable JavaScript in order to visit our site!
 
Logo PTMC
NAVIGATION
CANCEL
 
or via PTMC account
Restore password
or via PTMC account
Logo PTMC
NAVIGATION
or via PTMC account
Restore password
or via PTMC account
or via PTMC account
Restore password
or via PTMC account

NewTrade

event
Occurs when the new trade quote by subscribed instrument is coming.

Syntax

public event Action<Instrument, Trade> NewTrade

Example


 В следующем примере кода показано как можно использовать использовать event NewTrade.
 
 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
 using System.Drawing;
 using PTLRuntime.NETScript;

 namespace InstrumentsCollection_
 {
     public class InstrumentsCollection_ : NETStrategy
     {
         int QuoteCounter = 0,
         TradeCounter = 0,
         Level2Counter = 0,
         MaintCount = 0;

         Instrument instr;
         Instrument[] instrArray, instrSortArray;
         string[] instrNames;

         int index = 10;

         public override void Init()
         {
             Instruments.NewTrade += OnTrade; //Создание event на новые сделки
             Instruments.NewQuote += OnQuote2; //Создание event на обновление lvl1 котировок
             Instruments.NewLevel2 += OnLevel2; //Создание event на обновление lvl2 котировок

             Instruments.InstrumentAdded += OnInstrumentAdd;//Создание event на добавление нового инструмента на сервере

             instr = Instruments.Current; //текущий инструмент
             Alert("Current instrument is: " + instr.Name);

             //Подписка на выбранный инстурмент
             Instruments.Subscribe(instr, QuoteTypes.Trade); //подписка на пройденные сделки
             Instruments.Subscribe(instr, QuoteTypes.Quote);
             Instruments.Subscribe(instr, QuoteTypes.Level2);

             instrArray = Instruments.GetInstruments();
             instrSortArray = Instruments.GetSortedInstruments();
             instrNames = Instruments.GetSortedInstrumentNames();

             Print(index + " instrument name in unsorte instrument name array is " + Instruments.GetInstrument(instrNames[index]).Name);
             Print(index + " instrument name in unsorted instrument array is " + Instruments.GetInstrument(instrArray[index].Symbol, instrArray[index].Route).Name);
             Print(index + " instrument name in sorted instrument array is " + Instruments.GetInstrument(instrSortArray[index].Symbol, instrSortArray[index].Route).Name);

             foreach (Instrument i in instrArray)
             {
                 if (i.Type == InstrumentType.Future)
                 {
                     instr = Instruments.GetInstrument(i.Symbol, i.Route, i.GetDerivativeSettings().ContractMonthDate);
                     Alert(instr.Name);
                 }
             }
         }

         private void OnQuote2(Instrument instr, Quote quote)
         {
             QuoteCounter++;
         }

         private void OnLevel2(Instrument instr, Level2 level2)
         {
             Level2Counter++;
         }

         private void OnTrade(Instrument instr, Trade trade)
         {
             TradeCounter++;
         }

         private void OnInstrumentAdd(Instrument instr)
         {
             Print("Add new instrument on server");
         }

         public override void OnQuote()
         {
             MaintCount++;
             Comment("#LVL1: " + QuoteCounter + "\t#LVL2: " + Level2Counter + "\t#LVL3: " + TradeCounter + "\t#OnQuote: " + MaintCount);
         }

         public override void Complete()
         {
             Instruments.NewTrade -= OnTrade;
             Instruments.NewQuote -= OnQuote2;
             Instruments.NewLevel2 -= OnLevel2;

             Instruments.InstrumentAdded -= OnInstrumentAdd;

             //Отписка от инструмента к которому подписывались вначале.
             Instruments.Unsubscribe(instr, QuoteTypes.Trade);
             Instruments.Unsubscribe(instr, QuoteTypes.Quote);
             Instruments.Unsubscribe(instr, QuoteTypes.Level2);
         }
     }
 }
 
Discussion
Join PTMC community to post your comments
No comments yet. Be the first.
PTMC is a professional trading platform that combines all the best charting and analytical tools to trade on different financial markets. It is developed by PFSOFT UK LTD, a global provider of trading technology for banks & brokers
© 2024. PTMC is based on Protrader technology
PFSOFT UK LTD
71-75, Shelton Street,
Covent Garden,
London, WC2H9SQ,
United Kingdom
Support & Development
PFSOFT Ukraine
Office #701
Mechnikova Street, 10B
49000, Dnipro, Ukraine
Contact us
Phone: +380 56 740 30 01
E-mail: info@protrader.org
Skype: PTMC_support
Find more ways to contact
Join us in social networks