blancos13 / TideBitEx

TideBit Exchange

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tidebit-Lagacy 流程補充

為了使被推薦的用戶有對應的 commission_plans_id 及得到推薦者的分潤比例,需要再 import 兩張table commission_planscommission_policies

TideBitEx

TideBit Exchange

General Requirements

remove build/index.html

Getting started

setup TideBit-Legacy

Node.js

TideBit-Legacy使用的Node.js版本較舊,只用於編譯UI,跑完就可以換版本了。

vi install.sh
#!/bin/bash

###
### Prepare Environment ###
###

### Install Library ###
sudo apt-get update
sudo apt-get install openssl libtool autoconf automake uuid-dev build-essential gcc g++ software-properties-common unzip make git libcap2-bin -y

### Setup Swap ###
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab


NODE_VERSION="v14.17.6"
NODE_FILENAME="node-$NODE_VERSION-linux-x64"
PARENT_LOCATION="/opt/nodejs"

###
### Install NodeJS & PM2 ###
###

### Download NodeJS ###
cd /usr/local/src
sudo wget -nc http://nodejs.org/dist/$NODE_VERSION/$NODE_FILENAME.tar.gz
#wget -E -H -k -K -p http:///
sudo tar zxvf $NODE_FILENAME.tar.gz
sudo mkdir -p $PARENT_LOCATION
sudo mv $NODE_FILENAME $PARENT_LOCATION/

### Link binary files ###
rm -f /usr/local/bin/node
rm -f /usr/local/bin/npm
sudo ln -s $PARENT_LOCATION/$NODE_FILENAME/bin/node /usr/local/bin
sudo ln -s $PARENT_LOCATION/$NODE_FILENAME/bin/npm /usr/local/bin

### assign 80 & 443 port ###
sudo setcap 'cap_net_bind_service=+ep' $PARENT_LOCATION/$NODE_FILENAME/bin/node

### Install PM2 ###
sudo npm i -g pm2
sudo ln -s $PARENT_LOCATION/$NODE_FILENAME/bin/pm2 /usr/local/bin

pm2 install pm2-logrotate
sh install.sh
rm install.sh

clone Project

git clone https://github.com/CAFECA-IO/TideBitEx.git
cd TideBitEx
npm i

設定config

mkdir private
vi private/config.toml

可參照default.config.toml,略過[api], [base]

sample:

# 請參考 https://www.okx.com/docs-v5/broker_zh/#non-disclosed-broker 申請
[okex]
domain = 'https://www.okx.com'
apiKey = 'your-api-key'
secretKey = 'your-api-secretKey'
passPhrase = 'your-api-passPhrase'
brokerId = '377bd372412fSCDE'

[peatio]
domain = 'http://127.0.0.1:3000'      # 要與TideBit-Legacy application.yml中URL_HOST相同

[redis]
domain = 'redis://127.0.0.1:6379'

[database]
protocol = 'mysql'
host = '127.0.0.1'
port = '3306'
user = 'tidebitstaging'
password = 'tidebitstaging'
dbName = 'tidebitstaging'
logging = false
ormEnable = false
  [database.dialectOptions]
  connectTimeout = 3000
  [database.pool]
  max = 10

設定 tradingview Communicator config

Sample: in default.config.js

export const baseUrl = 'new.tidebit.com';
export const wsUrl = 'ws.tidebit.network/ws';

將 default.config.js 複製到 public/tradingview/config.js 將 default.config.js 複製到 src/constant/Config.js

cp default.config.js public/tradingview/config.js
cp default.config.js src/constant/Config.js

或是將上一個版本的資料,複製的最新版本 ex:

cp -r TideBitEx/private/ TideBitEx-[version]/private
cp TideBitEx/shell/restart.sh TideBitEx-[version]/shell/restart.sh
cp TideBitEx/src/constant/Config.js TideBitEx-[version]/src/constant/Config.js
cp TideBitEx/public/tradingview/config.js TideBitEx-[version]/public/tradingview/config.js

設定 crontab

將 default.restart.sh 複製到 shell/restart.sh

cp default.restart.sh shell/restart.sh
crontab -e
* */6 * * * /bin/bash -l -c 'sh ./workspace/TideBitEx/shell/restart.sh' //At every minute past every 6th hour
sudo service cron restart

設定markets

vi private/marketsSource.toml

可參照default.marketsSource.toml,所有的instId都以tb開頭

欄位名稱 解釋
key instId(大寫),以tb開頭,ex: tbETH-USDT
value 來源字串,請參考backend/bots/constants/SupportedExchange.js

需要同時有定義交易對名稱以及來源名稱

sample:

[markets]
BTCUSD = 'BTC-USD'
tbBTC-USD = 'TideBit'

db migrate

chmod a+x bin/dbmigrate.js 
npm run dbmigrate

啟動

之後便可以使用pm2掛載

pm2 start bin/main.js

正常執行後會看到

[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/.pm2
[PM2] PM2 Successfully daemonized
[PM2][Module] Starting NPM module pm2-logrotate
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [pm2-logrotate] launched (1 instances)
[PM2] Starting /home/ubuntu/workspace/TideBitEx/bin/main.js in fork_mode (1 instance)
[PM2] Done.

再執行

pm2 log 1

會看到

DB    tidebitstaging connect success
register options ...
...
HTTP   http://127.0.0.1:80
HTTPS  https://127.0.0.1:443

之後有在TidebitEX上做修改後需重啟

pm2 restart bin/main.js

組合log一起使用

pm2 restart bin/main.js && pm2 log 1

關閉掛載

pm2 kill

trouble shoot

ENOTFOUND

https://phoenixnap.com/kb/mysql-remote-connection

ER_ACCESS_DENIED_ERROR

https://stackoverflow.com/questions/58107591/authentication-failure-when-connecting-to-mysql-as-non-root-user

Redis Client Error Error: connect ECONNREFUSED

sudo service redis-server restart
sudo service redis-server status

About

TideBit Exchange

License:GNU General Public License v3.0


Languages

Language:JavaScript 37.2%Language:HTML 33.9%Language:CSS 24.7%Language:SCSS 3.3%Language:TypeScript 0.9%Language:Shell 0.0%