Ejemplo n.º 1
0
    def __init__(self, logger_name):
        ServiceBase.__init__(self, logger_name)

        # servie id used for control
        # self.sid = 'sid002'

        # SUB data
        self.deribitmsgclient = self.ctx.socket(zmq.SUB)
        self.deribitmsgclient.connect('tcp://localhost:9000')
        self.deribitmsgclient.setsockopt_string(zmq.SUBSCRIBE, '')

        self.okexmsgclient = self.ctx.socket(zmq.SUB)
        self.okexmsgclient.connect('tcp://localhost:9100')
        self.okexmsgclient.setsockopt_string(zmq.SUBSCRIBE, '')

        self.okexclient = OptionAPI('3b43d558-c6e6-4460-b8dd-1e542bc8c6c1',
                                    '90EB8F53AABAE20C67FB7E3B0EFBB318',
                                    'mogu198812', True)

        self.deribitauth = openapi_client.AuthenticationApi()
        res = self.deribitauth.public_auth_get(grant_type='client_credentials',
                                               username='',
                                               password='',
                                               client_id=deribit_apikey,
                                               client_secret=deribit_apisecret,
                                               refresh_token='',
                                               timestamp='',
                                               signature='')
        self.deribitconfig = openapi_client.Configuration()
        self.deribitconfig.access_token = res['result']['access_token']
        self.deribitconfig.refresh_token = res['result']['refresh_token']
        self.deribittradingapi = openapi_client.TradingApi(
            openapi_client.ApiClient(self.deribitconfig))
Ejemplo n.º 2
0
def example_api_get_project():
    #  Set the configuration
    configuration = openapi_client.Configuration(
        host=example_host,
    )
    configuration.verify_ssl = False
    configuration.ssl_ca_cert = None
    configuration.assert_hostname = False
    configuration.cert_file = None

    #  Get an access token and add it to the configuration
    with openapi_client.ApiClient(configuration) as api_client:
        api_instance_auth = openapi_client.AuthenticationApi(api_client)
        body_login = openapi_client.ApiCredentials(password=example_password, username=example_username)
        api_response = api_instance_auth.login(body_login)
        configuration.access_token = api_response.token

        # Create a ProjectApi instance to make API storage commands
        api_instance = openapi_client.ProjectApi(api_client)

        print("# Get a single project")
        try:
            api_response = api_instance.get_project(project_name="Example-Archive-Project")
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling ProjectApi->get_project (example GET single project): %s\n" % e)

        print("# Get ALL projects")
        try:
            api_response = api_instance.list_projects()
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling ProjectApi->list_projects (example GET list of projects): %s\n" % e)
Ejemplo n.º 3
0
    def create_connection(self):
        '''
        Connects to deribit api and prescribes access token to bot
        ROBOT SHOULD BE CONFIGURED BEFORE CALLING THIS FUNCTION!
        '''
        assert not self.__client_id == 'not configured',     "Client ID is not configured!"
        assert not self.__client_secret == 'not configured', "Client Secret is not configured!" 
        assert not self.__host          == 'not configured', "Host is not configured!" 
        
        configuration = openapi_client.Configuration()
        configuration.host = self.__host
        configuration.access_token = self.__client_id

        auth_api_instance = openapi_client.AuthenticationApi(openapi_client.ApiClient(configuration))
       
        grant_type = 'client_credentials' 
        client_id = self.__client_id 
        client_secret = self.__client_secret
        scope = 'trade:read_write'
        
        try:
            api_response = auth_api_instance.public_auth_get(grant_type, '', '', client_id, client_secret, '', '', '',  scope=scope)
            
        except ApiException as e:
            print("Exception when calling AuthenticationApi->public_auth_get: %s\n" % e)

        self.__access_token = api_response['result']['access_token']
