Skip to main content

nautilus_finfeed/python/
models.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Typed Python views of raw provider results, with exact decimals and RFC 3339 timestamps.
17
18use nautilus_core::{UnixNanos, python::to_pyvalue_err};
19use nautilus_model::instruments::BinaryOption;
20use pyo3::{prelude::*, types::PyDict};
21use rust_decimal::Decimal;
22
23use crate::http::{
24    models::{
25        ActivityBatch, ActivityCurrent, Book, BookEvent, BookLevel, Exchange, Market, MarketStatus,
26        MarketsPage, Ohlcv, OhlcvPeriod, OutcomeType, Quote, Trade, TradeSide,
27    },
28    parse::parse_instrument,
29};
30
31/// Provider exchange identity and metadata, retaining nullable fields.
32#[derive(Debug, Clone)]
33#[pyclass(
34    name = "FinFeedExchange",
35    module = "nautilus_trader.adapters.finfeed",
36    frozen,
37    from_py_object
38)]
39#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
40pub struct PyFinFeedExchange {
41    inner: Exchange,
42}
43
44#[pymethods]
45#[pyo3_stub_gen::derive::gen_stub_pymethods]
46impl PyFinFeedExchange {
47    /// Provider exchange identifier, retained verbatim.
48    #[getter(exchange_id)]
49    fn py_exchange_id(&self) -> Option<String> {
50        self.inner.exchange_id.map(|value| value.to_string())
51    }
52
53    /// Provider description of the exchange or institution.
54    #[getter(market_name_institution_description)]
55    fn py_market_name_institution_description(&self) -> Option<String> {
56        self.inner.market_name_institution_description.clone()
57    }
58
59    /// Provider-supplied website URL.
60    #[getter(website)]
61    fn py_website(&self) -> Option<String> {
62        self.inner.website.clone()
63    }
64}
65
66impl From<Exchange> for PyFinFeedExchange {
67    fn from(inner: Exchange) -> Self {
68        Self { inner }
69    }
70}
71
72/// Provider outcome metadata, with exact decimals and a separate checked Nautilus mapping.
73#[derive(Debug, Clone)]
74#[pyclass(
75    name = "FinFeedMarket",
76    module = "nautilus_trader.adapters.finfeed",
77    frozen,
78    from_py_object
79)]
80#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
81pub struct PyFinFeedMarket {
82    inner: Market,
83}
84
85#[pymethods]
86#[pyo3_stub_gen::derive::gen_stub_pymethods]
87impl PyFinFeedMarket {
88    /// Provider exchange identifier for this outcome.
89    #[getter(exchange_id)]
90    fn py_exchange_id(&self) -> Option<String> {
91        self.inner.exchange_id.map(|value| value.to_string())
92    }
93
94    /// Provider outcome identifier, retained verbatim.
95    #[getter(market_id)]
96    fn py_market_id(&self) -> Option<String> {
97        self.inner.market_id.map(|value| value.to_string())
98    }
99
100    /// Provider contract classification, independent of native mapping support.
101    #[getter(outcome_type)]
102    fn py_outcome_type(&self) -> FinFeedOutcomeType {
103        self.inner.outcome_type.into()
104    }
105
106    /// Provider outcome label, such as `Yes` or `No`.
107    #[getter(outcome_name)]
108    fn py_outcome_name(&self) -> Option<String> {
109        self.inner.outcome_name.clone()
110    }
111
112    /// Provider market mechanism label.
113    #[getter(mechanism)]
114    fn py_mechanism(&self) -> Option<String> {
115        self.inner.mechanism.map(|value| value.to_string())
116    }
117
118    /// Provider lifecycle label; unknown labels decode as `Unknown`.
119    #[getter(status)]
120    fn py_status(&self) -> FinFeedMarketStatus {
121        self.inner.status.into()
122    }
123
124    /// Provider-reported outcome price, decoded without floating-point conversion.
125    #[getter(price)]
126    fn py_price(&self) -> Decimal {
127        self.inner.price
128    }
129
130    /// Provider market title.
131    #[getter(title)]
132    fn py_title(&self) -> Option<String> {
133        self.inner.title.clone()
134    }
135
136    /// Provider market description.
137    #[getter(description)]
138    fn py_description(&self) -> Option<String> {
139        self.inner.description.clone()
140    }
141
142    /// Nested exchange metadata, when supplied.
143    #[getter(exchange)]
144    fn py_exchange(&self) -> Option<PyFinFeedExchange> {
145        self.inner.exchange.clone().map(Into::into)
146    }
147
148    /// Venue-specific metadata retained as raw JSON values.
149    #[getter(source_specific_data)]
150    fn py_source_specific_data(&self, py: Python<'_>) -> PyResult<Option<Py<PyDict>>> {
151        let Some(source) = &self.inner.source_specific_data else {
152            return Ok(None);
153        };
154
155        let loads = py.import("json")?.getattr("loads")?;
156        let kwargs = PyDict::new(py);
157        kwargs.set_item("parse_float", py.import("decimal")?.getattr("Decimal")?)?;
158        let values = PyDict::new(py);
159        for (key, raw) in source {
160            values.set_item(key, loads.call((raw.get(),), Some(&kwargs))?)?;
161        }
162
163        Ok(Some(values.unbind()))
164    }
165
166    /// Parses a checked provider-owned Polymarket Yes/No definition.
167    ///
168    /// Polymarket uses pUSD and six-decimal shares, matching the native adapter's conventions.
169    /// Unavailable activation uses its zero timestamp convention. `EndDateIso` sets the simulated
170    /// trading cutoff; it does not prove actual venue closure or authoritative settlement.
171    /// Other venue families fail until their required field rules are verified.
172    ///
173    /// # Errors
174    ///
175    /// Returns an error if:
176    /// - The venue or contract is unsupported.
177    /// - Required identity or metadata is missing, invalid, or conflicting.
178    /// - The tick is outside `(0, 1)` or the provider price is outside `[0, 1]`.
179    /// - A price requires rounding or expiry is outside the supported timestamp range.
180    #[pyo3(signature = (ts_init=0))]
181    fn to_instrument(&self, ts_init: u64) -> PyResult<BinaryOption> {
182        let ts_init = UnixNanos::from(ts_init);
183        parse_instrument(&self.inner, ts_init).map_err(to_pyvalue_err)
184    }
185}
186
187impl From<Market> for PyFinFeedMarket {
188    fn from(inner: Market) -> Self {
189        Self { inner }
190    }
191}
192
193/// A cursor listing envelope; a missing next cursor establishes termination.
194#[derive(Debug, Clone)]
195#[pyclass(
196    name = "FinFeedMarketsPage",
197    module = "nautilus_trader.adapters.finfeed",
198    frozen,
199    from_py_object
200)]
201#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
202pub struct PyFinFeedMarketsPage {
203    inner: MarketsPage,
204}
205
206#[pymethods]
207#[pyo3_stub_gen::derive::gen_stub_pymethods]
208impl PyFinFeedMarketsPage {
209    /// Outcome definitions for this page; absent or null data remains `None`.
210    #[getter(data)]
211    fn py_data(&self) -> Option<Vec<PyFinFeedMarket>> {
212        self.inner
213            .data
214            .clone()
215            .map(|records| records.into_iter().map(Into::into).collect())
216    }
217
218    /// Continuation cursor; `None` ends traversal.
219    #[getter(next_cursor)]
220    fn py_next_cursor(&self) -> Option<String> {
221        self.inner.next_cursor.clone()
222    }
223}
224
225impl From<MarketsPage> for PyFinFeedMarketsPage {
226    fn from(inner: MarketsPage) -> Self {
227        Self { inner }
228    }
229}
230
231/// A provider trade with exact price and quantity, without aggressor-side inference.
232#[derive(Debug, Clone)]
233#[pyclass(
234    name = "FinFeedTrade",
235    module = "nautilus_trader.adapters.finfeed",
236    frozen,
237    from_py_object
238)]
239#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
240pub struct PyFinFeedTrade {
241    inner: Trade,
242}
243
244#[pymethods]
245#[pyo3_stub_gen::derive::gen_stub_pymethods]
246impl PyFinFeedTrade {
247    /// Provider outcome identifier.
248    #[getter(market_id)]
249    fn py_market_id(&self) -> Option<String> {
250        self.inner.market_id.map(|value| value.to_string())
251    }
252
253    /// Opaque provider trade ID; native conversion requires a nonempty ID.
254    #[getter(id)]
255    fn py_id(&self) -> Option<String> {
256        self.inner.id.clone()
257    }
258
259    /// Provider outcome label, when supplied.
260    #[getter(outcome)]
261    fn py_outcome(&self) -> Option<String> {
262        self.inner.outcome.clone()
263    }
264
265    /// Provider side label; does not identify the aggressor.
266    #[getter(side)]
267    fn py_side(&self) -> FinFeedTradeSide {
268        self.inner.side.into()
269    }
270
271    /// Trade price, decoded without floating-point conversion.
272    #[getter(price)]
273    fn py_price(&self) -> Decimal {
274        self.inner.price
275    }
276
277    /// Trade quantity, decoded without floating-point conversion.
278    #[getter(quantity)]
279    fn py_quantity(&self) -> Decimal {
280        self.inner.quantity
281    }
282
283    /// Sole provider timestamp, used for both native event and initialization times.
284    #[getter(timestamp)]
285    fn py_timestamp(&self) -> String {
286        self.inner.timestamp.to_string()
287    }
288}
289
290impl From<Trade> for PyFinFeedTrade {
291    fn from(inner: Trade) -> Self {
292        Self { inner }
293    }
294}
295
296/// Exact quote prices and sizes, retaining both provider timestamps.
297#[derive(Debug, Clone)]
298#[pyclass(
299    name = "FinFeedQuote",
300    module = "nautilus_trader.adapters.finfeed",
301    frozen,
302    from_py_object
303)]
304#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
305pub struct PyFinFeedQuote {
306    inner: Quote,
307}
308
309#[pymethods]
310#[pyo3_stub_gen::derive::gen_stub_pymethods]
311impl PyFinFeedQuote {
312    /// Bid price, decoded exactly.
313    #[getter(bid)]
314    fn py_bid(&self) -> Decimal {
315        self.inner.bid
316    }
317
318    /// Ask price, decoded exactly.
319    #[getter(ask)]
320    fn py_ask(&self) -> Decimal {
321        self.inner.ask
322    }
323
324    /// Size available at the bid, decoded exactly.
325    #[getter(bid_volume)]
326    fn py_bid_volume(&self) -> Decimal {
327        self.inner.bid_volume
328    }
329
330    /// Size available at the ask, decoded exactly.
331    #[getter(ask_volume)]
332    fn py_ask_volume(&self) -> Decimal {
333        self.inner.ask_volume
334    }
335
336    /// Provider entry timestamp, used as native `ts_event`.
337    #[getter(entry_time)]
338    fn py_entry_time(&self) -> String {
339        self.inner.entry_time.to_string()
340    }
341
342    /// Provider receive timestamp, used as native `ts_init`.
343    #[getter(recv_time)]
344    fn py_recv_time(&self) -> String {
345        self.inner.recv_time.to_string()
346    }
347}
348
349impl From<Quote> for PyFinFeedQuote {
350    fn from(inner: Quote) -> Self {
351        Self { inner }
352    }
353}
354
355/// The latest trade and quote, each independently optional.
356#[derive(Debug, Clone)]
357#[pyclass(
358    name = "FinFeedActivityCurrent",
359    module = "nautilus_trader.adapters.finfeed",
360    frozen,
361    from_py_object
362)]
363#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
364pub struct PyFinFeedActivityCurrent {
365    inner: ActivityCurrent,
366}
367
368#[pymethods]
369#[pyo3_stub_gen::derive::gen_stub_pymethods]
370impl PyFinFeedActivityCurrent {
371    /// Latest quote; absent or null values remain `None`.
372    #[getter(quote)]
373    fn py_quote(&self) -> Option<PyFinFeedQuote> {
374        self.inner.quote.clone().map(Into::into)
375    }
376
377    /// Latest trade; absent or null values remain `None`.
378    #[getter(trade)]
379    fn py_trade(&self) -> Option<PyFinFeedTrade> {
380        self.inner.trade.clone().map(Into::into)
381    }
382}
383
384impl From<ActivityCurrent> for PyFinFeedActivityCurrent {
385    fn from(inner: ActivityCurrent) -> Self {
386        Self { inner }
387    }
388}
389
390/// Latest activity lists, retaining the distinction between absent and empty lists.
391#[derive(Debug, Clone)]
392#[pyclass(
393    name = "FinFeedActivityBatch",
394    module = "nautilus_trader.adapters.finfeed",
395    frozen,
396    from_py_object
397)]
398#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
399pub struct PyFinFeedActivityBatch {
400    inner: ActivityBatch,
401}
402
403#[pymethods]
404#[pyo3_stub_gen::derive::gen_stub_pymethods]
405impl PyFinFeedActivityBatch {
406    /// Quote list, independently bounded by the activity query limit.
407    #[getter(quotes)]
408    fn py_quotes(&self) -> Option<Vec<PyFinFeedQuote>> {
409        self.inner
410            .quotes
411            .clone()
412            .map(|records| records.into_iter().map(Into::into).collect())
413    }
414
415    /// Trade list, independently bounded by the activity query limit.
416    #[getter(trades)]
417    fn py_trades(&self) -> Option<Vec<PyFinFeedTrade>> {
418        self.inner
419            .trades
420            .clone()
421            .map(|records| records.into_iter().map(Into::into).collect())
422    }
423}
424
425impl From<ActivityBatch> for PyFinFeedActivityBatch {
426    fn from(inner: ActivityBatch) -> Self {
427        Self { inner }
428    }
429}
430
431/// A snapshot price level with exact size.
432#[derive(Debug, Clone)]
433#[pyclass(
434    name = "FinFeedBookLevel",
435    module = "nautilus_trader.adapters.finfeed",
436    frozen,
437    from_py_object
438)]
439#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
440pub struct PyFinFeedBookLevel {
441    inner: BookLevel,
442}
443
444#[pymethods]
445#[pyo3_stub_gen::derive::gen_stub_pymethods]
446impl PyFinFeedBookLevel {
447    /// Price of the aggregated level, decoded exactly.
448    #[getter(price)]
449    fn py_price(&self) -> Decimal {
450        self.inner.price
451    }
452
453    /// Size of the aggregated level, decoded exactly.
454    #[getter(size)]
455    fn py_size(&self) -> Decimal {
456        self.inner.size
457    }
458}
459
460impl From<BookLevel> for PyFinFeedBookLevel {
461    fn from(inner: BookLevel) -> Self {
462        Self { inner }
463    }
464}
465
466/// A raw current snapshot with nullable sides, without continuity or recovery inference.
467#[derive(Debug, Clone)]
468#[pyclass(
469    name = "FinFeedBook",
470    module = "nautilus_trader.adapters.finfeed",
471    frozen,
472    from_py_object
473)]
474#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
475pub struct PyFinFeedBook {
476    inner: Book,
477}
478
479#[pymethods]
480#[pyo3_stub_gen::derive::gen_stub_pymethods]
481impl PyFinFeedBook {
482    /// Provider exchange identifier.
483    #[getter(exchange_id)]
484    fn py_exchange_id(&self) -> Option<String> {
485        self.inner.exchange_id.map(|value| value.to_string())
486    }
487
488    /// Provider outcome identifier.
489    #[getter(market_id)]
490    fn py_market_id(&self) -> Option<String> {
491        self.inner.market_id.map(|value| value.to_string())
492    }
493
494    /// Bid levels; `None` remains distinct from an empty side.
495    #[getter(bids)]
496    fn py_bids(&self) -> Option<Vec<PyFinFeedBookLevel>> {
497        self.inner
498            .bids
499            .clone()
500            .map(|records| records.into_iter().map(Into::into).collect())
501    }
502
503    /// Ask levels; `None` remains distinct from an empty side.
504    #[getter(asks)]
505    fn py_asks(&self) -> Option<Vec<PyFinFeedBookLevel>> {
506        self.inner
507            .asks
508            .clone()
509            .map(|records| records.into_iter().map(Into::into).collect())
510    }
511
512    /// Exchange timestamp, used as native `ts_event`.
513    #[getter(time_exchange)]
514    fn py_time_exchange(&self) -> String {
515        self.inner.time_exchange.to_string()
516    }
517
518    /// Provider receive timestamp, used as native `ts_init`.
519    #[getter(time_coinapi)]
520    fn py_time_coinapi(&self) -> String {
521        self.inner.time_coinapi.to_string()
522    }
523}
524
525impl From<Book> for PyFinFeedBook {
526    fn from(inner: Book) -> Self {
527        Self { inner }
528    }
529}
530
531/// A raw historical book event with uninterpreted numeric actions and provider ordering.
532#[derive(Debug, Clone)]
533#[pyclass(
534    name = "FinFeedBookEvent",
535    module = "nautilus_trader.adapters.finfeed",
536    frozen,
537    from_py_object
538)]
539#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
540pub struct PyFinFeedBookEvent {
541    inner: BookEvent,
542}
543
544#[pymethods]
545#[pyo3_stub_gen::derive::gen_stub_pymethods]
546impl PyFinFeedBookEvent {
547    /// Provider symbol identifier, retained verbatim.
548    #[getter(symbol_id)]
549    fn py_symbol_id(&self) -> String {
550        self.inner.symbol_id.to_string()
551    }
552
553    /// Provider event identifier, retained verbatim.
554    #[getter(id)]
555    fn py_id(&self) -> String {
556        self.inner.id.clone()
557    }
558
559    /// Raw numeric action code, interpreted only during native L2 replay.
560    #[getter(update_type)]
561    fn py_update_type(&self) -> i64 {
562        self.inner.update_type
563    }
564
565    /// Whether the event applies to the ask side.
566    #[getter(is_sell_ask)]
567    fn py_is_sell_ask(&self) -> bool {
568        self.inner.is_sell_ask
569    }
570
571    /// Raw event price, decoded exactly.
572    #[getter(price)]
573    fn py_price(&self) -> Decimal {
574        self.inner.price
575    }
576
577    /// Raw event size; absolute or relative meaning depends on the action.
578    #[getter(size)]
579    fn py_size(&self) -> Decimal {
580        self.inner.size
581    }
582
583    /// Exchange event timestamp.
584    #[getter(time_exchange)]
585    fn py_time_exchange(&self) -> String {
586        self.inner.time_exchange.to_string()
587    }
588
589    /// Optional provider processing timestamp; omissions remain `None`.
590    #[getter(time_coinapi)]
591    fn py_time_coinapi(&self) -> Option<String> {
592        self.inner.time_coinapi.map(|time| time.to_string())
593    }
594}
595
596impl From<BookEvent> for PyFinFeedBookEvent {
597    fn from(inner: BookEvent) -> Self {
598        Self { inner }
599    }
600}
601
602/// A provider OHLCV period definition.
603#[derive(Debug, Clone)]
604#[pyclass(
605    name = "FinFeedOhlcvPeriod",
606    module = "nautilus_trader.adapters.finfeed",
607    frozen,
608    from_py_object
609)]
610#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
611pub struct PyFinFeedOhlcvPeriod {
612    inner: OhlcvPeriod,
613}
614
615#[pymethods]
616#[pyo3_stub_gen::derive::gen_stub_pymethods]
617impl PyFinFeedOhlcvPeriod {
618    /// Provider identifier accepted by DB-backed OHLCV queries.
619    #[getter(period_id)]
620    fn py_period_id(&self) -> Option<String> {
621        self.inner.period_id.map(|value| value.to_string())
622    }
623
624    /// Provider unit label.
625    #[getter(unit_name)]
626    fn py_unit_name(&self) -> Option<String> {
627        self.inner.unit_name.map(|value| value.to_string())
628    }
629
630    /// Number of units in the provider period definition.
631    #[getter(unit_count)]
632    fn py_unit_count(&self) -> Option<i32> {
633        self.inner.unit_count
634    }
635
636    /// Fixed period length in seconds.
637    #[getter(length_seconds)]
638    fn py_length_seconds(&self) -> i32 {
639        self.inner.length_seconds
640    }
641
642    /// Calendar period length in months.
643    #[getter(length_months)]
644    fn py_length_months(&self) -> i32 {
645        self.inner.length_months
646    }
647
648    /// Provider display label for the period.
649    #[getter(display_name)]
650    fn py_display_name(&self) -> Option<String> {
651        self.inner.display_name.map(|value| value.to_string())
652    }
653}
654
655impl From<OhlcvPeriod> for PyFinFeedOhlcvPeriod {
656    fn from(inner: OhlcvPeriod) -> Self {
657        Self { inner }
658    }
659}
660
661/// A provider bar with nullable prices, exact aggregate volume, and an optional raw market identifier.
662#[derive(Debug, Clone)]
663#[pyclass(
664    name = "FinFeedOhlcv",
665    module = "nautilus_trader.adapters.finfeed",
666    frozen,
667    from_py_object
668)]
669#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
670pub struct PyFinFeedOhlcv {
671    inner: Ohlcv,
672}
673
674#[pymethods]
675#[pyo3_stub_gen::derive::gen_stub_pymethods]
676impl PyFinFeedOhlcv {
677    /// Raw outcome identifier; exchange-wide history can include unknown or missing IDs.
678    #[getter(market_id_exchange)]
679    fn py_market_id_exchange(&self) -> Option<String> {
680        self.inner.market_id_exchange.map(|value| value.to_string())
681    }
682
683    /// Opening price; absent or null values remain `None`.
684    #[getter(price_open)]
685    fn py_price_open(&self) -> Option<Decimal> {
686        self.inner.price_open
687    }
688
689    /// Highest price; absent or null values remain `None`.
690    #[getter(price_high)]
691    fn py_price_high(&self) -> Option<Decimal> {
692        self.inner.price_high
693    }
694
695    /// Lowest price; absent or null values remain `None`.
696    #[getter(price_low)]
697    fn py_price_low(&self) -> Option<Decimal> {
698        self.inner.price_low
699    }
700
701    /// Closing price; absent or null values remain `None`.
702    #[getter(price_close)]
703    fn py_price_close(&self) -> Option<Decimal> {
704        self.inner.price_close
705    }
706
707    /// Provider aggregate volume, decoded without floating-point conversion.
708    #[getter(volume_traded)]
709    fn py_volume_traded(&self) -> Decimal {
710        self.inner.volume_traded
711    }
712
713    /// Provider-reported trade count.
714    #[getter(trades_count)]
715    fn py_trades_count(&self) -> i64 {
716        self.inner.trades_count
717    }
718
719    /// Period start timestamp.
720    #[getter(time_period_start)]
721    fn py_time_period_start(&self) -> String {
722        self.inner.time_period_start.to_string()
723    }
724
725    /// Period end timestamp, used for both native bar timestamps.
726    #[getter(time_period_end)]
727    fn py_time_period_end(&self) -> String {
728        self.inner.time_period_end.to_string()
729    }
730
731    /// Provider timestamp of the opening observation, when supplied.
732    #[getter(time_open)]
733    fn py_time_open(&self) -> Option<String> {
734        self.inner.time_open.map(|time| time.to_string())
735    }
736
737    /// Provider timestamp of the closing observation, when supplied.
738    #[getter(time_close)]
739    fn py_time_close(&self) -> Option<String> {
740        self.inner.time_close.map(|time| time.to_string())
741    }
742}
743
744impl From<Ohlcv> for PyFinFeedOhlcv {
745    fn from(inner: Ohlcv) -> Self {
746        Self { inner }
747    }
748}
749
750/// Provider lifecycle labels, without settlement inference.
751#[derive(Debug, Clone, Copy, PartialEq, Eq)]
752#[pyclass(
753    module = "nautilus_trader.adapters.finfeed",
754    frozen,
755    from_py_object,
756    eq,
757    rename_all = "SCREAMING_SNAKE_CASE"
758)]
759#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
760pub enum FinFeedMarketStatus {
761    /// Provider labels the market open.
762    Open,
763    /// Provider labels the market closed; this is not a settlement event.
764    Closed,
765    /// Provider labels the market resolved; no payout is inferred.
766    Resolved,
767    /// Provider labels the market suspended.
768    Suspended,
769    /// Unrecognized provider lifecycle label.
770    Unknown,
771}
772
773impl From<MarketStatus> for FinFeedMarketStatus {
774    fn from(value: MarketStatus) -> Self {
775        match value {
776            MarketStatus::Open => Self::Open,
777            MarketStatus::Closed => Self::Closed,
778            MarketStatus::Resolved => Self::Resolved,
779            MarketStatus::Suspended => Self::Suspended,
780            MarketStatus::Unknown => Self::Unknown,
781        }
782    }
783}
784
785/// Provider outcome classifications, independent of Nautilus mapping support.
786#[derive(Debug, Clone, Copy, PartialEq, Eq)]
787#[pyclass(
788    module = "nautilus_trader.adapters.finfeed",
789    frozen,
790    from_py_object,
791    eq,
792    rename_all = "SCREAMING_SNAKE_CASE"
793)]
794#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
795pub enum FinFeedOutcomeType {
796    /// Binary outcome contract.
797    Binary,
798    /// Multiple-choice outcome contract.
799    MultipleChoice,
800    /// Numeric outcome contract.
801    Numeric,
802    /// Unrecognized provider outcome classification.
803    Other,
804}
805
806impl From<OutcomeType> for FinFeedOutcomeType {
807    fn from(value: OutcomeType) -> Self {
808        match value {
809            OutcomeType::Binary => Self::Binary,
810            OutcomeType::MultipleChoice => Self::MultipleChoice,
811            OutcomeType::Numeric => Self::Numeric,
812            OutcomeType::Other => Self::Other,
813        }
814    }
815}
816
817/// Provider trade-side labels, without aggressor-side inference.
818#[derive(Debug, Clone, Copy, PartialEq, Eq)]
819#[pyclass(
820    module = "nautilus_trader.adapters.finfeed",
821    frozen,
822    from_py_object,
823    eq,
824    rename_all = "SCREAMING_SNAKE_CASE"
825)]
826#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
827pub enum FinFeedTradeSide {
828    /// Provider buy-side label; does not identify the aggressor.
829    Buy,
830    /// Provider sell-side label; does not identify the aggressor.
831    Sell,
832    /// Unrecognized provider trade-side label.
833    Other,
834}
835
836impl From<TradeSide> for FinFeedTradeSide {
837    fn from(value: TradeSide) -> Self {
838        match value {
839            TradeSide::Buy => Self::Buy,
840            TradeSide::Sell => Self::Sell,
841            TradeSide::Other => Self::Other,
842        }
843    }
844}
845
846pub(super) fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
847    m.add_class::<PyFinFeedExchange>()?;
848    m.add_class::<PyFinFeedMarket>()?;
849    m.add_class::<PyFinFeedMarketsPage>()?;
850    m.add_class::<PyFinFeedTrade>()?;
851    m.add_class::<PyFinFeedQuote>()?;
852    m.add_class::<PyFinFeedActivityCurrent>()?;
853    m.add_class::<PyFinFeedActivityBatch>()?;
854    m.add_class::<PyFinFeedBookLevel>()?;
855    m.add_class::<PyFinFeedBook>()?;
856    m.add_class::<PyFinFeedBookEvent>()?;
857    m.add_class::<PyFinFeedOhlcvPeriod>()?;
858    m.add_class::<PyFinFeedOhlcv>()?;
859    m.add_class::<FinFeedMarketStatus>()?;
860    m.add_class::<FinFeedOutcomeType>()?;
861    m.add_class::<FinFeedTradeSide>()?;
862    Ok(())
863}