简体   繁体   English

ModuleNotFoundError:没有名为“common.config”的模块 oanda api python

[英]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:我正在尝试使用 juypter notebook 连接到 Oanda REST API,代码如下:

#!/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' ModuleNotFoundError Traceback(最近一次调用)在 ----> 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.我在代码顶部添加了 2 行,然后正确运行它。我认为这是因为错误路径。

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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