Ejemplo n.º 4
0
    def main(self):
        self._args = docopt(__doc__)
        logging.basicConfig(level=-10 * self._args["-v"] + 30)

        if not (self._args["--monitor-room-schedule"]
                or self._args["--record-now"]):
            self._log.error("Please provide an operation option")
            exit(1)

        self._cam = PiCamInterface()
        self._api_conf = openapi_client.Configuration(
            host=self._args["--api-url"])
        self._api_conf.verify_ssl = False if self._args[
            "--no-verify-certs"] else True
        self._api_client = openapi_client.ApiClient(
            configuration=self._api_conf)
        self._auth_api = openapi_client.AuthenticationApi(self._api_client)
        self._schedule_api = openapi_client.ScheduleApi(self._api_client)
        self._video_upload_api = openapi_client.VideostreamApi(
            self._api_client)
        self._recorder = RecordHandler(ul_api=self._video_upload_api,
                                       video_intf=self._cam,
                                       audio_intf=None,
                                       buffer_size=int(
                                           self._args["--mem-buffer-size"]))

        auth_token = self._get_jwt_token(self._args["<vc_username>"],
                                         self._args["<vc_password>"])
        if auth_token:
            self._api_conf.access_token = auth_token
            self._log.debug("Authorized as %s with JWT token %s" %
                            (self._args["<vc_username>"], auth_token))
        else:
            self._log.error("Unable to authenticate as %s. Exiting.." %
                            self._args["<vc_username>"])
            exit(1)

        if self._args["--record-now"]:
            self._start_recording_now(int(self._args["--record-now"]))

        if self._args["--monitor-room-schedule"]:
            self._log.info(
                "Recording sessions upcoming in room %s indefinitely. Ctrl-C to terminate",
                self._args["--monitor-room-schedule"])
            if self._update_schedule_jobs():
                schedule.every().day.at("06:00").do(self._update_schedule_jobs)

                while True:
                    schedule.run_pending()
                    sleep(5)
Ejemplo n.º 5
0
def example_api_login():
    #  Set the configuration
    configuration = openapi_client.Configuration(
        host=example_host,
    )
    configuration.verify_ssl = False
    configuration.ssl_ca_cert = None
    configuration.assert_hostname = False
    configuration.cert_file = None

    print("# Get an access token")
    with openapi_client.ApiClient(configuration) as api_client:
        api_instance_auth = openapi_client.AuthenticationApi(api_client)
        body_login = openapi_client.ApiCredentials(password=example_password, username=example_username)
        api_response = api_instance_auth.login(body_login)
        pprint(api_response)
Ejemplo n.º 6
0
    def main(self):
        arguments = docopt(__doc__)
        logging.basicConfig(level=-10 * arguments["-v"] + 30)

        if not (arguments["--update-schedule"] or arguments["--update-courses"]
                or arguments["--add-room"] or arguments["--print-rooms"]):
            self.log.error("Please provide an operation option")
            exit(1)

        self.api_conf = openapi_client.Configuration(
            host=arguments["--api-url"])
        self.api_conf.verify_ssl = False if arguments[
            "--no-verify-certs"] else True
        self.api_client = openapi_client.ApiClient(configuration=self.api_conf)
        self.auth_api = openapi_client.AuthenticationApi(self.api_client)
        self.schedule_api = openapi_client.ScheduleApi(self.api_client)
        self.course_api = openapi_client.CoursesApi(self.api_client)
        self.untis = WebuntisFetcher(arguments["<webuntis_user>"],
                                     arguments["<webuntis_pwd>"])

        auth_token = self._get_jwt_token(arguments["<vc_username>"],
                                         arguments["<vc_password>"])
        if auth_token:
            self.api_conf.access_token = auth_token
            self.log.debug("Authorized as %s with JWT token %s" %
                           (arguments["<vc_username>"], auth_token))
        else:
            self.log.error("Unable to authenticate as %s. Exiting.." %
                           arguments["<vc_username>"])
            exit(1)

        if arguments["--print-rooms"]:
            self._print_room_list(arguments["--print-rooms"])
        else:
            self.untis.login()
            if arguments["--add-room"]:
                self._add_room(arguments["--add-room"])
            if arguments["--update-courses"]:
                self._post_courses()
            if arguments["--update-schedule"]:
                self._fetch_schedules(arguments["--schedule-start"],
                                      arguments["--schedule-end"])
