diff --git a/mango/marketmaking/marketmaker.py b/mango/marketmaking/marketmaker.py index 95bceb7..01cd934 100644 --- a/mango/marketmaking/marketmaker.py +++ b/mango/marketmaking/marketmaker.py @@ -62,7 +62,7 @@ class MarketMaker: cancellations = mango.CombinableInstructions.empty() for to_cancel in reconciled.to_cancel: - self.logger.info(f"Cancelling {to_cancel}") + self.logger.info(f"Cancelling {self.market.symbol} {to_cancel}") cancel = self.market_instruction_builder.build_cancel_order_instructions(to_cancel) cancellations += cancel @@ -72,7 +72,7 @@ class MarketMaker: to_place_with_client_id = to_place.with_client_id(desired_client_id) self.order_tracker.track(to_place_with_client_id) - self.logger.info(f"Placing {to_place_with_client_id}") + self.logger.info(f"Placing {self.market.symbol} {to_place_with_client_id}") place_order = self.market_instruction_builder.build_place_order_instructions(to_place_with_client_id) place_orders += place_order diff --git a/mango/marketoperations.py b/mango/marketoperations.py index 1d37841..58ead21 100644 --- a/mango/marketoperations.py +++ b/mango/marketoperations.py @@ -95,14 +95,14 @@ class NullMarketOperations(MarketOperations): self.market_name: str = market_name def cancel_order(self, order: Order) -> typing.Sequence[str]: - self.logger.info( - f"Cancelling order {order.id} for quantity {order.quantity} at price {order.price} on market {self.market_name} with client ID {order.client_id}.") + self.logger.info(f"Cancelling order {order}.") return [""] def place_order(self, side: Side, order_type: OrderType, price: Decimal, quantity: Decimal) -> Order: - self.logger.info( - f"Placing {order_type} {side} order for quantity {quantity} at price {price} on market {self.market_name}.") - return Order(id=0, side=side, price=price, quantity=quantity, client_id=0, owner=SYSTEM_PROGRAM_ADDRESS, order_type=order_type) + order: Order = Order(id=0, side=side, price=price, quantity=quantity, client_id=0, + owner=SYSTEM_PROGRAM_ADDRESS, order_type=order_type) + self.logger.info(f"Placing order {order}.") + return order def load_orders(self) -> typing.Sequence[Order]: return [] diff --git a/mango/orders.py b/mango/orders.py index 2c6d50c..4ef146e 100644 --- a/mango/orders.py +++ b/mango/orders.py @@ -116,7 +116,13 @@ class Order(typing.NamedTuple): return Order(id=id, client_id=client_id, owner=SYSTEM_PROGRAM_ADDRESS, side=side, price=Decimal(0), quantity=Decimal(0), order_type=OrderType.UNKNOWN) def __str__(self): - return f"Β« π™Ύπš›πšπšŽπš› [{self.owner}] {self.side} for {self.quantity:,.8f} at {self.price:.8f} [ID: {self.id} / {self.client_id}] {self.order_type} Β»" + owner: str = "" + if self.owner != SYSTEM_PROGRAM_ADDRESS: + owner = f"[{self.owner}] " + order_type: str = "" + if self.order_type != OrderType.UNKNOWN: + order_type = f" {self.order_type}" + return f"Β« π™Ύπš›πšπšŽπš› {owner}{self.side} for {self.quantity:,.8f} at {self.price:.8f} [ID: {self.id} / {self.client_id}]{order_type} Β»" def __repr__(self) -> str: return f"{self}" diff --git a/mango/perpmarketoperations.py b/mango/perpmarketoperations.py index 40c79e9..2af7a30 100644 --- a/mango/perpmarketoperations.py +++ b/mango/perpmarketoperations.py @@ -51,21 +51,18 @@ class PerpMarketOperations(MarketOperations): self.perp_market: PerpMarket = perp_market def cancel_order(self, order: Order) -> typing.Sequence[str]: - self.logger.info( - f"Cancelling order {order.id} for quantity {order.quantity} at price {order.price} on market {self.market_name} with client ID {order.client_id}.") + self.logger.info(f"Cancelling {self.market_name} order {order}.") signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) - cancel = self.market_instruction_builder.build_cancel_order_instructions(order) + cancel: CombinableInstructions = self.market_instruction_builder.build_cancel_order_instructions(order) return (signers + cancel).execute_and_unwrap_transaction_ids(self.context) def place_order(self, side: Side, order_type: OrderType, price: Decimal, quantity: Decimal) -> Order: client_id: int = self.context.random_client_id() - self.logger.info( - f"Placing {order_type} {side} order for quantity {quantity} at price {price} on market {self.market_name} with ID {client_id}.") - signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) - order = Order(id=0, client_id=client_id, owner=self.account.address, - side=side, price=price, quantity=quantity, order_type=order_type) - place = self.market_instruction_builder.build_place_order_instructions(order) + order: Order = Order(id=0, client_id=client_id, owner=self.account.address, + side=side, price=price, quantity=quantity, order_type=order_type) + self.logger.info(f"Placing {self.market_name} order {order}.") + place: CombinableInstructions = self.market_instruction_builder.build_place_order_instructions(order) (signers + place).execute(self.context) return order diff --git a/mango/serummarketoperations.py b/mango/serummarketoperations.py index cb32227..6109ed1 100644 --- a/mango/serummarketoperations.py +++ b/mango/serummarketoperations.py @@ -51,32 +51,29 @@ class SerumMarketOperations(MarketOperations): self.market_instruction_builder: SerumMarketInstructionBuilder = market_instruction_builder def cancel_order(self, order: Order) -> typing.Sequence[str]: - self.logger.info( - f"Cancelling order {order.id} for quantity {order.quantity} at price {order.price} on market {self.serum_market.symbol} with client ID {order.client_id}.") + self.logger.info(f"Cancelling {self.serum_market.symbol} order {order}.") signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) - cancel = self.market_instruction_builder.build_cancel_order_instructions(order) + cancel: CombinableInstructions = self.market_instruction_builder.build_cancel_order_instructions(order) open_orders_to_crank: typing.Sequence[PublicKey] = fetch_market_open_orders_addresses_to_crank( self.context, self.raw_market) - crank = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) - settle = self.market_instruction_builder.build_settle_instructions() + crank: CombinableInstructions = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) + settle: CombinableInstructions = self.market_instruction_builder.build_settle_instructions() return (signers + cancel + crank + settle).execute_and_unwrap_transaction_ids(self.context) def place_order(self, side: Side, order_type: OrderType, price: Decimal, quantity: Decimal) -> Order: client_id: int = self.context.random_client_id() - self.logger.info( - f"Placing {order_type} {side} order for quantity {quantity} at price {price} on market {self.serum_market.symbol} with client ID {client_id}.") - signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) open_orders_address = self.market_instruction_builder.open_orders_address or SYSTEM_PROGRAM_ADDRESS - order = Order(id=0, client_id=client_id, side=side, price=price, - quantity=quantity, owner=open_orders_address, order_type=order_type) - place = self.market_instruction_builder.build_place_order_instructions(order) + order: Order = Order(id=0, client_id=client_id, side=side, price=price, + quantity=quantity, owner=open_orders_address, order_type=order_type) + self.logger.info(f"Placing {self.serum_market.symbol} order {order}.") + place: CombinableInstructions = self.market_instruction_builder.build_place_order_instructions(order) open_orders_to_crank: typing.Sequence[PublicKey] = fetch_market_open_orders_addresses_to_crank( self.context, self.raw_market) - crank = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) + crank: CombinableInstructions = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) - settle = self.market_instruction_builder.build_settle_instructions() + settle: CombinableInstructions = self.market_instruction_builder.build_settle_instructions() (signers + place + crank + settle).execute(self.context) return order diff --git a/mango/spotmarketoperations.py b/mango/spotmarketoperations.py index 93a114f..d2590e2 100644 --- a/mango/spotmarketoperations.py +++ b/mango/spotmarketoperations.py @@ -56,32 +56,29 @@ class SpotMarketOperations(MarketOperations): self.open_orders_address = self.account.spot_open_orders[self.market_index] def cancel_order(self, order: Order) -> typing.Sequence[str]: - self.logger.info( - f"Cancelling order {order.id} for quantity {order.quantity} at price {order.price} on market {self.spot_market.symbol} with client ID {order.client_id}.") + self.logger.info(f"Cancelling {self.spot_market.symbol} order {order}.") signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) - cancel = self.market_instruction_builder.build_cancel_order_instructions(order) + cancel: CombinableInstructions = self.market_instruction_builder.build_cancel_order_instructions(order) open_orders_to_crank: typing.Sequence[PublicKey] = fetch_market_open_orders_addresses_to_crank( self.context, self.raw_market) - crank = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) - # settle = self.market_instruction_builder.build_settle_instructions() + crank: CombinableInstructions = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) + settle: CombinableInstructions = self.market_instruction_builder.build_settle_instructions() - return (signers + cancel + crank).execute(self.context) + return (signers + cancel + crank + settle).execute(self.context) def place_order(self, side: Side, order_type: OrderType, price: Decimal, quantity: Decimal) -> Order: client_id: int = self.context.random_client_id() - self.logger.info( - f"Placing {order_type} {side} order for quantity {quantity} at price {price} on market {self.spot_market.symbol} with ID {client_id}.") - signers: CombinableInstructions = CombinableInstructions.from_wallet(self.wallet) - order = Order(id=0, client_id=client_id, side=side, price=price, - quantity=quantity, owner=self.open_orders_address, order_type=order_type) - place = self.market_instruction_builder.build_place_order_instructions(order) + order: Order = Order(id=0, client_id=client_id, side=side, price=price, + quantity=quantity, owner=self.open_orders_address, order_type=order_type) + self.logger.info(f"Placing {self.spot_market.symbol} order {order}.") + place: CombinableInstructions = self.market_instruction_builder.build_place_order_instructions(order) open_orders_to_crank: typing.Sequence[PublicKey] = fetch_market_open_orders_addresses_to_crank( self.context, self.raw_market) - crank = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) - # settle = self.market_instruction_builder.build_settle_instructions() + crank: CombinableInstructions = self.market_instruction_builder.build_crank_instructions(open_orders_to_crank) + settle: CombinableInstructions = self.market_instruction_builder.build_settle_instructions() - (signers + place + crank).execute(self.context) + (signers + place + crank + settle).execute(self.context) return order