Skip to content

Commit

Permalink
Merge branch 'main' of github.com:blockplusim/crypto_trading_service_…
Browse files Browse the repository at this point in the history
…for_tradingview
  • Loading branch information
SZIIT committed Dec 17, 2021
2 parents 0e1e589 + cf01238 commit d7cd167
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 41 deletions.
47 changes: 6 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,10 @@
2.目前建议使用合约交易,使用一倍杠杆就和现货一样了
3.此脚本仅作学习使用,请勿

**使用流程**
1.在你的服务器上运行这个程序,可以在本页面有百年的 release 中直接下载 exe 程序,将程序所有文件放到你的Windows服务器上解压
2.解压出来后,我们需要修改 ***config.ini*** 文件。该文件包含以下内容
```ini
[account]
apiKey =
secret =
password =
enable_proxies = False
proxies =

[trading]
symbol = TRX-USDT-SWAP
amount = 1
tdMode = isolated
lever = 5

[service]
apiSec = 5BFJYtNg7hwkgCzYQMwwQNctqan9CmqOzmtldJc
listenHost = 0.0.0.0
listenPort = 80
debugMode = True
ipWhiteList = 52.89.214.238,34.212.75.30,54.218.53.128,52.32.178.7,127.0.0.1
```

**[account]** 节点主要配置欧易交易所的API信息
apiKey、secret和password可以在欧易个人中心的API中创建(创建API记得给予交易和读取权限,不要给提现的权限),enable_proxies是是否启用代理的意思,如果你的服务器是国内服务器,一般需要启用,启用填写True,proxies填写具体的代理地址,如:http://127.0.0.1:1080 所以建议使用海外服务器来运行这个程序

**[trading]** 交易API的默认配置
**symbol**:交易对,比特币BTC/USDT永续合约就是 BTC-USDT-SWAP 其他币也类似,不知道这个怎么设置的话,可以打开电脑版欧易,打开 交易 -> 基础交易 -> 切换你要交易的币对 -> 浏览器地址栏最后面就有交易对信息
**amount**:交易的数量,币的个数。注意这里统一使用币来计价,比如你开BTC,那么这里就是开BTC的数量
**lever**:默认杠杆倍数,如果 /order 请求中带有这个参数,系统会根据lever重新修改杠杆倍数
**tdMode**:保证金模式,isolated:逐仓 ;cross:全仓

**[service]** 服务配置
**apiSec**:通信密钥,这个一定要修改,随便改长一点复杂一点就行了
**listenHost**: 服务监听地址,一般默认即可
**listenPort**:服务监听端口,一般80即可,注意 TradingView 只支持80和443
**debugMode**:True或者False,开启debug模式的话日志输出会更详细
**ipWhiteList**:授权使用本服务接口的IP地址集合,每个IP地址用英文逗号 **,** 隔开,这里默认前面四个地址是 TradingView 的官方地址

