NewQuote
event
Occurs when the new Level1 quote by subscribed instrument is coming.
Syntax
public event Action<Instrument, Quote> NewQuote
Example
В следующем примере кода показано как можно использовать использовать event NewQuote.
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.