@@ -74,6 +74,72 @@ def __post_init__(self):
7474 self .external_link = self ._contract ['external_link' ]
7575
7676
77+ @dataclass
78+ class OrderResponse (BaseResponse ):
79+ _json : dict
80+
81+ def __str__ (self ):
82+ return f"{ self .id = } " if self .id else f"{ self .order_hash = } "
83+
84+ def __post_init__ (self ):
85+ self ._set_optional_attrs ()
86+ self ._set_common_attrs ()
87+
88+ @property
89+ def asset (self ) -> 'AssetResponse' :
90+ return AssetResponse (self ._json ['asset' ])
91+
92+ def _set_optional_attrs (self ):
93+ """Depending on the endpoint you use, the Order response object will contain optional attributes."""
94+ self .id : Optional = self ._json .get ('id' ) # id is only provided if you use the OrdersEndpoint
95+ self .asset_bundle = self ._json .get ('asset_bundle' )
96+
97+ def _set_common_attrs (self ):
98+ self .order_hash = self ._json .get ('order_hash' )
99+ self .created_date = self ._json ['created_date' ]
100+ self .closing_date = self ._json ['closing_date' ]
101+ self .closing_extendable = self ._json ['closing_extendable' ]
102+ self .expiration_time = self ._json ['expiration_time' ]
103+ self .listing_time = self ._json ['listing_time' ]
104+ self .order_hash = self ._json ['order_hash' ]
105+ self .exchange = self ._json ['exchange' ]
106+ self .current_price = self ._json ['current_price' ]
107+ self .current_bounty = self ._json ['current_bounty' ]
108+ self .bounty_multiple = self ._json ['bounty_multiple' ]
109+ self .maker_relayer_fee = self ._json ['maker_relayer_fee' ]
110+ self .taker_relayer_fee = self ._json ['taker_relayer_fee' ]
111+ self .maker_protocol_fee = self ._json ['maker_protocol_fee' ]
112+ self .taker_protocol_fee = self ._json ['taker_protocol_fee' ]
113+ self .maker_referrer_fee = self ._json ['maker_referrer_fee' ]
114+ self .fee_method = self ._json ['fee_method' ]
115+ self .side = self ._json ['side' ]
116+ self .sale_kind = self ._json ['sale_kind' ]
117+ self .target = self ._json ['target' ]
118+ self .how_to_call = self ._json ['how_to_call' ]
119+ self .calldata = self ._json ['calldata' ]
120+ self .replacement_pattern = self ._json ['replacement_pattern' ]
121+ self .static_target = self ._json ['static_target' ]
122+ self .static_extradata = self ._json ['static_extradata' ]
123+ self .payment_token = self ._json ['payment_token' ]
124+ self .base_price = self ._json ['base_price' ]
125+ self .extra = self ._json ['extra' ]
126+ self .quantity = self ._json ['quantity' ]
127+ self .salt = self ._json ['salt' ]
128+ self .v = self ._json ['v' ]
129+ self .r = self ._json ['r' ]
130+ self .s = self ._json ['s' ]
131+ self .approved_on_chain = self ._json ['approved_on_chain' ]
132+ self .cancelled = self ._json ['cancelled' ]
133+ self .finalized = self ._json ['finalized' ]
134+ self .marked_invalid = self ._json ['marked_invalid' ]
135+ self .prefixed_hash = self ._json ['prefixed_hash' ]
136+ self .metadata : dict = self ._json ['metadata' ]
137+ self .maker : dict = self ._json ['maker' ]
138+ self .taker : dict = self ._json ['taker' ]
139+ self .fee_recipient : dict = self ._json ['fee_recipient' ]
140+ self .payment_token_contract : dict = self ._json ['payment_token_contract' ]
141+
142+
77143@dataclass
78144class AssetResponse (BaseResponse ):
79145 _json : dict
@@ -112,7 +178,6 @@ def _set_common_attrs(self):
112178 self .is_presale = self ._json .get ("is_presale" )
113179 self .listing_date = self ._json .get ("listing_date" )
114180 self .top_bid = self ._json .get ("top_bid" )
115- self .sell_orders = self ._json .get ("sell_orders" )
116181
117182 @property
118183 def asset_contract (self ) -> _Contract :
@@ -140,6 +205,12 @@ def last_sale(self) -> Optional[_LastSale]:
140205 def collection (self ):
141206 return CollectionResponse (self ._json ['collection' ])
142207
208+ @property
209+ def sell_orders (self ) -> Optional [list [OrderResponse ]]:
210+ if sell_orders := self ._json .get ('sell_orders' ):
211+ return [OrderResponse (order ) for order in sell_orders ]
212+ return None
213+
143214 @property
144215 def creator (self ) -> Optional [dict ]:
145216 return self ._json .get ('creator' )
0 commit comments