Ejemplo n.º 7
0
def example_api_create_update_project_restore():
    # Create instance of a restore project (the request body)
    example_restore = make_instance_restore_project(include_optional=False)
    example_restore_optional = make_instance_restore_project(include_optional=True)

    #  Set the configuration
    configuration = openapi_client.Configuration(
        host=example_host,
    )
    configuration.verify_ssl = False
    configuration.ssl_ca_cert = None
    configuration.assert_hostname = False
    configuration.cert_file = None

    #  Get an access token and add it to the configuration
    with openapi_client.ApiClient(configuration) as api_client:
        api_instance_auth = openapi_client.AuthenticationApi(api_client)
        body_login = openapi_client.ApiCredentials(password=example_password, username=example_username)
        api_response = api_instance_auth.login(body_login)
        configuration.access_token = api_response.token

        # Create a ProjectApi instance to make API storage commands
        api_instance = openapi_client.ProjectApi(api_client)

        print("# Create restore project with optional fields")
        try:
            api_response = api_instance.update_restore_project(project_name="Example-Restore-Project-Optional-Fields",
                                                               body=example_restore_optional)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling ProjectApi->update_restore_project (example for restore from local nas "
                  "to local nas w/ optional fields): %s\n" % e)

        print("# Create restore project with required fields")
        try:
            api_response = api_instance.update_restore_project(project_name="Example-Restore-Project",
                                                               body=example_restore)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling ProjectApi->update_restore_project (example for restore from local nas "
                  "to local nas): %s\n" % e)
Ejemplo n.º 8
0
def example_api_create_update_storage_location():
    # Create instance of a source storage location (the request body)
    example_local_nas_source = make_instance_storage_location_source(include_optional=False)
    example_local_nas_source_optional = make_instance_storage_location_source(include_optional=True)

    # Create instance of a target storage location (the request body)
    example_local_nas_target = make_instance_storage_location_target(include_optional=False)
    example_local_nas_target_optional = make_instance_storage_location_target(include_optional=True)

    #  Set the configuration
    configuration = openapi_client.Configuration(
        host=example_host,
    )
    configuration.verify_ssl = False
    configuration.ssl_ca_cert = None
    configuration.assert_hostname = False
    configuration.cert_file = None

    #  Get an access token and add it to the configuration
    with openapi_client.ApiClient(configuration) as api_client:
        api_instance_auth = openapi_client.AuthenticationApi(api_client)
        body_login = openapi_client.ApiCredentials(password=example_password, username=example_username)
        api_response = api_instance_auth.login(body_login)
        configuration.access_token = api_response.token

        # Create a StorageApi instance to make API storage commands
        api_instance = openapi_client.StorageApi(api_client)

        print("# Create/Update source storage location using required fields")
        try:
            api_response = api_instance.update_storage_location(storage_location_name=
                                                                "Example-Source",
                                                                body=example_local_nas_source)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling StorageApi->update_storage_location (example for local NAS source): %s\n"
                  % e)

        print("# Create/Update target storage location using required fields")
        try:
            api_response = api_instance.update_storage_location(storage_location_name=
                                                                "Example-Target",
                                                                body=example_local_nas_target)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling StorageApi->update_storage_location (example for local NAS target): %s\n"
                  % e)

        print("# Create/Update source storage location optional fields")
        try:
            api_response = api_instance.update_storage_location(storage_location_name=
                                                                "Example-Source-Optional-Fields",
                                                                body=example_local_nas_source_optional)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling StorageApi->update_storage_location (example for local NAS source w/ "
                  "optional fields): %s\n" % e)

        print("# Create/Update target storage location optional fields")
        try:
            api_response = api_instance.update_storage_location(storage_location_name=
                                                                "Example-Target-Optional-Fields",
                                                                body=example_local_nas_target_optional)
            pprint(api_response)
        except ApiException as e:
            print("Exception when calling StorageApi->update_storage_location (example for local NAS target w/ "
                  "optional fields): %s\n" % e)