本文整理汇总了C#中QDMS.Instrument类的典型用法代码示例。如果您正苦于以下问题:C# Instrument类的具体用法?C# Instrument怎么用?C# Instrument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instrument类属于QDMS命名空间,在下文中一共展示了Instrument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DataImportWindow
public DataImportWindow(Instrument instrument)
{
InitializeComponent();
//reload the instrument first to make sure we have up-to-date data
using (var context = new MyDBContext())
{
context.Instruments.Attach(instrument);
context.Entry(instrument).Reload();
_instrument = instrument;
}
Title += " - " + _instrument.Symbol;
//fill frequency combo box
var values = MyUtils.GetEnumValues<BarSize>();
foreach (BarSize s in values)
{
FrequencyComboBox.Items.Add(s);
}
FrequencyComboBox.SelectedItem = BarSize.OneDay;
MinDT.Value = new DateTime(1950, 1, 1);
MaxDT.Value = DateTime.Now;
}
示例2: InstrumentToContract
public static Contract InstrumentToContract(Instrument instrument)
{
string symbol = string.IsNullOrEmpty(instrument.DatasourceSymbol) ? instrument.Symbol : instrument.DatasourceSymbol;
var contract = new Contract(
0,
symbol,
SecurityTypeConverter(instrument.Type),
instrument.Expiration.HasValue ? instrument.Expiration.Value.ToString("yyyyMM", CultureInfo.InvariantCulture) : "",
0,
OptionTypeToRightType(instrument.OptionType),
instrument.Multiplier.ToString(),
"",
instrument.Currency,
null,
null,
SecurityIdType.None,
string.Empty);
if (instrument.Strike.HasValue)
contract.Strike = (double)instrument.Strike.Value;
if (instrument.Exchange != null)
contract.Exchange = instrument.Exchange.Name;
return contract;
}
示例3: DataPushRequestIsForwardedToLocalStorage
public void DataPushRequestIsForwardedToLocalStorage()
{
var instrument = new Instrument
{
ID = 1,
Symbol = "SPY",
Datasource = new Datasource { ID = 1, Name = "MockSource" }
};
var data = new List<OHLCBar>
{
new OHLCBar {Open = 1, High = 2, Low = 3, Close = 4, DT = new DateTime(2013, 1, 1) }
};
var req = new DataAdditionRequest(BarSize.OneDay, instrument, data, true);
_client.PushData(req);
Thread.Sleep(50);
_brokerMock.Verify(x => x.AddData(
It.Is<DataAdditionRequest>(y =>
y.Frequency == BarSize.OneDay &&
y.Instrument.ID == 1 &&
y.Data.Count == 1)
), Times.Once);
}
示例4: SetUp
public void SetUp()
{
_instrument = new Instrument
{
ID = 1,
Symbol = "SPY",
Datasource = new Datasource { ID = 1, Name = "MockSource" }
};
_instrument.Exchange = new Exchange()
{
ID = 1,
Name = "Exchange",
Timezone = "Eastern Standard Time"
};
_dataSourceMock = new Mock<IHistoricalDataSource>();
_dataSourceMock.SetupGet(x => x.Name).Returns("MockSource");
_dataSourceMock.SetupGet(x => x.Connected).Returns(false);
_localStorageMock = new Mock<IDataStorage>();
_cfBrokerMock = new Mock<IContinuousFuturesBroker>();
_cfBrokerMock.SetupGet(x => x.Connected).Returns(true);
_broker = new HistoricalDataBroker(_cfBrokerMock.Object, _localStorageMock.Object, new List<IHistoricalDataSource> { _dataSourceMock.Object });
_dataSourceMock.SetupGet(x => x.Connected).Returns(true);
}
示例5: HistoricalRequestWindow
public HistoricalRequestWindow(Instrument instrument)
{
InitializeComponent();
DataContext = this;
Random r = new Random(); //we have to randomize the name of the client, can't reuse the identity
Title = string.Format("Data Request - {0} @ {1}", instrument.Symbol, instrument.Datasource.Name);
_client = new QDMSClient.QDMSClient(
string.Format("DataRequestClient-{0}", r.Next()),
"localhost",
Properties.Settings.Default.rtDBReqPort,
Properties.Settings.Default.rtDBPubPort,
Properties.Settings.Default.instrumentServerPort,
Properties.Settings.Default.hDBPort);
_client.HistoricalDataReceived += _client_HistoricalDataReceived;
_client.Error += _client_Error;
_client.Connect();
Data = new ObservableCollection<OHLCBar>();
TheInstrument = instrument;
StartTime = new DateTime(1950, 1, 1, 0, 0, 0, 0);
EndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0);
if (!TheInstrument.ID.HasValue) return;
ShowDialog();
}
示例6: RealTimeDataRequest
public RealTimeDataRequest(Instrument instrument, BarSize frequency, bool rthOnly = true, bool savetoLocalStorage = false)
{
Instrument = instrument;
Frequency = frequency;
RTHOnly = rthOnly;
SaveToLocalStorage = savetoLocalStorage;
}
示例7: EmailReportSentOnBrokerError
public void EmailReportSentOnBrokerError()
{
var settings = new UpdateJobSettings(errors: true, timeout: 1, toEmail: "[email protected]", fromEmail: "[email protected]");
var job = new DataUpdateJob(_brokerMock.Object, _mailMock.Object, settings, _localStorageMock.Object, _instrumentManagerMock.Object);
_brokerMock
.Setup(x => x.RequestHistoricalData(It.IsAny<HistoricalDataRequest>()))
.Throws(new Exception("TestException123"));
Instrument inst = new Instrument() { ID = 1, Symbol = "SPY", Currency = "USD", Type = InstrumentType.Stock };
_instrumentManagerMock
.Setup(x => x.FindInstruments(It.IsAny<Expression<Func<Instrument, bool>>>(), It.IsAny<MyDBContext>()))
.Returns(new List<Instrument>() { inst });
_localStorageMock
.Setup(x => x.GetStorageInfo(It.IsAny<int>()))
.Returns(new List<StoredDataInfo>() {
new StoredDataInfo()
{
Frequency = BarSize.OneDay,
InstrumentID = inst.ID.Value,
LatestDate = DateTime.Now.AddDays(-2)
} });
job.Execute(_contextMock.Object);
_mailMock.Verify(x =>
x.Send(
It.IsAny<string>(),
It.Is<string>(y => y == "[email protected]"),
It.IsAny<string>(),
It.Is<string>(y => y.Contains("TestException123"))));
}
示例8: ServerCorrectlyForwardsRealTimeData
public void ServerCorrectlyForwardsRealTimeData()
{
var ds = new Datasource() { ID = 1, Name = "TestDS" };
var inst = new Instrument() { ID = 15, Datasource = ds, DatasourceID = 1, Symbol = "SPY", Type = InstrumentType.Stock };
var req = new RealTimeDataRequest(inst, BarSize.FiveSeconds, rthOnly: false, savetoLocalStorage: false);
_brokerMock.Setup(x => x.RequestRealTimeData(It.IsAny<RealTimeDataRequest>())).Returns(true);
_client.RequestRealTimeData(req);
Thread.Sleep(50);
RealTimeDataEventArgs receivedData = null;
_client.RealTimeDataReceived += (s,e) => receivedData = e;
long dt = DateTime.Now.ToBinary();
_brokerMock.Raise(x => x.RealTimeDataArrived += null, new RealTimeDataEventArgs(15, dt, 100m, 105m, 95m, 99m, 10000000, 101, 500, 1));
Thread.Sleep(50);
Assert.IsNotNull(receivedData);
Assert.AreEqual(15, receivedData.InstrumentID);
Assert.AreEqual(dt, receivedData.Time);
Assert.AreEqual(100m, receivedData.Open);
Assert.AreEqual(105m, receivedData.High);
Assert.AreEqual(95m, receivedData.Low);
Assert.AreEqual(99m, receivedData.Close);
Assert.AreEqual(10000000, receivedData.Volume);
Assert.AreEqual(500, receivedData.Count);
Assert.AreEqual(101, receivedData.Wap);
}
示例9: HistoricalDataRequestsAreForwardedToTheBroker
public void HistoricalDataRequestsAreForwardedToTheBroker()
{
var instrument = new Instrument
{
ID = 1,
Symbol = "SPY",
Datasource = new Datasource { ID = 1, Name = "MockSource" },
Exchange = new Exchange
{
ID = 1,
Name = "Exchange",
Timezone = "Eastern Standard Time"
}
};
var request = new HistoricalDataRequest(instrument, BarSize.OneDay, new DateTime(2012, 1, 1), new DateTime(2013, 1, 1));
_client.RequestHistoricalData(request);
// TODO: Think about delay amount
Thread.Sleep(1500);
_historicalDataBrokerMock.Verify(
x => x.RequestHistoricalData(
It.Is<HistoricalDataRequest>(
r =>
r.Instrument.ID == 1 &&
r.Frequency == BarSize.OneDay &&
r.StartingDate == new DateTime(2012, 1, 1) &&
r.EndingDate == new DateTime(2013, 1, 1))),
Times.Once);
}
示例10: DataAdditionRequest
public DataAdditionRequest(BarSize frequency, Instrument instrument, List<OHLCBar> data, bool overwrite = true)
{
Data = data;
Frequency = frequency;
Instrument = instrument;
Overwrite = overwrite;
}
示例11: ContractDetailsToInstrument
public static Instrument ContractDetailsToInstrument(ContractDetails contract)
{
var instrument = new Instrument
{
Symbol = contract.Summary.LocalSymbol,
UnderlyingSymbol = contract.Summary.Symbol,
Name = contract.LongName,
OptionType = RightTypeToOptionType(contract.Summary.Right),
Type = InstrumentTypeConverter(contract.Summary.SecurityType),
Multiplier = contract.Summary.Multiplier == null ? 1 : int.Parse(contract.Summary.Multiplier),
Expiration = string.IsNullOrEmpty(contract.Summary.Expiry) ? (DateTime?)null : DateTime.ParseExact(contract.Summary.Expiry, "yyyyMMdd", CultureInfo.InvariantCulture),
Strike = (decimal)contract.Summary.Strike,
Currency = contract.Summary.Currency,
MinTick = (decimal)contract.MinTick,
Industry = contract.Industry,
Category = contract.Category,
Subcategory = contract.Subcategory,
IsContinuousFuture = false,
ValidExchanges = contract.ValidExchanges
};
if (!string.IsNullOrEmpty(contract.Summary.PrimaryExchange))
instrument.PrimaryExchange = new Exchange { Name = contract.Summary.PrimaryExchange };
return instrument;
}
示例12: RemoveInstrument
/// <summary>
/// Delete an instrument and all locally stored data.
/// </summary>
public static void RemoveInstrument(Instrument instrument)
{
using (var entityContext = new MyDBContext())
{
//hacking around the circular reference issue
if (instrument.IsContinuousFuture)
{
entityContext.Instruments.Attach(instrument);
var tmpCF = instrument.ContinuousFuture;
instrument.ContinuousFuture = null;
instrument.ContinuousFutureID = null;
entityContext.SaveChanges();
entityContext.ContinuousFutures.Attach(tmpCF);
entityContext.ContinuousFutures.Remove(tmpCF);
entityContext.SaveChanges();
}
entityContext.Instruments.Attach(instrument);
entityContext.Instruments.Remove(instrument);
entityContext.SaveChanges();
}
using (var localStorage = DataStorageFactory.Get())
{
localStorage.Connect();
localStorage.DeleteAllInstrumentData(instrument);
}
}
示例13: ServerCorrectlyForwardsCancellationRequestsToBroker
public void ServerCorrectlyForwardsCancellationRequestsToBroker()
{
var ds = new Datasource() { ID = 1, Name = "TestDS" };
var inst = new Instrument() { ID = 15, Datasource = ds, DatasourceID = 1, Symbol = "SPY", Type = InstrumentType.Stock };
_client.CancelRealTimeData(inst);
_brokerMock.Verify(x => x.CancelRTDStream(It.Is<int>(y => y == 15)));
}
示例14: RealTimeStreamInfo
public RealTimeStreamInfo(Instrument instrument, int requestID, string datasource, BarSize frequency, bool rthOnly) : this()
{
Instrument = instrument;
RequestID = requestID;
Datasource = datasource;
Frequency = frequency;
RTHOnly = rthOnly;
}
示例15: GetTZInfoThrowsExceptionIfNonExistingTimezoneIsSpecified
public void GetTZInfoThrowsExceptionIfNonExistingTimezoneIsSpecified()
{
var inst = new Instrument { Exchange = new Exchange { Timezone = "asdf____" } };
Assert.Throws<TimeZoneNotFoundException>(() =>
{
TimeZoneInfo tz = inst.GetTZInfo();
});
}