예제 #1
0
 def __init__(self,
              time_slot=None,
              bc=None,
              notification_listener=None,
              readonly=False,
              transfer_fees: TransferFees = None,
              name=None):
     self.name = name
     self.bc = bc
     self.id = str(uuid.uuid4())
     self.time_slot = time_slot
     self.time_slot_str = time_slot.format(DATE_TIME_FORMAT) \
         if self.time_slot is not None \
         else None
     self.readonly = readonly
     # offer-id -> Offer
     self.offers = {}  # type: Dict[str, Offer]
     self.offer_history = []  # type: List[Offer]
     self.notification_listeners = []
     self.bids = {}  # type: Dict[str, Bid]
     self.bid_history = []  # type: List[Bid]
     self.trades = []  # type: List[Trade]
     self.transfer_fee_ratio = transfer_fees.grid_fee_percentage / 100 \
         if transfer_fees is not None else 0
     self.transfer_fee_const = transfer_fees.transfer_fee_const \
         if transfer_fees is not None else 0
     self.market_fee = 0
     # Store trades temporarily until bc event has fired
     self.traded_energy = {}
     self.accumulated_actual_energy_agg = {}
     self.min_trade_price = sys.maxsize
     self._avg_trade_price = None
     self.max_trade_price = 0
     self.min_offer_price = sys.maxsize
     self._avg_offer_price = None
     self.max_offer_price = 0
     self.accumulated_trade_price = 0
     self.accumulated_trade_energy = 0
     if ConstSettings.GeneralSettings.EVENT_DISPATCHING_VIA_REDIS:
         self.redis_publisher = MarketRedisEventPublisher(self.id)
     elif notification_listener:
         self.notification_listeners.append(notification_listener)
     self.current_tick = 0
     self.device_registry = DeviceRegistry.REGISTRY
     if ConstSettings.GeneralSettings.EVENT_DISPATCHING_VIA_REDIS:
         self.redis_api = MarketRedisEventSubscriber(self) \
             if ConstSettings.IAASettings.MARKET_TYPE == 1 \
             else TwoSidedMarketRedisEventSubscriber(self)
     setattr(self, RLOCK_MEMBER_NAME, RLock())
 def setUp(self):
     self.publisher = MarketRedisEventPublisher("test_id")