diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 8bd7343e..a0c68b35 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,5 @@ +* [MDAPI-96] [.NET] Retrieve latest events from feed + ## Version 2.5.2 * [MDAPI-165] [.NET] DxFeed.Graal.Net.Schedules.GetNextSession does not return null if no session exists diff --git a/src/DxFeed.Graal.Net/Api/DXFeed.cs b/src/DxFeed.Graal.Net/Api/DXFeed.cs index e71192e5..2703a907 100644 --- a/src/DxFeed.Graal.Net/Api/DXFeed.cs +++ b/src/DxFeed.Graal.Net/Api/DXFeed.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using DxFeed.Graal.Net.Api.Osub; using DxFeed.Graal.Net.Events; using DxFeed.Graal.Net.Native.Feed; using DxFeed.Graal.Net.Utils; @@ -78,10 +79,89 @@ public DXFeedSubscription CreateSubscription(params Type[] eventTypes) public DXFeedSubscription CreateSubscription(IEnumerable eventTypes) => CreateSubscription(eventTypes.ToArray()); + /// + /// Returns the last event for the specified event instance. + /// This method works only for event types that implement marker interface. + /// This method does not make any remote calls to the uplink data provider. + /// It just retrieves last received event from the local cache of this feed. + /// The events are stored in the cache only if there is some + /// attached that is subscribed to the corresponding symbol and event type. + /// subscription does not count for that purpose. + /// + ///

Use method + /// if an event needs to be requested in the absence of subscription.

+ /// + ///

This method fills in the values for the last event into the event argument. + /// If the last event is not available for any reason (no subscription, no connection to uplink, etc). + /// then the event object is not changed. + /// This method always returns the same event instance that is passed to it as an argument.

+ /// + ///

This method provides no way to distinguish a case when there is no subscription from the case when + /// there is a subscription, but the event data have not arrived yet. It is recommended to use + /// method + /// instead of this GetLastEvent method to fail-fast in case when the subscription was supposed to be + /// set by the logic of the code, since + /// method returns null when there is no subscription.

+ /// + ///

Note, that this method does not work when was created with + /// role (never fills in the event).

+ /// + ///
+ /// The event. + /// The type of event. + /// The same event. + public TE GetLastEvent(TE e) + where TE : ILastingEvent => + _feedNative.GetLastEvent(e); + + /// + /// Returns the last events for the specified list of event instances. + /// This is a bulk version of method. + /// + ///

Note, that this method does not work when was created with + /// role (never fills in the event).

+ /// + ///
+ /// The collection of events. + /// The type of event. + /// The same collection of events. + public IList GetLastEvents(IList events) + where TE : ILastingEvent => + _feedNative.GetLastEvents(events); + + /// + /// Returns the last event for the specified event type and symbol if there is a subscription for it. + /// This method works only for event types that implement marker interface. + /// This method does not make any remote calls to the uplink data provider. + /// It just retrieves last received event from the local cache of this feed. + /// The events are stored in the cache only if there is some + /// attached that is subscribed to the corresponding event type and symbol. + /// The subscription can also be permanently defined using properties. + /// subscription does not count for that purpose. + /// If there is no subscription, then this method returns null. + /// + ///

If there is a subscription, but the event has not arrived from the uplink data provider, + /// this method returns an non-initialized event object: its + /// property is set to the requested symbol, but all the other properties have their default values.

+ /// + ///

Use method + /// if an event needs to be requested in the absence of subscription.

+ /// + ///

Note, that this method does not work when was created with + /// role (never fills in the event).

+ /// + ///
+ /// The symbol. + /// The event type. + /// The event or null if there is no subscription for the specified event type and symbol. + public TE? GetLasEventIfSubscribed(object symbol) + where TE : ILastingEvent => + _feedNative.GetLastEventIfSubscribed(symbol); + /// /// Requests the last event for the specified event type and symbol. /// This method works only for event types that implement marker interface. - /// This method requests the data from the the uplink data provider, + /// This method requests the data from the uplink data provider, /// creates new event of the specified event type, /// and the resulting task with this event. /// diff --git a/src/DxFeed.Graal.Net/Native/Events/Candles/CandleMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Candles/CandleMapper.cs index 2d2afcf9..7a6f4a48 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Candles/CandleMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Candles/CandleMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,25 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Candle)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((CandleNative*)nativeEventType, (Candle)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Candle Convert(CandleNative* eventType) { - var candle = CreateEventType(eventType); - candle.EventFlags = eventType->EventFlags; - candle.Index = eventType->Index; - candle.Count = eventType->Count; - candle.Open = eventType->Open; - candle.High = eventType->High; - candle.Low = eventType->Low; - candle.Close = eventType->Close; - candle.Volume = eventType->Volume; - candle.VWAP = eventType->VWAP; - candle.BidVolume = eventType->BidVolume; - candle.AskVolume = eventType->AskVolume; - candle.ImpVolatility = eventType->ImpVolatility; - candle.OpenInterest = eventType->OpenInterest; + var candle = new Candle(); + Fill(eventType, candle); return candle; } @@ -61,4 +52,23 @@ protected override unsafe Candle Convert(CandleNative* eventType) }; return ptr; } + + private static unsafe Candle Fill(CandleNative* eventType, Candle candle) + { + AssignEventType((EventTypeNative*)eventType, candle); + candle.EventFlags = eventType->EventFlags; + candle.Index = eventType->Index; + candle.Count = eventType->Count; + candle.Open = eventType->Open; + candle.High = eventType->High; + candle.Low = eventType->Low; + candle.Close = eventType->Close; + candle.Volume = eventType->Volume; + candle.VWAP = eventType->VWAP; + candle.BidVolume = eventType->BidVolume; + candle.AskVolume = eventType->AskVolume; + candle.ImpVolatility = eventType->ImpVolatility; + candle.OpenInterest = eventType->OpenInterest; + return candle; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/EventMapper.cs b/src/DxFeed.Graal.Net/Native/Events/EventMapper.cs index 8b76b6f2..3e027dd7 100644 --- a/src/DxFeed.Graal.Net/Native/Events/EventMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/EventMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -80,6 +80,9 @@ public static unsafe ICollection FromNative(EventTypeNative** eventT public static unsafe IEventType FromNative(EventTypeNative* eventTypeNative) => GetEventMapperByEventCode(eventTypeNative->EventCode).FromNative(eventTypeNative); + public static unsafe IEventType FillFromNative(EventTypeNative* eventTypeNative, IEventType eventType) => + GetEventMapperByEventCode(eventTypeNative->EventCode).FillFromNative(eventTypeNative, eventType); + public static unsafe EventTypeNative* ToNative(IEventType eventType) => GetEventMapperByEventCode(eventType).ToNative(eventType); diff --git a/src/DxFeed.Graal.Net/Native/Events/EventTypeMapper.cs b/src/DxFeed.Graal.Net/Native/Events/EventTypeMapper.cs index e35ad491..a9a7b4fd 100644 --- a/src/DxFeed.Graal.Net/Native/Events/EventTypeMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/EventTypeMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -28,6 +28,9 @@ internal abstract class EventTypeMapper : IEventMa /// public abstract unsafe EventTypeNative* ToNative(IEventType eventType); + /// + public abstract unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType); + /// public abstract unsafe void Release(EventTypeNative* eventType); @@ -50,18 +53,12 @@ protected static EventTypeNative CreateEventType(TEventType eventType) => protected static EventTypeNative CreateEventType(EventCodeNative eventCode, TEventType eventType) => new() { EventCode = eventCode, EventSymbol = eventType.EventSymbol, EventTime = eventType.EventTime, }; - /// - protected static unsafe TEventType CreateEventType(TEventTypeNative* eventType) => - CreateEventType((EventTypeNative*)eventType); - - /// - /// Creates the specified TEventType from . - /// Populates only the fields contained in . - /// - /// The . - /// The created TEventType. - protected static unsafe TEventType CreateEventType(EventTypeNative* eventType) => - new() { EventSymbol = eventType->EventSymbol, EventTime = eventType->EventTime, }; + protected static unsafe TEventType AssignEventType(EventTypeNative* eventTypeNative, TEventType eventType) + { + eventType.EventSymbol = eventTypeNative->EventSymbol; + eventType.EventTime = eventTypeNative->EventTime; + return eventType; + } /// /// Allocates an unmanaged pointer with type and size TEventTypeNative. diff --git a/src/DxFeed.Graal.Net/Native/Events/IEventMapper.cs b/src/DxFeed.Graal.Net/Native/Events/IEventMapper.cs index e8693941..2816f0a5 100644 --- a/src/DxFeed.Graal.Net/Native/Events/IEventMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/IEventMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -35,6 +35,14 @@ internal interface IEventMapper /// unsafe EventTypeNative* ToNative(IEventType eventType); + /// + /// Populates an existing managed event type instance with data from a native event type. + /// + /// An unsafe pointer to a native instance. + /// The managed instance to populate. + /// The populated instance. + public unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType); + /// /// Releases all associated resources. /// This method released unmanaged memory allocated by . diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/AnalyticOrderMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/AnalyticOrderMapper.cs index 3b5be998..03e649b1 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/AnalyticOrderMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/AnalyticOrderMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -19,17 +19,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((AnalyticOrder)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((AnalyticOrderNative*)nativeEventType, (AnalyticOrder)eventType); + public override unsafe void Release(EventTypeNative* eventType) => OrderMapper.Release(eventType); protected override unsafe AnalyticOrder Convert(AnalyticOrderNative* eventType) { - var analyticOrder = CreateOrderBase((OrderBaseNative*)eventType); - analyticOrder.MarketMaker = eventType->Order.MarketMaker; - analyticOrder.IcebergPeakSize = eventType->IcebergPeakSize; - analyticOrder.IcebergHiddenSize = eventType->IcebergHiddenSize; - analyticOrder.IcebergExecutedSize = eventType->IcebergExecutedSize; - analyticOrder.IcebergFlags = eventType->IcebergFlags; + var analyticOrder = new AnalyticOrder(); + Fill(eventType, analyticOrder); return analyticOrder; } @@ -46,4 +45,15 @@ protected override unsafe AnalyticOrder Convert(AnalyticOrderNative* eventType) }; return ptr; } + + private static unsafe AnalyticOrder Fill(AnalyticOrderNative* eventType, AnalyticOrder analyticOrder) + { + AssignOrderBase((OrderBaseNative*)eventType, analyticOrder); + analyticOrder.MarketMaker = eventType->Order.MarketMaker; + analyticOrder.IcebergPeakSize = eventType->IcebergPeakSize; + analyticOrder.IcebergHiddenSize = eventType->IcebergHiddenSize; + analyticOrder.IcebergExecutedSize = eventType->IcebergExecutedSize; + analyticOrder.IcebergFlags = eventType->IcebergFlags; + return analyticOrder; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/OptionSaleMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/OptionSaleMapper.cs index f78a66d7..ac4fb7d7 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/OptionSaleMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/OptionSaleMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,6 +17,9 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((OptionSale)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((OptionSaleNative*)nativeEventType, (OptionSale)eventType); + public override unsafe void Release(EventTypeNative* eventType) { if (eventType == (EventTypeNative*)0) @@ -32,22 +35,8 @@ public override unsafe void Release(EventTypeNative* eventType) protected override unsafe OptionSale Convert(OptionSaleNative* eventType) { - var optionSale = CreateEventType(eventType); - optionSale.EventFlags = eventType->EventFlags; - optionSale.Index = eventType->Index; - optionSale.TimeSequence = eventType->TimeSequence; - optionSale.TimeNanoPart = eventType->TimeNanoPart; - optionSale.ExchangeCode = eventType->ExchangeCode; - optionSale.Price = eventType->Price; - optionSale.Size = eventType->Size; - optionSale.BidPrice = eventType->BidPrice; - optionSale.AskPrice = eventType->AskPrice; - optionSale.ExchangeSaleConditions = eventType->ExchangeSaleConditions; - optionSale.Flags = eventType->Flags; - optionSale.UnderlyingPrice = eventType->UnderlyingPrice; - optionSale.Volatility = eventType->Volatility; - optionSale.Delta = eventType->Delta; - optionSale.OptionSymbol = eventType->OptionSymbol; + var optionSale = new OptionSale(); + Fill(eventType, optionSale); return optionSale; } @@ -75,4 +64,25 @@ protected override unsafe OptionSale Convert(OptionSaleNative* eventType) }; return ptr; } + + private static unsafe OptionSale Fill(OptionSaleNative* eventType, OptionSale optionSale) + { + AssignEventType((EventTypeNative*)eventType, optionSale); + optionSale.EventFlags = eventType->EventFlags; + optionSale.Index = eventType->Index; + optionSale.TimeSequence = eventType->TimeSequence; + optionSale.TimeNanoPart = eventType->TimeNanoPart; + optionSale.ExchangeCode = eventType->ExchangeCode; + optionSale.Price = eventType->Price; + optionSale.Size = eventType->Size; + optionSale.BidPrice = eventType->BidPrice; + optionSale.AskPrice = eventType->AskPrice; + optionSale.ExchangeSaleConditions = eventType->ExchangeSaleConditions; + optionSale.Flags = eventType->Flags; + optionSale.UnderlyingPrice = eventType->UnderlyingPrice; + optionSale.Volatility = eventType->Volatility; + optionSale.Delta = eventType->Delta; + optionSale.OptionSymbol = eventType->OptionSymbol; + return optionSale; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/OrderBaseMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/OrderBaseMapper.cs index c68b568c..84c941dd 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/OrderBaseMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/OrderBaseMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -12,24 +12,25 @@ internal abstract class OrderBaseMapper : EventTyp where TOrderBase : OrderBase, new() where TOrderBaseNative : unmanaged { - protected static unsafe TOrderBase CreateOrderBase(OrderBaseNative* native) + protected static unsafe TOrderBase AssignOrderBase(OrderBaseNative* eventType, TOrderBase orderBase) { - var orderBase = CreateEventType((EventTypeNative*)native); - orderBase.EventFlags = native->EventFlags; - orderBase.Index = native->Index; - orderBase.TimeSequence = native->TimeSequence; - orderBase.TimeNanoPart = native->TimeNanoPart; - orderBase.ActionTime = native->ActionTime; - orderBase.OrderId = native->OrderId; - orderBase.AuxOrderId = native->AuxOrderId; - orderBase.Price = native->Price; - orderBase.Size = native->Size; - orderBase.ExecutedSize = native->ExecutedSize; - orderBase.Count = native->Count; - orderBase.Flags = native->Flags; - orderBase.TradeId = native->TradeId; - orderBase.TradePrice = native->TradePrice; - orderBase.TradeSize = native->TradeSize; + orderBase.EventSymbol = eventType->EventType.EventSymbol; + orderBase.EventTime = eventType->EventType.EventTime; + orderBase.EventFlags = eventType->EventFlags; + orderBase.Index = eventType->Index; + orderBase.TimeSequence = eventType->TimeSequence; + orderBase.TimeNanoPart = eventType->TimeNanoPart; + orderBase.ActionTime = eventType->ActionTime; + orderBase.OrderId = eventType->OrderId; + orderBase.AuxOrderId = eventType->AuxOrderId; + orderBase.Price = eventType->Price; + orderBase.Size = eventType->Size; + orderBase.ExecutedSize = eventType->ExecutedSize; + orderBase.Count = eventType->Count; + orderBase.Flags = eventType->Flags; + orderBase.TradeId = eventType->TradeId; + orderBase.TradePrice = eventType->TradePrice; + orderBase.TradeSize = eventType->TradeSize; return orderBase; } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/OrderMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/OrderMapper.cs index bd71b31e..d3127e14 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/OrderMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/OrderMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,6 +17,9 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Order)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((OrderNative*)nativeEventType, (Order)eventType); + public override unsafe void Release(EventTypeNative* eventType) { if (eventType == (EventTypeNative*)0) @@ -31,8 +34,8 @@ public override unsafe void Release(EventTypeNative* eventType) protected override unsafe Order Convert(OrderNative* eventType) { - var order = CreateOrderBase((OrderBaseNative*)eventType); - order.MarketMaker = eventType->MarketMaker; + var order = new Order(); + Fill(eventType, order); return order; } @@ -42,4 +45,11 @@ protected override unsafe Order Convert(OrderNative* eventType) *ptr = new() { OrderBase = CreateOrderBase(eventType), MarketMaker = eventType.MarketMaker, }; return ptr; } + + private static unsafe Order Fill(OrderNative* eventType, Order order) + { + AssignOrderBase((OrderBaseNative*)eventType, order); + order.MarketMaker = eventType->MarketMaker; + return order; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/OtcMarketsOrderMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/OtcMarketsOrderMapper.cs index 2a5e0ae4..c039a2ad 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/OtcMarketsOrderMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/OtcMarketsOrderMapper.cs @@ -19,15 +19,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((OtcMarketsOrder)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((OtcMarketsOrderNative*)nativeEventType, (OtcMarketsOrder)eventType); + public override unsafe void Release(EventTypeNative* eventType) => OrderMapper.Release(eventType); protected override unsafe OtcMarketsOrder Convert(OtcMarketsOrderNative* eventType) { - var order = CreateOrderBase((OrderBaseNative*)eventType); - order.MarketMaker = eventType->Order.MarketMaker; - order.OtcMarketsFlags = eventType->OtcMarketsFlags; - order.QuoteAccessPayment = eventType->QuoteAccessPayment; + var order = new OtcMarketsOrder(); + Fill(eventType, order); return order; } @@ -42,4 +43,13 @@ protected override unsafe OtcMarketsOrder Convert(OtcMarketsOrderNative* eventTy }; return ptr; } + + private static unsafe OtcMarketsOrder Fill(OtcMarketsOrderNative* eventType, OtcMarketsOrder order) + { + AssignOrderBase((OrderBaseNative*)eventType, order); + order.MarketMaker = eventType->Order.MarketMaker; + order.OtcMarketsFlags = eventType->OtcMarketsFlags; + order.QuoteAccessPayment = eventType->QuoteAccessPayment; + return order; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/ProfileMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/ProfileMapper.cs index 600b62d9..62d8c2da 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/ProfileMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/ProfileMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,6 +17,9 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Profile)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((ProfileNative*)nativeEventType, (Profile)eventType); + public override unsafe void Release(EventTypeNative* eventType) { if (eventType == (EventTypeNative*)0) @@ -32,23 +35,8 @@ public override unsafe void Release(EventTypeNative* eventType) protected override unsafe Profile Convert(ProfileNative* eventType) { - var profile = CreateEventType(eventType); - profile.Description = eventType->Description; - profile.StatusReason = eventType->StatusReason; - profile.HaltStartTime = eventType->HaltStartTime; - profile.HaltEndTime = eventType->HaltEndTime; - profile.HighLimitPrice = eventType->HighLimitPrice; - profile.LowLimitPrice = eventType->LowLimitPrice; - profile.High52WeekPrice = eventType->High52WeekPrice; - profile.Low52WeekPrice = eventType->Low52WeekPrice; - profile.Beta = eventType->Beta; - profile.EarningsPerShare = eventType->EarningsPerShare; - profile.DividendFrequency = eventType->DividendFrequency; - profile.ExDividendAmount = eventType->ExDividendAmount; - profile.ExDividendDayId = eventType->ExDividendDayId; - profile.Shares = eventType->Shares; - profile.FreeFloat = eventType->FreeFloat; - profile.Flags = eventType->Flags; + var profile = new Profile(); + Fill(eventType, profile); return profile; } @@ -77,4 +65,26 @@ protected override unsafe Profile Convert(ProfileNative* eventType) }; return ptr; } + + private static unsafe Profile Fill(ProfileNative* eventType, Profile profile) + { + AssignEventType((EventTypeNative*)eventType, profile); + profile.Description = eventType->Description; + profile.StatusReason = eventType->StatusReason; + profile.HaltStartTime = eventType->HaltStartTime; + profile.HaltEndTime = eventType->HaltEndTime; + profile.HighLimitPrice = eventType->HighLimitPrice; + profile.LowLimitPrice = eventType->LowLimitPrice; + profile.High52WeekPrice = eventType->High52WeekPrice; + profile.Low52WeekPrice = eventType->Low52WeekPrice; + profile.Beta = eventType->Beta; + profile.EarningsPerShare = eventType->EarningsPerShare; + profile.DividendFrequency = eventType->DividendFrequency; + profile.ExDividendAmount = eventType->ExDividendAmount; + profile.ExDividendDayId = eventType->ExDividendDayId; + profile.Shares = eventType->Shares; + profile.FreeFloat = eventType->FreeFloat; + profile.Flags = eventType->Flags; + return profile; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/QuoteMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/QuoteMapper.cs index 8af6c29a..890cfeab 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/QuoteMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/QuoteMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,22 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Quote)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((QuoteNative*)nativeEventType, (Quote)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Quote Convert(QuoteNative* eventType) { - var quote = CreateEventType(eventType); - quote.TimeMillisSequence = eventType->TimeMillisSequence; - quote.TimeNanoPart = eventType->TimeNanoPart; - quote.BidTime = eventType->BidTime; - quote.BidExchangeCode = eventType->BidExchangeCode; - quote.BidPrice = eventType->BidPrice; - quote.BidSize = eventType->BidSize; - quote.AskTime = eventType->AskTime; - quote.AskExchangeCode = eventType->AskExchangeCode; - quote.AskPrice = eventType->AskPrice; - quote.AskSize = eventType->AskSize; + var quote = new Quote(); + Fill(eventType, quote); return quote; } @@ -55,4 +49,20 @@ protected override unsafe Quote Convert(QuoteNative* eventType) }; return ptr; } + + private static unsafe Quote Fill(QuoteNative* eventType, Quote quote) + { + AssignEventType((EventTypeNative*)eventType, quote); + quote.TimeMillisSequence = eventType->TimeMillisSequence; + quote.TimeNanoPart = eventType->TimeNanoPart; + quote.BidTime = eventType->BidTime; + quote.BidExchangeCode = eventType->BidExchangeCode; + quote.BidPrice = eventType->BidPrice; + quote.BidSize = eventType->BidSize; + quote.AskTime = eventType->AskTime; + quote.AskExchangeCode = eventType->AskExchangeCode; + quote.AskPrice = eventType->AskPrice; + quote.AskSize = eventType->AskSize; + return quote; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/SpreadOrderMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/SpreadOrderMapper.cs index 530ad036..652c1c63 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/SpreadOrderMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/SpreadOrderMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,6 +17,9 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((SpreadOrder)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((SpreadOrderNative*)nativeEventType, (SpreadOrder)eventType); + public override unsafe void Release(EventTypeNative* eventType) { if (eventType == (EventTypeNative*)0) @@ -31,8 +34,8 @@ public override unsafe void Release(EventTypeNative* eventType) protected override unsafe SpreadOrder Convert(SpreadOrderNative* eventType) { - var spreadOrder = CreateOrderBase((OrderBaseNative*)eventType); - spreadOrder.SpreadSymbol = eventType->SpreadSymbol; + var spreadOrder = new SpreadOrder(); + Fill(eventType, spreadOrder); return spreadOrder; } @@ -42,4 +45,11 @@ protected override unsafe SpreadOrder Convert(SpreadOrderNative* eventType) *ptr = new() { OrderBase = CreateOrderBase(eventType), SpreadSymbol = eventType.SpreadSymbol, }; return ptr; } + + private static unsafe SpreadOrder Fill(SpreadOrderNative* eventType, SpreadOrder spreadOrder) + { + AssignOrderBase((OrderBaseNative*)eventType, spreadOrder); + spreadOrder.SpreadSymbol = eventType->SpreadSymbol; + return spreadOrder; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/SummaryMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/SummaryMapper.cs index f60479ab..0fd20cf2 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/SummaryMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/SummaryMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,22 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Summary)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((SummaryNative*)nativeEventType, (Summary)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Summary Convert(SummaryNative* eventType) { - var summary = CreateEventType(eventType); - summary.DayId = eventType->DayId; - summary.DayOpenPrice = eventType->DayOpenPrice; - summary.DayHighPrice = eventType->DayHighPrice; - summary.DayLowPrice = eventType->DayLowPrice; - summary.DayClosePrice = eventType->DayClosePrice; - summary.PrevDayId = eventType->PrevDayId; - summary.PrevDayClosePrice = eventType->PrevDayClosePrice; - summary.PrevDayVolume = eventType->PrevDayVolume; - summary.OpenInterest = eventType->OpenInterest; - summary.Flags = eventType->Flags; + var summary = new Summary(); + Fill(eventType, summary); return summary; } @@ -55,4 +49,20 @@ protected override unsafe Summary Convert(SummaryNative* eventType) }; return ptr; } + + private static unsafe Summary Fill(SummaryNative* eventType, Summary summary) + { + AssignEventType((EventTypeNative*)eventType, summary); + summary.DayId = eventType->DayId; + summary.DayOpenPrice = eventType->DayOpenPrice; + summary.DayHighPrice = eventType->DayHighPrice; + summary.DayLowPrice = eventType->DayLowPrice; + summary.DayClosePrice = eventType->DayClosePrice; + summary.PrevDayId = eventType->PrevDayId; + summary.PrevDayClosePrice = eventType->PrevDayClosePrice; + summary.PrevDayVolume = eventType->PrevDayVolume; + summary.OpenInterest = eventType->OpenInterest; + summary.Flags = eventType->Flags; + return summary; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/TimeAndSaleMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/TimeAndSaleMapper.cs index 647081a6..ad6e50be 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/TimeAndSaleMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/TimeAndSaleMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,6 +17,9 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((TimeAndSale)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((TimeAndSaleNative*)nativeEventType, (TimeAndSale)eventType); + public override unsafe void Release(EventTypeNative* eventType) { if (eventType == (EventTypeNative*)0) @@ -33,19 +36,8 @@ public override unsafe void Release(EventTypeNative* eventType) protected override unsafe TimeAndSale Convert(TimeAndSaleNative* eventType) { - var timeAndSale = CreateEventType(eventType); - timeAndSale.EventFlags = eventType->EventFlags; - timeAndSale.Index = eventType->Index; - timeAndSale.TimeNanoPart = eventType->TimeNanoPart; - timeAndSale.ExchangeCode = eventType->ExchangeCode; - timeAndSale.Price = eventType->Price; - timeAndSale.Size = eventType->Size; - timeAndSale.BidPrice = eventType->BidPrice; - timeAndSale.AskPrice = eventType->AskPrice; - timeAndSale.ExchangeSaleConditions = eventType->ExchangeSaleConditions; - timeAndSale.Flags = eventType->Flags; - timeAndSale.Buyer = eventType->Buyer; - timeAndSale.Seller = eventType->Seller; + var timeAndSale = new TimeAndSale(); + Fill(eventType, timeAndSale); return timeAndSale; } @@ -70,4 +62,22 @@ protected override unsafe TimeAndSale Convert(TimeAndSaleNative* eventType) }; return ptr; } + + private static unsafe TimeAndSale Fill(TimeAndSaleNative* eventType, TimeAndSale timeAndSale) + { + AssignEventType((EventTypeNative*)eventType, timeAndSale); + timeAndSale.EventFlags = eventType->EventFlags; + timeAndSale.Index = eventType->Index; + timeAndSale.TimeNanoPart = eventType->TimeNanoPart; + timeAndSale.ExchangeCode = eventType->ExchangeCode; + timeAndSale.Price = eventType->Price; + timeAndSale.Size = eventType->Size; + timeAndSale.BidPrice = eventType->BidPrice; + timeAndSale.AskPrice = eventType->AskPrice; + timeAndSale.ExchangeSaleConditions = eventType->ExchangeSaleConditions; + timeAndSale.Flags = eventType->Flags; + timeAndSale.Buyer = eventType->Buyer; + timeAndSale.Seller = eventType->Seller; + return timeAndSale; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/TradeBaseMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/TradeBaseMapper.cs index 4ea1d732..736b90d3 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/TradeBaseMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/TradeBaseMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -12,9 +12,10 @@ internal abstract class TradeBaseMapper : EventTyp where TTradeBase : TradeBase, new() where TTradeBaseNative : unmanaged { - protected static unsafe TTradeBase CreateTradeBase(TradeBaseNative* eventType) + protected static unsafe TTradeBase AssignTradeBase(TradeBaseNative* eventType, TTradeBase tradeBase) { - var tradeBase = CreateEventType((EventTypeNative*)eventType); + tradeBase.EventSymbol = eventType->EventType.EventSymbol; + tradeBase.EventTime = eventType->EventType.EventTime; tradeBase.TimeSequence = eventType->TimeSequence; tradeBase.TimeNanoPart = eventType->TimeNanoPart; tradeBase.ExchangeCode = eventType->ExchangeCode; diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/TradeETHMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/TradeETHMapper.cs index 5bfed3ed..1b06019b 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/TradeETHMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/TradeETHMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -20,11 +20,18 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((TradeETH)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((TradeETHNative*)nativeEventType, (TradeETH)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseTradeBase(eventType); - protected override unsafe TradeETH Convert(TradeETHNative* eventType) => - CreateTradeBase((TradeBaseNative*)eventType); + protected override unsafe TradeETH Convert(TradeETHNative* eventType) + { + var tradeETH = new TradeETH(); + Fill(eventType, tradeETH); + return tradeETH; + } protected override unsafe TradeETHNative* Convert(TradeETH eventType) { @@ -32,4 +39,10 @@ protected override unsafe TradeETH Convert(TradeETHNative* eventType) => *ptr = new() { TradeBase = CreateTradeBase(eventType) }; return ptr; } + + private static unsafe TradeETH Fill(TradeETHNative* eventType, TradeETH trade) + { + AssignTradeBase((TradeBaseNative*)eventType, trade); + return trade; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Market/TradeMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Market/TradeMapper.cs index c4dddf6b..9a77f082 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Market/TradeMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Market/TradeMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,11 +17,18 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Trade)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((TradeNative*)nativeEventType, (Trade)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseTradeBase(eventType); - protected override unsafe Trade Convert(TradeNative* eventType) => - CreateTradeBase((TradeBaseNative*)eventType); + protected override unsafe Trade Convert(TradeNative* eventType) + { + var trade = new Trade(); + Fill(eventType, trade); + return trade; + } protected override unsafe TradeNative* Convert(Trade eventType) { @@ -29,4 +36,10 @@ protected override unsafe Trade Convert(TradeNative* eventType) => *ptr = new() { TradeBase = CreateTradeBase(eventType) }; return ptr; } + + private static unsafe Trade Fill(TradeNative* eventType, Trade trade) + { + AssignTradeBase((TradeBaseNative*)eventType, trade); + return trade; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Options/GreeksMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Options/GreeksMapper.cs index 28caa71f..12085fdc 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Options/GreeksMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Options/GreeksMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,21 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Greeks)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((GreeksNative*)nativeEventType, (Greeks)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Greeks Convert(GreeksNative* eventType) { - var greeks = CreateEventType(eventType); - greeks.EventFlags = eventType->EventFlags; - greeks.Index = eventType->Index; - greeks.Price = eventType->Price; - greeks.Volatility = eventType->Volatility; - greeks.Delta = eventType->Delta; - greeks.Gamma = eventType->Gamma; - greeks.Theta = eventType->Theta; - greeks.Rho = eventType->Rho; - greeks.Vega = eventType->Vega; + var greeks = new Greeks(); + Fill(eventType, greeks); return greeks; } @@ -53,4 +48,19 @@ protected override unsafe Greeks Convert(GreeksNative* eventType) }; return ptr; } + + private static unsafe Greeks Fill(GreeksNative* eventType, Greeks greeks) + { + AssignEventType((EventTypeNative*)eventType, greeks); + greeks.EventFlags = eventType->EventFlags; + greeks.Index = eventType->Index; + greeks.Price = eventType->Price; + greeks.Volatility = eventType->Volatility; + greeks.Delta = eventType->Delta; + greeks.Gamma = eventType->Gamma; + greeks.Theta = eventType->Theta; + greeks.Rho = eventType->Rho; + greeks.Vega = eventType->Vega; + return greeks; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Options/SeriesMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Options/SeriesMapper.cs index 009af332..e5d8fc2c 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Options/SeriesMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Options/SeriesMapper.cs @@ -17,23 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Series)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((SeriesNative*)nativeEventType, (Series)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Series Convert(SeriesNative* eventType) { - var series = CreateEventType(eventType); - series.EventFlags = eventType->EventFlags; - series.Index = eventType->Index; - series.TimeSequence = eventType->TimeSequence; - series.Expiration = eventType->Expiration; - series.Volatility = eventType->Volatility; - series.CallVolume = eventType->CallVolume; - series.PutVolume = eventType->PutVolume; - series.PutCallRatio = eventType->PutCallRatio; - series.ForwardPrice = eventType->ForwardPrice; - series.Dividend = eventType->Dividend; - series.Interest = eventType->Interest; + var series = new Series(); + Fill(eventType, series); return series; } @@ -57,4 +50,21 @@ protected override unsafe Series Convert(SeriesNative* eventType) }; return ptr; } + + private static unsafe Series Fill(SeriesNative* eventType, Series series) + { + AssignEventType((EventTypeNative*)eventType, series); + series.EventFlags = eventType->EventFlags; + series.Index = eventType->Index; + series.TimeSequence = eventType->TimeSequence; + series.Expiration = eventType->Expiration; + series.Volatility = eventType->Volatility; + series.CallVolume = eventType->CallVolume; + series.PutVolume = eventType->PutVolume; + series.PutCallRatio = eventType->PutCallRatio; + series.ForwardPrice = eventType->ForwardPrice; + series.Dividend = eventType->Dividend; + series.Interest = eventType->Interest; + return series; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Options/TheoPriceMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Options/TheoPriceMapper.cs index a5f68915..fa6ea61b 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Options/TheoPriceMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Options/TheoPriceMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,20 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((TheoPrice)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((TheoPriceNative*)nativeEventType, (TheoPrice)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe TheoPrice Convert(TheoPriceNative* eventType) { - var theoPrice = CreateEventType(eventType); - theoPrice.EventFlags = eventType->EventFlags; - theoPrice.Index = eventType->Index; - theoPrice.Price = eventType->Price; - theoPrice.UnderlyingPrice = eventType->UnderlyingPrice; - theoPrice.Delta = eventType->Delta; - theoPrice.Gamma = eventType->Gamma; - theoPrice.Dividend = eventType->Dividend; - theoPrice.Interest = eventType->Interest; + var theoPrice = new TheoPrice(); + Fill(eventType, theoPrice); return theoPrice; } @@ -51,4 +47,18 @@ protected override unsafe TheoPrice Convert(TheoPriceNative* eventType) }; return ptr; } + + private static unsafe TheoPrice Fill(TheoPriceNative* eventType, TheoPrice theoPrice) + { + AssignEventType((EventTypeNative*)eventType, theoPrice); + theoPrice.EventFlags = eventType->EventFlags; + theoPrice.Index = eventType->Index; + theoPrice.Price = eventType->Price; + theoPrice.UnderlyingPrice = eventType->UnderlyingPrice; + theoPrice.Delta = eventType->Delta; + theoPrice.Gamma = eventType->Gamma; + theoPrice.Dividend = eventType->Dividend; + theoPrice.Interest = eventType->Interest; + return theoPrice; + } } diff --git a/src/DxFeed.Graal.Net/Native/Events/Options/UnderlyingMapper.cs b/src/DxFeed.Graal.Net/Native/Events/Options/UnderlyingMapper.cs index f5f04e15..e464aae0 100644 --- a/src/DxFeed.Graal.Net/Native/Events/Options/UnderlyingMapper.cs +++ b/src/DxFeed.Graal.Net/Native/Events/Options/UnderlyingMapper.cs @@ -1,5 +1,5 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // @@ -17,20 +17,16 @@ public override unsafe IEventType FromNative(EventTypeNative* eventType) => public override unsafe EventTypeNative* ToNative(IEventType eventType) => (EventTypeNative*)Convert((Underlying)eventType); + public override unsafe IEventType FillFromNative(EventTypeNative* nativeEventType, IEventType eventType) => + Fill((UnderlyingNative*)nativeEventType, (Underlying)eventType); + public override unsafe void Release(EventTypeNative* eventType) => ReleaseEventType(eventType); protected override unsafe Underlying Convert(UnderlyingNative* eventType) { - var underlying = CreateEventType(eventType); - underlying.EventFlags = eventType->EventFlags; - underlying.Index = eventType->Index; - underlying.Volatility = eventType->Volatility; - underlying.FrontVolatility = eventType->FrontVolatility; - underlying.BackVolatility = eventType->BackVolatility; - underlying.CallVolume = eventType->CallVolume; - underlying.PutVolume = eventType->PutVolume; - underlying.PutCallRatio = eventType->PutCallRatio; + var underlying = new Underlying(); + Fill(eventType, underlying); return underlying; } @@ -51,4 +47,18 @@ protected override unsafe Underlying Convert(UnderlyingNative* eventType) }; return ptr; } + + private static unsafe Underlying Fill(UnderlyingNative* eventType, Underlying underlying) + { + AssignEventType((EventTypeNative*)eventType, underlying); + underlying.EventFlags = eventType->EventFlags; + underlying.Index = eventType->Index; + underlying.Volatility = eventType->Volatility; + underlying.FrontVolatility = eventType->FrontVolatility; + underlying.BackVolatility = eventType->BackVolatility; + underlying.CallVolume = eventType->CallVolume; + underlying.PutVolume = eventType->PutVolume; + underlying.PutCallRatio = eventType->PutCallRatio; + return underlying; + } } diff --git a/src/DxFeed.Graal.Net/Native/Feed/FeedNative.cs b/src/DxFeed.Graal.Net/Native/Feed/FeedNative.cs index 2c8b094c..9103c6c0 100644 --- a/src/DxFeed.Graal.Net/Native/Feed/FeedNative.cs +++ b/src/DxFeed.Graal.Net/Native/Feed/FeedNative.cs @@ -1,18 +1,19 @@ // -// Copyright © 2022 Devexperts LLC. All rights reserved. +// Copyright © 2024 Devexperts LLC. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // using System.Collections.Generic; using System.Runtime.InteropServices; -using DxFeed.Graal.Net.Native.ErrorHandling; +using DxFeed.Graal.Net.Events; using DxFeed.Graal.Net.Native.Events; using DxFeed.Graal.Net.Native.Graal; using DxFeed.Graal.Net.Native.Interop; using DxFeed.Graal.Net.Native.Promise; using DxFeed.Graal.Net.Native.Subscription; using DxFeed.Graal.Net.Native.SymbolMappers; +using static DxFeed.Graal.Net.Native.ErrorHandling.ErrorCheck; namespace DxFeed.Graal.Net.Native.Feed; @@ -43,6 +44,58 @@ public void DetachSubscription(SubscriptionNative subscriptionNative) => public void DetachSubscriptionAndClear(SubscriptionNative subscriptionNative) => FeedImport.DetachSubscriptionAndClear(GetCurrentThread(), _feedHandle, subscriptionNative.GetHandle()); + public T GetLastEvent(T e) + where T : ILastingEvent + { + var eventCode = EventCodeAttribute.GetEventCode(typeof(T)); + var handle = GetLastEventIfSubscribed(eventCode, e.EventSymbol!); + if (handle == null) + { + return e; + } + + try + { + EventMapper.FillFromNative(handle, e); + return e; + } + finally + { + SafeCall(FeedImport.ReleaseNativeEvent(GetCurrentThread(), handle)); + } + } + + public IList GetLastEvents(IList events) + where T : ILastingEvent + { + foreach (var e in events) + { + GetLastEvent(e); + } + + return events; + } + + public T? GetLastEventIfSubscribed(object symbol) + where T : ILastingEvent + { + var eventCode = EventCodeAttribute.GetEventCode(typeof(T)); + var handle = FeedImport.GetLastEventIfSubscribed(GetCurrentThread(), _feedHandle, eventCode, symbol); + if (handle == null) + { + return default; + } + + try + { + return (T?)EventMapper.FromNative(handle); + } + finally + { + SafeCall(FeedImport.ReleaseNativeEvent(GetCurrentThread(), handle)); + } + } + public PromiseNative GetLastEventPromise(EventCodeNative eventCode, object symbol) => FeedImport.GetLastEventPromise(GetCurrentThread(), _feedHandle, eventCode, symbol); @@ -55,6 +108,9 @@ public PromiseNative GetTimeSeriesPromise(EventCodeNative eventCode, object symb private static nint GetCurrentThread() => Isolate.CurrentThread; + private EventTypeNative* GetLastEventIfSubscribed(EventCodeNative eventCode, object symbol) => + FeedImport.GetLastEventIfSubscribed(GetCurrentThread(), _feedHandle, eventCode, symbol); + /// /// Contains imported functions from native code. /// @@ -64,7 +120,7 @@ private static class FeedImport nint thread, FeedHandle* feedHandle, EventCodeNative eventCode) => - ErrorCheck.SafeCall(NativeCreateSubscription(thread, feedHandle, eventCode)); + SafeCall(NativeCreateSubscription(thread, feedHandle, eventCode)); public static SubscriptionHandle* CreateSubscription( nint thread, @@ -74,7 +130,7 @@ private static class FeedImport var codes = ListNative.Create(eventCodes); try { - return ErrorCheck.SafeCall(NativeCreateSubscription(thread, feedHandle, codes)); + return SafeCall(NativeCreateSubscription(thread, feedHandle, codes)); } finally { @@ -86,19 +142,31 @@ public static void AttachSubscription( nint thread, FeedHandle* feedHandle, SubscriptionHandle* subHandle) => - ErrorCheck.SafeCall(NativeAttachSubscription(thread, feedHandle, subHandle)); + SafeCall(NativeAttachSubscription(thread, feedHandle, subHandle)); public static void DetachSubscription( nint thread, FeedHandle* feedHandle, SubscriptionHandle* subHandle) => - ErrorCheck.SafeCall(NativeDetachSubscription(thread, feedHandle, subHandle)); + SafeCall(NativeDetachSubscription(thread, feedHandle, subHandle)); public static void DetachSubscriptionAndClear( nint thread, FeedHandle* feedHandle, SubscriptionHandle* subHandle) => - ErrorCheck.SafeCall(NativeDetachSubscriptionAndClear(thread, feedHandle, subHandle)); + SafeCall(NativeDetachSubscriptionAndClear(thread, feedHandle, subHandle)); + + [DllImport( + ImportInfo.DllName, + CallingConvention = CallingConvention.Cdecl, + CharSet = CharSet.Ansi, + EntryPoint = "dxfg_DXFeed_getLastEventIfSubscribed")] + public static extern EventTypeNative* GetLastEventIfSubscribed( + nint thread, + FeedHandle* feedHandle, + EventCodeNative eventCodes, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(SymbolMarshaler))] + object symbol); [DllImport( ImportInfo.DllName, @@ -126,6 +194,13 @@ public static extern PromiseNative GetLastEventPromise( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(SymbolMarshaler))] object value); + [DllImport( + ImportInfo.DllName, + EntryPoint = "dxfg_EventType_release")] + public static extern int ReleaseNativeEvent( + nint thread, + EventTypeNative* nativeEvent); + [DllImport( ImportInfo.DllName, CallingConvention = CallingConvention.Cdecl,