OANDA API v20 开源项目教程
1. 项目的目录结构及介绍
oanda-api-v20/
├── examples/
│ ├── account_details.py
│ ├── account_list.py
│ ├── ...
├── oandapyV20/
│ ├── contrib/
│ │ ├── ...
│ ├── endpoints/
│ │ ├── accounts.py
│ │ ├── instruments.py
│ │ ├── ...
│ ├── ...
├── tests/
│ ├── ...
├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
- examples/: 包含使用 OANDA API v20 的示例代码。
- oandapyV20/: 核心库文件,包含 API 的实现和端点处理。
- tests/: 包含项目的测试代码。
- .gitignore: Git 忽略文件。
- LICENSE: 项目许可证。
- README.md: 项目说明文档。
- requirements.txt: 项目依赖文件。
- setup.py: 项目安装脚本。
2. 项目的启动文件介绍
项目的启动文件通常是 examples/
目录下的示例代码。例如,account_details.py
是一个典型的启动文件,用于获取账户详情。
from oandapyV20 import API
import oandapyV20.endpoints.accounts as accounts
accountID = "YOUR_ACCOUNT_ID"
api = API(access_token="YOUR_ACCESS_TOKEN")
r = accounts.AccountDetails(accountID)
api.request(r)
print(r.response)
3. 项目的配置文件介绍
项目的配置文件主要是 setup.py
和 requirements.txt
。
- setup.py: 用于安装项目的脚本,包含项目的元数据和依赖项。
from setuptools import setup, find_packages
setup(
name="oandapyV20",
version="0.6.3",
packages=find_packages(),
install_requires=[
"requests",
],
author="Tor Dahl",
author_email="tordahl@gmail.com",
description="A python wrapper for the OANDA v20 API",
license="MIT",
keywords="oanda forex trading api",
url="https://github.com/hootnot/oanda-api-v20",
)
- requirements.txt: 列出了项目运行所需的依赖项。
requests==2.25.1
通过这些配置文件,可以确保项目在不同环境中的一致性和可重复性。