简体   繁体   中英

ModuleNotFoundError: No module named 'common.config' oanda api python

I am trying to connect to Oanda REST API using juypter notebook with the following code:

#!/usr/bin/env python

import sys
import select
import argparse
import common.config
from .account import Account


def main():
    """
    Create an API context, and use it to fetch an Account state and then
    continually poll for changes to it.
    The configuration for the context and Account to fetch is parsed from the
    config file provided as an argument.
    """

    parser = argparse.ArgumentParser()

    #
    # The config object is initialized by the argument parser, and contains
    # the REST APID host, port, accountID, etc.
    #
    common.config.add_argument(parser)

    parser.add_argument(
        "--poll-interval",
        type=int,
        default=5,
        help="The number of seconds between polls for Account changes"
    )

    args = parser.parse_args()

    account_id = args.config.active_account

    #
    # The v20 config object creates the v20.Context for us based on the
    # contents of the config file.
    #
    api = args.config.create_context()

    #
    # Fetch the details of the Account found in the config file
    #
    response = api.account.get(account_id)

    #
    # Extract the Account representation from the response and use
    # it to create an Account wrapper
    #
    account = Account(
        response.get("account", "200")
    )

    def dump():
        account.dump()

        print("Press <ENTER> to see current state for Account {}".format(
            account.details.id
        ))

    dump()

    while True:
        i, _, _ = select.select([sys.stdin], [], [], args.poll_interval)

        if i:
            sys.stdin.readline()
            dump()

        #
        # Poll for all changes to the account since the last
        # Account Transaction ID that was seen
        #
        response = api.account.changes(
            account_id,
            sinceTransactionID=account.details.lastTransactionID
        )

        account.apply_changes(
            response.get(
                "changes",
                "200"
            )
        )

        account.apply_state(
            response.get(
                "state",
                "200"
            )
        )

        account.details.lastTransactionID = response.get(
            "lastTransactionID",
            "200"
        )


if __name__ == "__main__":
    main()

It is showing this error:

ModuleNotFoundError Traceback (most recent call last) in ----> 1 import common.view 2 from position.view import print_positions_map 3 from order.view import print_orders_map 4 from trade.view import print_trades_map 5 ModuleNotFoundError: No module named 'common.view'

I added the 2 line on the top of the code then run it correctly.I think it's because of error path.

import sys sys.path.append('/Users/apple/Documents/code/PythonX86/OandaAPI/example/v20-python-samples/src')

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM