def __init__(self, trading_calendar:TradingCalendar, emit_frequency:int, queue:ClockQueue=None): check_input(RealtimeClock.__init__, locals()) super(RealtimeClock,self).__init__(trading_calendar, emit_frequency) self.clock_state = None self.last_emitted = None self.reset(queue,emit_frequency)
def _create(self, name: str = "fxcm", broker_type: BrokerType = BrokerType.RESTBROKER, calendar: TradingCalendar = None, **kwargs): check_input(FXCMBroker.__init__, locals()) super(self.__class__, self).__init__(name, broker_type, calendar, **kwargs) self._mode_supports = [MODE.LIVE] self._auth = kwargs.pop("auth", None) self._asset_finder = kwargs.pop("asset_finder", None) self._api = None if not self._asset_finder: msg = "Broker needs a corresponding Asset Finder" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) if not self._auth: msg = "authentication and API missing" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) if not self._trading_calendar: self._trading_calendar = self._auth._trading_calendar if self._auth.__class__ != FXCMAuth.cls: msg = "invalid authentication object" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) self._api = self._auth._api if self._api.__class__ != FXCMPy.cls: msg = "invalid kite API object" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) self._closed_orders = {} # list of closed/ cancelled orders self._open_orders = {} # list of open orders self._missing_orders = {} # track missing orders to be updated self._open_positions = {} # track open positions self._closed_positions = [] # closed poistions self._processed_positions = [] # track positions already processed self._trading_cache = {} # cache to validate close order self._account = ForexAccount(self._name, 0.01)
def _create(self, name: str = "kite", broker_type: BrokerType = BrokerType.RESTBROKER, calendar: TradingCalendar = None, **kwargs): check_input(KiteBroker.__init__, locals()) super(self.__class__, self).__init__(name, broker_type, calendar, **kwargs) self._mode_supports = [MODE.LIVE] self._auth = kwargs.pop("auth", None) self._asset_finder = kwargs.pop("asset_finder", None) self._api = None if not self._asset_finder: msg = "Broker needs a corresponding Asset Finder" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) if not self._auth: msg = "authentication and API missing" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) if not self._trading_calendar: self._trading_calendar = self._auth._trading_calendar if self._auth.__class__ != KiteAuth.cls: msg = "invalid authentication object" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) self._api = self._auth._api if self._api.__class__ != KiteConnect3.cls: msg = "invalid kite API object" handling = ExceptionHandling.TERMINATE raise AuthenticationError(msg=msg, handling=handling) self._closed_orders = {} self._open_orders = {} self._open_positions = {} self._closed_positions = [] self._account = EquityAccount(self._name, 0.01)
def __init__(self, name: str, broker_type: BrokerType, calendar: TradingCalendar, initial_capital: positive_num, **kwargs): check_input(BackTesterAPI.__init__, locals()) super(BackTesterAPI, self).__init__(name, broker_type, calendar, **kwargs) self._mode_supports = [MODE.BACKTEST] api = kwargs.get("broker", None) if api: if isinstance(api, BackTester): self._api = api else: self._api = BackTester(name, calendar, initial_capital) else: self._api = BackTester(name, calendar, initial_capital) self._trading_calendar = calendar self.initial_capital = initial_capital self._name = name # backtester is always connected self._connected = True
def from_json(cls, jsonstr: str): check_input(cls.from_json, locals()) d = json.loads(jsonstr) return cls(**d)
def sid(self, sec_id: int): ''' API function to resolve an asset ID (int) to an asset. ''' check_input(self.sid, locals()) return self.context.asset_finder.fetch_asset(sec_id)
def symbol(self, symbol_str: str): ''' API function to resolve a symbol string to an asset. ''' check_input(self.symbol, locals()) return self.context.asset_finder.lookup_symbol(symbol_str)
def order(x: str,y = 0): check_input(order, locals())
def from_json(cls, jsonstr: str): check_input(cls.from_json, locals()) d = json.loads(jsonstr) return cls(d['name'], d['tz'], d['opens'], d['closes'], d['bizdays'], d['weekends'])