forked from vnpy/vnpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
752 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# vn.oanda | ||
|
||
### 简介 | ||
OANDA外汇交易接口,基于REST API开发,实现了以下功能: | ||
|
||
1. 发送、修改、撤销委托 | ||
|
||
2. 查询委托、持仓(按照每笔成交算)、汇总持仓(按照单一货币对算)、资金、成交历史 | ||
|
||
3. 实时行情和成交推送 | ||
|
||
4. 获取Forex Lab中的日历、订单簿、历史持仓比、价差、交易商持仓、Autochartist | ||
|
||
### 特点 | ||
相比较于[OANDA官网](http://developer.oanda.com/rest-live/sample-code/)上贴出的一些Python API(如pyoanda、oanda-trading-environment等),vn.oanda的一些不同: | ||
|
||
1. 面向对象的API设计,接近CTP API的结构,对于国内用户而言更容易上手 | ||
|
||
2. 三个独立的工作线程,分别处理:用户请求(如发送委托等)、行情推送、事件推送(如成交事件等),提供更高的性能 | ||
|
||
3. 参考CTP API的设计,主动函数调用的结果通过异步(回调函数)的方式推送到程序中,适用于开发真正可靠的实盘交易程序(pyoanda里使用的同步阻塞工作模式在实盘应用中的风险:想象你的交易程序发送委托请求后,因为网络问题不能立即返回,因此主线程阻塞导致界面卡死或者背后的策略引擎线程卡死,对新的行情事件完全失去响应) | ||
|
||
### Quick Start | ||
1. 安装Anaconda 2.7 32位 | ||
|
||
2. 前往[OANDA](http://www.oanda.com)注册一个fxTrade practice测试账户(注意国家不要选中国,会无法申请API token,作者测试英国可以) | ||
|
||
3. 在网站登陆后,进入Manage Funds,记录下自己的Account Number | ||
|
||
4. 回到上一个界面,左侧有个Manage API Access(在Recent Logins上方,没有的就是第一步国家选错了),进入后生成token | ||
|
||
5. 下载vn.oanda到本地后,打开test.py,修改token和accountId为你的信息 | ||
|
||
6. 将test.py中想要测试的功能取消注释,开始使用吧! | ||
|
||
### API版本 | ||
OANDA REST API | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# encoding: utf-8 | ||
|
||
from api import OandaApi | ||
|
||
|
||
if __name__ == '__main__': | ||
token = '' | ||
accountId = '' | ||
|
||
api = OandaApi() | ||
api.DEBUG = True | ||
|
||
api.init('practice', token, accountId) | ||
|
||
# 获取交易合约列表,通过 | ||
#api.getInstruments({'accountId': accountId}) | ||
|
||
# 获取价格,通过 | ||
#api.getPrices({'instruments': 'EUR_USD'}) | ||
|
||
# 获取历史数据,失败 | ||
#api.getPriceHisory({'instruments': 'EUR_USD', | ||
#'granularity': 'D', | ||
#'candleFormat': 'midpoint', | ||
#'count': '50'}) | ||
|
||
# 查询用户的所有账户,通过 | ||
#api.getAccounts() | ||
|
||
# 查询账户信息,通过 | ||
#api.getAccountInfo() | ||
|
||
# 查询委托数据,通过 | ||
#api.getOrders({}) | ||
|
||
# 发送委托,通过 | ||
#api.sendOrder({'instrument': 'EUR_USD', | ||
#'units': '10000', | ||
#'side': 'buy', | ||
#'type': 'market'}) | ||
|
||
# 查询委托数据,通过 | ||
#api.getOrderInfo('123') | ||
|
||
# 修改委托,通过 | ||
#api.modifyOrder({'units': '10000', | ||
#'side': 'buy', | ||
#'type': 'market'}, '123') | ||
|
||
# 撤销委托,通过 | ||
#api.cancelOrder('123') | ||
|
||
# 查询所有持仓,通过 | ||
#api.getTrades({}) | ||
|
||
# 查询持仓数据,通过 | ||
#api.getTradeInfo('10125150909') | ||
|
||
# 修改持仓,通过 | ||
#api.modifyTrade({'trailingStop': '150'}, '10125150909') | ||
|
||
# 平仓,通过 | ||
#api.closeTrade('10125150909') | ||
|
||
# 查询汇总持仓,通过 | ||
#api.getPositions() | ||
|
||
# 查询汇总持仓细节,通过 | ||
#api.getPositionInfo('EUR_USD') | ||
|
||
# 平仓汇总持仓,通过 | ||
#api.closePosition('EUR_USD') | ||
|
||
# 查询账户资金变动,通过 | ||
#api.getTransactions({}) | ||
|
||
# 查询资金变动信息,通过 | ||
#api.getTransactionInfo('10135713982') | ||
|
||
# 查询账户变动历史,部分通过,某些情况下可能触发JSONDecodeError | ||
#api.getAccountHistory() | ||
|
||
# 查询财经日历,通过 | ||
#api.getCalendar({'period': '604800'}) | ||
|
||
# 查询历史持仓比,通过 | ||
#api.getPositionRatios({'instrument': 'EUR_USD', | ||
#'period': '604800'}) | ||
|
||
# 查询历史价差,通过 | ||
#api.getSpreads({'instrument': 'EUR_USD', | ||
#'period': '604800'}) | ||
|
||
# 查询交易商持仓,通过 | ||
#api.getCommitments({'instrument': 'EUR_USD'}) | ||
|
||
# 查询订单簿,通过 | ||
#api.getOrderbook({'instrument': 'EUR_USD', | ||
#'period': '604800'}) | ||
|
||
# 查询Autochartist,失败,OANDA服务器报错 | ||
#api.getAutochartist({'instrument': 'EUR_USD'}) | ||
|
||
# 阻塞 | ||
input() |