コード例 #1
0
    def login(self, l_args):
        """Connect to Degiro's API."""

        # PARSING ARGS
        default_credentials = self.__default_credentials
        parser = argparse.ArgumentParser(
            add_help=False,
            prog="login",
        )
        parser.add_argument(
            "-u",
            "--username",
            dest="username",
            type=str,
            default=default_credentials.username,
            help="Username in Degiro's account.",
        )
        parser.add_argument(
            "-p",
            "--password",
            dest="password",
            type=str,
            default=default_credentials.password,
            help="Password in Degiro's account.",
        )
        parser.add_argument(
            "-o",
            "--otp",
            dest="otp",
            type=int,
            default=None,
            help="One time password (2FA).",
        )
        parser.add_argument(
            "-s",
            "--topt-secret",
            dest="topt_secret",
            type=str,
            default=None,
            help="TOTP SECRET (2FA).",
        )
        ns_parser = parse_known_args_and_warn(parser, l_args)

        if ns_parser:
            credentials = Credentials()
            credentials.CopyFrom(default_credentials)
            credentials.username = ns_parser.username
            credentials.password = ns_parser.password

            if ns_parser.otp is not None:
                credentials.one_time_password = ns_parser.otp
            if ns_parser.topt_secret is not None:
                credentials.totp_secret_key = ns_parser.topt_secret

            self.__trading_api = TradingAPI(credentials=credentials)

            self.__trading_api.connect()
            self.setup_extra_credentials()

            print("You are now logged in !")
コード例 #2
0
    def __init__(self, credentials: Credentials):
        self.__default_credentials = credentials
        self.__trading_api = TradingAPI(credentials=credentials)

        self.__degiro_parser = argparse.ArgumentParser(
            add_help=False,
            prog="degiro",
        )
        self.__degiro_parser.add_argument("cmd", choices=self.CHOICES)
コード例 #3
0
ファイル: app.py プロジェクト: Tobiaqs/degiro-preorder
def recreate_trading_api_periodically():
    global trading_api
    while True:
        # every 10 minutes, recreate session.
        time.sleep(600)
        trading_api_mutex.acquire()
        try:
            trading_api = TradingAPI(credentials=credentials)
            trading_api.connect()
            trading_api.get_account_info()
        except:
            logger.error('failed to recreate TradingAPI.')
        finally:
            trading_api_mutex.release()
コード例 #4
0
# SETUP CONFIG DICT
with open('config/config.json') as config_file:
    config_dict = json.load(config_file)

# SETUP CREDENTIALS
int_account = config_dict['int_account']
username = config_dict['username']
password = config_dict['password']
credentials = Credentials(
    int_account=int_account,
    username=username,
    password=password,
)

# SETUP TRADING API
trading_api = TradingAPI(credentials=credentials)

# CONNECT
trading_api.connect()

# FETCH DATA - MESSAGE
products_config = trading_api.get_products_config(raw=False)

# DISPLAY - MESSAGE
for item in products_config.values:
    print(item)

# FETCH DATA - DICT
products_config_dict = trading_api.get_products_config(raw=True)
products_config_pretty = json.dumps(
    products_config_dict,
コード例 #5
0
def trading_api(credentials):
    trading_api = TradingAPI(credentials=credentials)
    trading_api.connect()

    return trading_api