コード例 #1
0
def fetch(config, fileobj):
    username, password, accts = config
    client = OFXClient('https://ofx.fidelity.com/ftgw/OFX/clients/download',
                       userid=username.value,
                       org='fidelity.com',
                       fid='7776',
                       brokerid='fidelity.com')
    accts = accts.value.split(',')
    resp = client.request_statements(
        password.value, *[InvStmtRq(acctid=acct) for acct in accts])
    fileobj.write(resp.read().decode())
コード例 #2
0
def request_stmt(args: ArgsType) -> None:
    """
    Send *STMTRQ
    """
    dt = convert_datetime(args)
    password = get_passwd(args)

    if args["all"]:
        acctinfo = _request_acctinfo(args, password)
        _merge_acctinfo(args, acctinfo)

    stmtrqs: List[Union[StmtRq, CcStmtRq, InvStmtRq]] = []
    for accttype in ("checking", "savings", "moneymrkt", "creditline"):
        stmtrqs.extend([
            StmtRq(
                acctid=acctid,
                accttype=accttype.upper(),
                dtstart=dt["start"],
                dtend=dt["end"],
                inctran=args["inctran"],
            ) for acctid in args[accttype]
        ])

    for acctid in args["creditcard"]:
        stmtrqs.append(
            CcStmtRq(
                acctid=acctid,
                dtstart=dt["start"],
                dtend=dt["end"],
                inctran=args["inctran"],
            ))

    for acctid in args["investment"]:
        stmtrqs.append(
            InvStmtRq(
                acctid=acctid,
                dtstart=dt["start"],
                dtend=dt["end"],
                dtasof=dt["asof"],
                inctran=args["inctran"],
                incoo=args["incoo"],
                incpos=args["incpos"],
                incbal=args["incbal"],
            ))

    if not stmtrqs:
        accttypes = [
            "checking",
            "savings",
            "moneymrkt",
            "creditline",
            "creditcard",
            "investment",
        ]
        msg = f"No accounts specified; configure at least one of {accttypes}"
        warnings.warn(msg, category=SyntaxWarning)

    client = init_client(args)
    with client.request_statements(password,
                                   *stmtrqs,
                                   dryrun=args["dryrun"],
                                   verify_ssl=not args["unsafe"]) as f:
        response = f.read()

    print(response.decode())

    if args["write"]:
        write_config(args)

    if args["savepass"]:
        save_passwd(args, password)
コード例 #3
0
 def invStmtRq(self):
     return InvStmtRq(
         acctid="444444",
         dtstart=datetime(2017, 1, 1, tzinfo=UTC),
         dtend=datetime(2017, 3, 31, tzinfo=UTC),
     )
コード例 #4
0
ファイル: test_client.py プロジェクト: cloudydata/ofxtools
    def testDoStmtDryrun(self):
        with patch("ofxtools.Client.OFXClient.request_statements"
                   ) as fake_rq_stmt:
            fake_rq_stmt.return_value = BytesIO(b"th-th-th-that's all folks!")
            output = do_stmt(self.args)

            self.assertEqual(output, None)

            args, kwargs = fake_rq_stmt.call_args
            user, password, *stmtrqs = args
            self.assertEqual(user, "porkypig")
            self.assertEqual(password, "{:0<32}".format("anonymous"))
            self.assertEqual(
                stmtrqs,
                [
                    StmtRq(
                        acctid="123",
                        accttype="CHECKING",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="234",
                        accttype="CHECKING",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="345",
                        accttype="SAVINGS",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="456",
                        accttype="SAVINGS",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="567",
                        accttype="MONEYMRKT",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="678",
                        accttype="MONEYMRKT",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="789",
                        accttype="CREDITLINE",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    StmtRq(
                        acctid="890",
                        accttype="CREDITLINE",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    CcStmtRq(
                        acctid="111",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    CcStmtRq(
                        acctid="222",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                    ),
                    InvStmtRq(
                        acctid="333",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        dtasof=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                        incoo=False,
                        incpos=True,
                        incbal=True,
                    ),
                    InvStmtRq(
                        acctid="444",
                        dtstart=datetime(2007, 1, 1, tzinfo=UTC),
                        dtend=datetime(2007, 12, 31, tzinfo=UTC),
                        dtasof=datetime(2007, 12, 31, tzinfo=UTC),
                        inctran=True,
                        incoo=False,
                        incpos=True,
                        incbal=True,
                    ),
                ],
            )
            self.assertEqual(
                kwargs, {
                    "clientuid": None,
                    "dryrun": True,
                    "close_elements": True,
                    "prettyprint": False,
                })