コード例 #1
0
ファイル: clock.py プロジェクト: rahulmr/Learning_cython
 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)
コード例 #2
0
ファイル: fxcmbroker.py プロジェクト: Sdoof/blueshift
    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)
コード例 #3
0
ファイル: kitebroker.py プロジェクト: Sdoof/blueshift
    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)
コード例 #4
0
ファイル: backtester.py プロジェクト: rahulmr/Learning_cython
    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
コード例 #5
0
ファイル: assets.py プロジェクト: rahulmr/Learning_cython
 def from_json(cls, jsonstr: str):
     check_input(cls.from_json, locals())
     d = json.loads(jsonstr)
     return cls(**d)
コード例 #6
0
ファイル: algorithm.py プロジェクト: rahulmr/Learning_cython
 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)
コード例 #7
0
ファイル: algorithm.py プロジェクト: rahulmr/Learning_cython
 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)
コード例 #8
0
def order(x: str,y = 0):
    check_input(order, locals())
コード例 #9
0
    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'])