Created
September 4, 2023 02:27
-
-
Save riven314/0e873c09dad41f013abcccc6833d005d to your computer and use it in GitHub Desktop.
process_manager_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_manager( | |
self, | |
trading_pair: str, | |
timestamp: float, | |
manager: Union[helper.ShiftOrderManager, helper.OffsetShiftOrderManager], | |
pending_offset_jobs: helper.PendingOffsetJobs, | |
) -> None: | |
manager_name = manager.__class__.__name__ | |
maker_exchange = self.maker_exchange | |
# skip condition applicable to both manager | |
if self.should_skip_process_manager(manager, trading_pair, timestamp): | |
self.logger().info( | |
f"[M: {maker_exchange}, {trading_pair}] Skip processing {manager_name} for this on_tick." | |
) | |
return | |
if isinstance(manager, helper.ShiftOrderManager): | |
# skip ShiftOrderManager if it accumulates too many offset jobs incompleted | |
if self.is_too_many_pending_offset_jobs(pending_offset_jobs): | |
self.logger().info( | |
f"[M: {maker_exchange}, {trading_pair}] There are too many pending offset jobs, stop {manager_name} from placing maker orders." | |
) | |
return | |
# skip ShiftOrderManager if price shift on ask book is not favorable | |
if self.is_bad_price_shift_for_shift_order_manager(trading_pair): | |
self.logger().info( | |
f"[M: {maker_exchange}, {trading_pair}] Current price shift is bad for {manager_name} to place maker ask, " | |
"because maker best ask price is not high enough than the taker hedge buy price." | |
) | |
return | |
else: | |
# skip OffsetShiftOrderManager if there is no pending offset job | |
if pending_offset_jobs.is_empty(): | |
self.logger().info( | |
f"[M: {maker_exchange}, {trading_pair}] There are no pending offset jobs. Skip processing its {manager_name}." | |
) | |
return | |
# check if manager has made any maker order | |
if manager.is_idle() is None: | |
if ( | |
isinstance(manager, helper.OffsetShiftOrderManager) | |
and not pending_offset_jobs.is_empty() | |
): | |
self._assign_job_to_offset_shift_order_manager( | |
trading_pair, manager, pending_offset_jobs | |
) | |
self.check_and_create_maker_order( | |
trading_pair, is_maker_buy=True, manager=manager | |
) | |
elif isinstance(manager, helper.ShiftOrderManager): | |
self.check_and_create_maker_order( | |
trading_pair, is_maker_buy=False, manager=manager | |
) | |
# check if existing maker order need to be replaced | |
else: | |
self.check_and_cancel_maker_order( | |
trading_pair, manager=manager, timestamp=timestamp | |
) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment