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    /// `FinFeedDataLoader` fetches the public metadata needed for Kalshi definitions.
172    /// Other venue families fail until their required field rules are verified.
173    ///
174    /// # Errors
175    ///
176    /// Returns an error if:
177    /// - The venue or contract is unsupported.
178    /// - Required identity or metadata is missing, invalid, or conflicting.
179    /// - The tick is outside `(0, 1)` or the provider price is outside `[0, 1]`.
180    /// - A price requires rounding or expiry is outside the supported timestamp range.
181    #[pyo3(signature = (ts_init=0))]
182    fn to_instrument(&self, ts_init: u64) -> PyResult<BinaryOption> {
183        let ts_init = UnixNanos::from(ts_init);
184        parse_instrument(&self.inner, ts_init).map_err(to_pyvalue_err)
185    }
186}
187
188impl From<Market> for PyFinFeedMarket {
189    fn from(inner: Market) -> Self {
190        Self { inner }
191    }
192}
193
194/// A cursor listing envelope; a missing next cursor establishes termination.
195#[derive(Debug, Clone)]
196#[pyclass(
197    name = "FinFeedMarketsPage",
198    module = "nautilus_trader.adapters.finfeed",
199    frozen,
200    from_py_object
201)]
202#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
203pub struct PyFinFeedMarketsPage {
204    inner: MarketsPage,
205}
206
207#[pymethods]
208#[pyo3_stub_gen::derive::gen_stub_pymethods]
209impl PyFinFeedMarketsPage {
210    /// Outcome definitions for this page; absent or null data remains `None`.
211    #[getter(data)]
212    fn py_data(&self) -> Option<Vec<PyFinFeedMarket>> {
213        self.inner
214            .data
215            .clone()
216            .map(|records| records.into_iter().map(Into::into).collect())
217    }
218
219    /// Continuation cursor; `None` ends traversal.
220    #[getter(next_cursor)]
221    fn py_next_cursor(&self) -> Option<String> {
222        self.inner.next_cursor.clone()
223    }
224}
225
226impl From<MarketsPage> for PyFinFeedMarketsPage {
227    fn from(inner: MarketsPage) -> Self {
228        Self { inner }
229    }
230}
231
232/// A provider trade with exact price and quantity, without aggressor-side inference.
233#[derive(Debug, Clone)]
234#[pyclass(
235    name = "FinFeedTrade",
236    module = "nautilus_trader.adapters.finfeed",
237    frozen,
238    from_py_object
239)]
240#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
241pub struct PyFinFeedTrade {
242    inner: Trade,
243}
244
245#[pymethods]
246#[pyo3_stub_gen::derive::gen_stub_pymethods]
247impl PyFinFeedTrade {
248    /// Provider outcome identifier.
249    #[getter(market_id)]
250    fn py_market_id(&self) -> Option<String> {
251        self.inner.market_id.map(|value| value.to_string())
252    }
253
254    /// Opaque provider trade ID; native conversion requires a nonempty ID.
255    #[getter(id)]
256    fn py_id(&self) -> Option<String> {
257        self.inner.id.clone()
258    }
259
260    /// Provider outcome label, when supplied.
261    #[getter(outcome)]
262    fn py_outcome(&self) -> Option<String> {
263        self.inner.outcome.clone()
264    }
265
266    /// Provider side label; does not identify the aggressor.
267    #[getter(side)]
268    fn py_side(&self) -> FinFeedTradeSide {
269        self.inner.side.into()
270    }
271
272    /// Trade price, decoded without floating-point conversion.
273    #[getter(price)]
274    fn py_price(&self) -> Decimal {
275        self.inner.price
276    }
277
278    /// Trade quantity, decoded without floating-point conversion.
279    #[getter(quantity)]
280    fn py_quantity(&self) -> Decimal {
281        self.inner.quantity
282    }
283
284    /// Sole provider timestamp, used for both native event and initialization times.
285    #[getter(timestamp)]
286    fn py_timestamp(&self) -> String {
287        self.inner.timestamp.to_string()
288    }
289}
290
291impl From<Trade> for PyFinFeedTrade {
292    fn from(inner: Trade) -> Self {
293        Self { inner }
294    }
295}
296
297/// Exact quote prices and sizes, retaining both provider timestamps.
298#[derive(Debug, Clone)]
299#[pyclass(
300    name = "FinFeedQuote",
301    module = "nautilus_trader.adapters.finfeed",
302    frozen,
303    from_py_object
304)]
305#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
306pub struct PyFinFeedQuote {
307    inner: Quote,
308}
309
310#[pymethods]
311#[pyo3_stub_gen::derive::gen_stub_pymethods]
312impl PyFinFeedQuote {
313    /// Bid price, decoded exactly.
314    #[getter(bid)]
315    fn py_bid(&self) -> Decimal {
316        self.inner.bid
317    }
318
319    /// Ask price, decoded exactly.
320    #[getter(ask)]
321    fn py_ask(&self) -> Decimal {
322        self.inner.ask
323    }
324
325    /// Size available at the bid, decoded exactly.
326    #[getter(bid_volume)]
327    fn py_bid_volume(&self) -> Decimal {
328        self.inner.bid_volume
329    }
330
331    /// Size available at the ask, decoded exactly.
332    #[getter(ask_volume)]
333    fn py_ask_volume(&self) -> Decimal {
334        self.inner.ask_volume
335    }
336
337    /// Provider entry timestamp, used as native `ts_event`.
338    #[getter(entry_time)]
339    fn py_entry_time(&self) -> String {
340        self.inner.entry_time.to_string()
341    }
342
343    /// Provider receive timestamp, used as native `ts_init`.
344    #[getter(recv_time)]
345    fn py_recv_time(&self) -> String {
346        self.inner.recv_time.to_string()
347    }
348}
349
350impl From<Quote> for PyFinFeedQuote {
351    fn from(inner: Quote) -> Self {
352        Self { inner }
353    }
354}
355
356/// The latest trade and quote, each independently optional.
357#[derive(Debug, Clone)]
358#[pyclass(
359    name = "FinFeedActivityCurrent",
360    module = "nautilus_trader.adapters.finfeed",
361    frozen,
362    from_py_object
363)]
364#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
365pub struct PyFinFeedActivityCurrent {
366    inner: ActivityCurrent,
367}
368
369#[pymethods]
370#[pyo3_stub_gen::derive::gen_stub_pymethods]
371impl PyFinFeedActivityCurrent {
372    /// Latest quote; absent or null values remain `None`.
373    #[getter(quote)]
374    fn py_quote(&self) -> Option<PyFinFeedQuote> {
375        self.inner.quote.clone().map(Into::into)
376    }
377
378    /// Latest trade; absent or null values remain `None`.
379    #[getter(trade)]
380    fn py_trade(&self) -> Option<PyFinFeedTrade> {
381        self.inner.trade.clone().map(Into::into)
382    }
383}
384
385impl From<ActivityCurrent> for PyFinFeedActivityCurrent {
386    fn from(inner: ActivityCurrent) -> Self {
387        Self { inner }
388    }
389}
390
391/// Latest activity lists, retaining the distinction between absent and empty lists.
392#[derive(Debug, Clone)]
393#[pyclass(
394    name = "FinFeedActivityBatch",
395    module = "nautilus_trader.adapters.finfeed",
396    frozen,
397    from_py_object
398)]
399#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
400pub struct PyFinFeedActivityBatch {
401    inner: ActivityBatch,
402}
403
404#[pymethods]
405#[pyo3_stub_gen::derive::gen_stub_pymethods]
406impl PyFinFeedActivityBatch {
407    /// Quote list, independently bounded by the activity query limit.
408    #[getter(quotes)]
409    fn py_quotes(&self) -> Option<Vec<PyFinFeedQuote>> {
410        self.inner
411            .quotes
412            .clone()
413            .map(|records| records.into_iter().map(Into::into).collect())
414    }
415
416    /// Trade list, independently bounded by the activity query limit.
417    #[getter(trades)]
418    fn py_trades(&self) -> Option<Vec<PyFinFeedTrade>> {
419        self.inner
420            .trades
421            .clone()
422            .map(|records| records.into_iter().map(Into::into).collect())
423    }
424}
425
426impl From<ActivityBatch> for PyFinFeedActivityBatch {
427    fn from(inner: ActivityBatch) -> Self {
428        Self { inner }
429    }
430}
431
432/// A snapshot price level with exact size.
433#[derive(Debug, Clone)]
434#[pyclass(
435    name = "FinFeedBookLevel",
436    module = "nautilus_trader.adapters.finfeed",
437    frozen,
438    from_py_object
439)]
440#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
441pub struct PyFinFeedBookLevel {
442    inner: BookLevel,
443}
444
445#[pymethods]
446#[pyo3_stub_gen::derive::gen_stub_pymethods]
447impl PyFinFeedBookLevel {
448    /// Price of the aggregated level, decoded exactly.
449    #[getter(price)]
450    fn py_price(&self) -> Decimal {
451        self.inner.price
452    }
453
454    /// Size of the aggregated level, decoded exactly.
455    #[getter(size)]
456    fn py_size(&self) -> Decimal {
457        self.inner.size
458    }
459}
460
461impl From<BookLevel> for PyFinFeedBookLevel {
462    fn from(inner: BookLevel) -> Self {
463        Self { inner }
464    }
465}
466
467/// A raw current snapshot with nullable sides, without continuity or recovery inference.
468#[derive(Debug, Clone)]
469#[pyclass(
470    name = "FinFeedBook",
471    module = "nautilus_trader.adapters.finfeed",
472    frozen,
473    from_py_object
474)]
475#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
476pub struct PyFinFeedBook {
477    inner: Book,
478}
479
480#[pymethods]
481#[pyo3_stub_gen::derive::gen_stub_pymethods]
482impl PyFinFeedBook {
483    /// Provider exchange identifier.
484    #[getter(exchange_id)]
485    fn py_exchange_id(&self) -> Option<String> {
486        self.inner.exchange_id.map(|value| value.to_string())
487    }
488
489    /// Provider outcome identifier.
490    #[getter(market_id)]
491    fn py_market_id(&self) -> Option<String> {
492        self.inner.market_id.map(|value| value.to_string())
493    }
494
495    /// Bid levels; `None` remains distinct from an empty side.
496    #[getter(bids)]
497    fn py_bids(&self) -> Option<Vec<PyFinFeedBookLevel>> {
498        self.inner
499            .bids
500            .clone()
501            .map(|records| records.into_iter().map(Into::into).collect())
502    }
503
504    /// Ask levels; `None` remains distinct from an empty side.
505    #[getter(asks)]
506    fn py_asks(&self) -> Option<Vec<PyFinFeedBookLevel>> {
507        self.inner
508            .asks
509            .clone()
510            .map(|records| records.into_iter().map(Into::into).collect())
511    }
512
513    /// Exchange timestamp, used as native `ts_event`.
514    #[getter(time_exchange)]
515    fn py_time_exchange(&self) -> String {
516        self.inner.time_exchange.to_string()
517    }
518
519    /// Provider receive timestamp, used as native `ts_init`.
520    #[getter(time_coinapi)]
521    fn py_time_coinapi(&self) -> String {
522        self.inner.time_coinapi.to_string()
523    }
524}
525
526impl From<Book> for PyFinFeedBook {
527    fn from(inner: Book) -> Self {
528        Self { inner }
529    }
530}
531
532/// A raw historical book event with uninterpreted numeric actions and provider ordering.
533#[derive(Debug, Clone)]
534#[pyclass(
535    name = "FinFeedBookEvent",
536    module = "nautilus_trader.adapters.finfeed",
537    frozen,
538    from_py_object
539)]
540#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
541pub struct PyFinFeedBookEvent {
542    inner: BookEvent,
543}
544
545#[pymethods]
546#[pyo3_stub_gen::derive::gen_stub_pymethods]
547impl PyFinFeedBookEvent {
548    /// Provider symbol identifier, retained verbatim.
549    #[getter(symbol_id)]
550    fn py_symbol_id(&self) -> String {
551        self.inner.symbol_id.to_string()
552    }
553
554    /// Provider event identifier, retained verbatim.
555    #[getter(id)]
556    fn py_id(&self) -> String {
557        self.inner.id.clone()
558    }
559
560    /// Raw numeric action code, interpreted only during native L2 replay.
561    #[getter(update_type)]
562    fn py_update_type(&self) -> i64 {
563        self.inner.update_type
564    }
565
566    /// Whether the event applies to the ask side.
567    #[getter(is_sell_ask)]
568    fn py_is_sell_ask(&self) -> bool {
569        self.inner.is_sell_ask
570    }
571
572    /// Raw event price, decoded exactly.
573    #[getter(price)]
574    fn py_price(&self) -> Decimal {
575        self.inner.price
576    }
577
578    /// Raw event size; absolute or relative meaning depends on the action.
579    #[getter(size)]
580    fn py_size(&self) -> Decimal {
581        self.inner.size
582    }
583
584    /// Exchange event timestamp.
585    #[getter(time_exchange)]
586    fn py_time_exchange(&self) -> String {
587        self.inner.time_exchange.to_string()
588    }
589
590    /// Optional provider processing timestamp; omissions remain `None`.
591    #[getter(time_coinapi)]
592    fn py_time_coinapi(&self) -> Option<String> {
593        self.inner.time_coinapi.map(|time| time.to_string())
594    }
595}
596
597impl From<BookEvent> for PyFinFeedBookEvent {
598    fn from(inner: BookEvent) -> Self {
599        Self { inner }
600    }
601}
602
603/// A provider OHLCV period definition.
604#[derive(Debug, Clone)]
605#[pyclass(
606    name = "FinFeedOhlcvPeriod",
607    module = "nautilus_trader.adapters.finfeed",
608    frozen,
609    from_py_object
610)]
611#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
612pub struct PyFinFeedOhlcvPeriod {
613    inner: OhlcvPeriod,
614}
615
616#[pymethods]
617#[pyo3_stub_gen::derive::gen_stub_pymethods]
618impl PyFinFeedOhlcvPeriod {
619    /// Provider identifier accepted by DB-backed OHLCV queries.
620    #[getter(period_id)]
621    fn py_period_id(&self) -> Option<String> {
622        self.inner.period_id.map(|value| value.to_string())
623    }
624
625    /// Provider unit label.
626    #[getter(unit_name)]
627    fn py_unit_name(&self) -> Option<String> {
628        self.inner.unit_name.map(|value| value.to_string())
629    }
630
631    /// Number of units in the provider period definition.
632    #[getter(unit_count)]
633    fn py_unit_count(&self) -> Option<i32> {
634        self.inner.unit_count
635    }
636
637    /// Fixed period length in seconds.
638    #[getter(length_seconds)]
639    fn py_length_seconds(&self) -> i32 {
640        self.inner.length_seconds
641    }
642
643    /// Calendar period length in months.
644    #[getter(length_months)]
645    fn py_length_months(&self) -> i32 {
646        self.inner.length_months
647    }
648
649    /// Provider display label for the period.
650    #[getter(display_name)]
651    fn py_display_name(&self) -> Option<String> {
652        self.inner.display_name.map(|value| value.to_string())
653    }
654}
655
656impl From<OhlcvPeriod> for PyFinFeedOhlcvPeriod {
657    fn from(inner: OhlcvPeriod) -> Self {
658        Self { inner }
659    }
660}
661
662/// A provider bar with nullable prices, exact aggregate volume, and an optional raw market identifier.
663#[derive(Debug, Clone)]
664#[pyclass(
665    name = "FinFeedOhlcv",
666    module = "nautilus_trader.adapters.finfeed",
667    frozen,
668    from_py_object
669)]
670#[pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.finfeed")]
671pub struct PyFinFeedOhlcv {
672    inner: Ohlcv,
673}
674
675#[pymethods]
676#[pyo3_stub_gen::derive::gen_stub_pymethods]
677impl PyFinFeedOhlcv {
678    /// Raw outcome identifier; exchange-wide history can include unknown or missing IDs.
679    #[getter(market_id_exchange)]
680    fn py_market_id_exchange(&self) -> Option<String> {
681        self.inner.market_id_exchange.map(|value| value.to_string())
682    }
683
684    /// Opening price; absent or null values remain `None`.
685    #[getter(price_open)]
686    fn py_price_open(&self) -> Option<Decimal> {
687        self.inner.price_open
688    }
689
690    /// Highest price; absent or null values remain `None`.
691    #[getter(price_high)]
692    fn py_price_high(&self) -> Option<Decimal> {
693        self.inner.price_high
694    }
695
696    /// Lowest price; absent or null values remain `None`.
697    #[getter(price_low)]
698    fn py_price_low(&self) -> Option<Decimal> {
699        self.inner.price_low
700    }
701
702    /// Closing price; absent or null values remain `None`.
703    #[getter(price_close)]
704    fn py_price_close(&self) -> Option<Decimal> {
705        self.inner.price_close
706    }
707
708    /// Provider aggregate volume, decoded without floating-point conversion.
709    #[getter(volume_traded)]
710    fn py_volume_traded(&self) -> Decimal {
711        self.inner.volume_traded
712    }
713
714    /// Provider-reported trade count.
715    #[getter(trades_count)]
716    fn py_trades_count(&self) -> i64 {
717        self.inner.trades_count
718    }
719
720    /// Period start timestamp.
721    #[getter(time_period_start)]
722    fn py_time_period_start(&self) -> String {
723        self.inner.time_period_start.to_string()
724    }
725
726    /// Period end timestamp, used for both native bar timestamps.
727    #[getter(time_period_end)]
728    fn py_time_period_end(&self) -> String {
729        self.inner.time_period_end.to_string()
730    }
731
732    /// Provider timestamp of the opening observation, when supplied.
733    #[getter(time_open)]
734    fn py_time_open(&self) -> Option<String> {
735        self.inner.time_open.map(|time| time.to_string())
736    }
737
738    /// Provider timestamp of the closing observation, when supplied.
739    #[getter(time_close)]
740    fn py_time_close(&self) -> Option<String> {
741        self.inner.time_close.map(|time| time.to_string())
742    }
743}
744
745impl From<Ohlcv> for PyFinFeedOhlcv {
746    fn from(inner: Ohlcv) -> Self {
747        Self { inner }
748    }
749}
750
751/// Provider lifecycle labels, without settlement inference.
752#[derive(Debug, Clone, Copy, PartialEq, Eq)]
753#[pyclass(
754    module = "nautilus_trader.adapters.finfeed",
755    frozen,
756    from_py_object,
757    eq,
758    rename_all = "SCREAMING_SNAKE_CASE"
759)]
760#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
761pub enum FinFeedMarketStatus {
762    /// Provider labels the market open.
763    Open,
764    /// Provider labels the market closed; this is not a settlement event.
765    Closed,
766    /// Provider labels the market resolved; no payout is inferred.
767    Resolved,
768    /// Provider labels the market suspended.
769    Suspended,
770    /// Unrecognized provider lifecycle label.
771    Unknown,
772}
773
774impl From<MarketStatus> for FinFeedMarketStatus {
775    fn from(value: MarketStatus) -> Self {
776        match value {
777            MarketStatus::Open => Self::Open,
778            MarketStatus::Closed => Self::Closed,
779            MarketStatus::Resolved => Self::Resolved,
780            MarketStatus::Suspended => Self::Suspended,
781            MarketStatus::Unknown => Self::Unknown,
782        }
783    }
784}
785
786/// Provider outcome classifications, independent of Nautilus mapping support.
787#[derive(Debug, Clone, Copy, PartialEq, Eq)]
788#[pyclass(
789    module = "nautilus_trader.adapters.finfeed",
790    frozen,
791    from_py_object,
792    eq,
793    rename_all = "SCREAMING_SNAKE_CASE"
794)]
795#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
796pub enum FinFeedOutcomeType {
797    /// Binary outcome contract.
798    Binary,
799    /// Multiple-choice outcome contract.
800    MultipleChoice,
801    /// Numeric outcome contract.
802    Numeric,
803    /// Unrecognized provider outcome classification.
804    Other,
805}
806
807impl From<OutcomeType> for FinFeedOutcomeType {
808    fn from(value: OutcomeType) -> Self {
809        match value {
810            OutcomeType::Binary => Self::Binary,
811            OutcomeType::MultipleChoice => Self::MultipleChoice,
812            OutcomeType::Numeric => Self::Numeric,
813            OutcomeType::Other => Self::Other,
814        }
815    }
816}
817
818/// Provider trade-side labels, without aggressor-side inference.
819#[derive(Debug, Clone, Copy, PartialEq, Eq)]
820#[pyclass(
821    module = "nautilus_trader.adapters.finfeed",
822    frozen,
823    from_py_object,
824    eq,
825    rename_all = "SCREAMING_SNAKE_CASE"
826)]
827#[pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.adapters.finfeed")]
828pub enum FinFeedTradeSide {
829    /// Provider buy-side label; does not identify the aggressor.
830    Buy,
831    /// Provider sell-side label; does not identify the aggressor.
832    Sell,
833    /// Unrecognized provider trade-side label.
834    Other,
835}
836
837impl From<TradeSide> for FinFeedTradeSide {
838    fn from(value: TradeSide) -> Self {
839        match value {
840            TradeSide::Buy => Self::Buy,
841            TradeSide::Sell => Self::Sell,
842            TradeSide::Other => Self::Other,
843        }
844    }
845}
846
847pub(super) fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
848    m.add_class::<PyFinFeedExchange>()?;
849    m.add_class::<PyFinFeedMarket>()?;
850    m.add_class::<PyFinFeedMarketsPage>()?;
851    m.add_class::<PyFinFeedTrade>()?;
852    m.add_class::<PyFinFeedQuote>()?;
853    m.add_class::<PyFinFeedActivityCurrent>()?;
854    m.add_class::<PyFinFeedActivityBatch>()?;
855    m.add_class::<PyFinFeedBookLevel>()?;
856    m.add_class::<PyFinFeedBook>()?;
857    m.add_class::<PyFinFeedBookEvent>()?;
858    m.add_class::<PyFinFeedOhlcvPeriod>()?;
859    m.add_class::<PyFinFeedOhlcv>()?;
860    m.add_class::<FinFeedMarketStatus>()?;
861    m.add_class::<FinFeedOutcomeType>()?;
862    m.add_class::<FinFeedTradeSide>()?;
863    Ok(())
864}