**使用方法**
方法一(推荐!适合新手小白不会写程序的):直接使用我这里写好的UI界面程序,在本页面找到“Release”下载Configer程序即可。[前往查看使用说明>>](https://github.com/blockplusim/crypto_trading_service_for_tradingview/blob/main/okex_trading_ui_guide.md)
方法二(适合有Python开发经验的):在Python环境中直接运行本`Okex_trading.py`程序。[前往查看使用说明>>](https://github.com/blockplusim/crypto_trading_service_for_tradingview/blob/main/okex_trading_guide.md)

**视频教程**
Youtube教程:https://youtu.be/UEYo3aVgtjQ
Bilibili教程:https://www.bilibili.com/video/BV1aF411z7tM/
19 changes: 19 additions & 0 deletions code_sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**常用代码模板**

开多代码信号模板
```
plotshape(condition1, text='▲', style=shape.labeldown, textcolor=color.white, color = color.green, location = location.abovebar, title = "开多")
alertcondition(condition1 , title="CrossOver Double EMA Buy", message="CrossOver Double EMA Buy")
```

开空代码信号模板
```
plotshape(condition2, text='▼', style=shape.labeldown, textcolor=color.white, color = color.red, location = location.abovebar, title = "开空")
alertcondition(condition2 , title="CrossUnder Double EMA Sell", message="CrossUnder Double EMA Sell")
```

平仓代码模板
```
plotshape(condition2, text='Cancel', style=shape.labeldown, textcolor=color.white, color = color.red, location = location.abovebar, title = "开空")
alertcondition(condition2 , title="CrossUnder Double EMA Sell", message="CrossUnder Double EMA Sell")
```
53 changes: 53 additions & 0 deletions okex_trading_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## okex_trading.py 使用指南
适用于有python使用经验的朋友,因为只是一个python脚本

**使用流程**
1.购买海外服务器,注意必须是中国大陆以外的,因为许多交易所目前大陆IP无法连接和交易
2.安装 Python3.6 环境,安装必备的包:ccxt flask 等
3.我们需要修改 ***config.ini*** 文件。该文件包含以下内容

```ini
[account]
apiKey =
secret =
password =
enable_proxies = False
proxies =

[trading]
symbol = TRX-USDT-SWAP
amount = 1
tdMode = isolated
lever = 5

[service]
apiSec = 5BFJYtNg7hwkgCzYQMwwQNctqan9CmqOzmtldJc
listenHost = 0.0.0.0
listenPort = 80
debugMode = True
ipWhiteList = 52.89.214.238,34.212.75.30,54.218.53.128,52.32.178.7,127.0.0.1
```

**[account]** 节点主要配置欧易交易所的API信息
apiKey、secret和password可以在欧易个人中心的API中创建(创建API记得给予交易和读取权限,不要给提现的权限),enable_proxies是是否启用代理的意思,如果你的服务器是国内服务器,一般需要启用,启用填写True,proxies填写具体的代理地址,如:http://127.0.0.1:1080 所以建议使用海外服务器来运行这个程序

**[trading]** 交易API的默认配置
**symbol**:交易对,比特币BTC/USDT永续合约就是 BTC-USDT-SWAP 其他币也类似,不知道这个怎么设置的话,可以打开电脑版欧易,打开 交易 -> 基础交易 -> 切换你要交易的币对 -> 浏览器地址栏最后面就有交易对信息
**amount**:交易的数量,币的个数。注意这里统一使用币来计价,比如你开BTC,那么这里就是开BTC的数量
**lever**:默认杠杆倍数,如果 /order 请求中带有这个参数,系统会根据lever重新修改杠杆倍数
**tdMode**:保证金模式,isolated:逐仓 ;cross:全仓

**[service]** 服务配置
**apiSec**:通信密钥,这个一定要修改,随便改长一点复杂一点就行了
**listenHost**: 服务监听地址,一般默认即可
**listenPort**:服务监听端口,一般80即可,注意 TradingView 只支持80和443
**debugMode**:True或者False,开启debug模式的话日志输出会更详细
**ipWhiteList**:授权使用本服务接口的IP地址集合,每个IP地址用英文逗号 **,** 隔开,这里默认前面四个地址是 TradingView 的官方地址

**运行环境**
Python 3.6.10
ccxt 1.56.41
flask 1.1.2

**如何运行**
修改玩config.ini中的配置后,直接使用 `python okex_trading.py` 启动即可
36 changes: 36 additions & 0 deletions okex_trading_ui_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## okex_trading_ui 使用说明
预编译好且带有操作界面的程序,操作比较简单,适合新手小白

**使用前准备**
1.需要准备一个欧易OKEX交易所账号,如果你还没有注册,请先[注册一个账号](http://okex.pw/tvbot),然后到账号API申请V5API,备注名称随意,权限需要选择只读和交易,不要勾选提现!然后确认添加即可
2.你需要购买一台海外的服务器用于24小时自动运行这个自动交易程序,可以选择腾讯云轻量应用服务器香港等东亚地区的服务器(注意必须买海外的,推荐香港),可查看[腾讯轻量服务器教程](https://cloud.tencent.com/document/product/1207/44549)

**使用步骤**
1.在服务器上下载程序,从 `release` 中下载 `okex_trading_ui` 程序并解压到服务器上。[服务器上打开这个链接下载](https://github.com/blockplusim/crypto_trading_service_for_tradingview/releases)
2.下载完成以后解压,直接双击打开 `okex_trading_ui.exe` 界面如下:

<img src="https://user-images.githubusercontent.com/94948670/146109501-70f09b0d-59c2-4690-8993-64c33d823d0f.png" alt="" width="40%" height="40%" />

在上面的界面中,我们看到需要用到三个参数 apiKey / secret / password 。这三个参数我们可以在欧易OKEX个人中心中API中申请V5API中获取,然后把三个参数复制过来

<img src="https://user-images.githubusercontent.com/94948670/146110819-1b3a1ea5-39df-4fd7-8a98-35d7ca0763a0.png" alt="" width="70%" height="70%" />

下一步我们配置交易相关信息

<img src="https://user-images.githubusercontent.com/94948670/146111099-c4fc3341-038d-48c3-a80b-55a95647d638.png" alt="" width="40%" height="40%" />

下一步在服务配置这边,一般需要修改 `通信密钥`, 这里就是一个简单的密码,用于验证身份。我们在TradingView调用的时候需要用到

<img src="https://user-images.githubusercontent.com/94948670/146111335-9842154a-3f0b-48d2-8cf1-a8d9ba5d6a02.png" alt="" width="40%" height="40%" />

配置完成后,点击 `保存配置`,然后再点击 `启动服务` 即可

<img src="https://user-images.githubusercontent.com/94948670/146112100-2be19db2-2dc6-4328-a997-0d68ba335bea.png" alt="" width="40%" height="40%" />

这个启动完成后,我们就可以对接 `TradingView` 来实现自动交易了

<img src="https://user-images.githubusercontent.com/94948670/146113041-85c79ee7-4917-4953-9f07-17a86e023ee9.png" alt="" width="100%" height="100%" />

在香港服务器上运行成功界面如上图所示


0 comments on commit d7cd167

Please sign in to comment.