| 370 | |
| 371 | @functools.total_ordering |
| 372 | class Order(object): |
| 373 | __slots__ = "id", "symbol", "side", "type", "price", "volume", |
| 374 | |
| 375 | def __init__(self, id=0, symbol="", side=None, type=None, price=float(0.0), volume=float(0.0)): |
| 376 | if side is None: |
| 377 | side = OrderSide() |
| 378 | if type is None: |
| 379 | type = OrderType() |
| 380 | self.id = id |
| 381 | self.symbol = symbol |
| 382 | self.side = side |
| 383 | self.type = type |
| 384 | self.price = price |
| 385 | self.volume = volume |
| 386 | |
| 387 | # Struct shallow copy |
| 388 | def copy(self, other): |
| 389 | self.id = other.id |
| 390 | self.symbol = other.symbol |
| 391 | self.side = other.side |
| 392 | self.type = other.type |
| 393 | self.price = other.price |
| 394 | self.volume = other.volume |
| 395 | return self |
| 396 | |
| 397 | # Struct deep clone |
| 398 | def clone(self): |
| 399 | # Serialize the struct to the FBE stream |
| 400 | writer = OrderModel(fbe.WriteBuffer()) |
| 401 | writer.serialize(self) |
| 402 | |
| 403 | # Deserialize the struct from the FBE stream |
| 404 | reader = OrderModel(fbe.ReadBuffer()) |
| 405 | reader.attach_buffer(writer.buffer) |
| 406 | return reader.deserialize()[0] |
| 407 | |
| 408 | def __eq__(self, other): |
| 409 | if not isinstance(self, other.__class__): |
| 410 | return NotImplemented |
| 411 | if not self.id == other.id: |
| 412 | return False |
| 413 | return True |
| 414 | |
| 415 | def __lt__(self, other): |
| 416 | if not isinstance(self, other.__class__): |
| 417 | return NotImplemented |
| 418 | if self.id < other.id: |
| 419 | return True |
| 420 | if self.id == other.id: |
| 421 | return False |
| 422 | return False |
| 423 | |
| 424 | @property |
| 425 | def __key__(self): |
| 426 | return self.id, |
| 427 | |
| 428 | def __hash__(self): |
| 429 | return hash(self.__key__) |
no outgoing calls
no test coverage detected