Important
🚀 auto-trade support AI 🤖 trading 💹 now !! You could use aiTrade
command to use AI tradebot. The AI trading strategy is based on the reinforcement learning đź“‘ model. The model will learn from the historical data and make the best decision for you. The AI trading strategy is a premium feature, but you dont need to pay for it!
auto is an open source project that aims to provide a simple and easy to use trading bot for the TideBit DeFi . The bot is written in TypeScript and uses the NestJS framework.
auto trade is a simple trading bot that uses the TideBit API to trade on the exchange. The bot is written in TypeScript and uses the NestJS framework. The bot is designed to be simple and easy to use, and is intended to be used by people who are new to trading and want to apply different trading strategies.
- Clone this repository:
git clone https://github.com/CAFECA-IO/auto-trade/tree/develop
cd auto-trade
- Install dependencies:
npm install
- Copy the example
.env
file in your root directory and fill in the required information:
SUGGESTION = "autoArima"
STOP_LOSS = "autoArima"
TAKE_PROFIT = "autoArima"
PRIVATE_KEY = "YOUR_PRIVATE_KEY"// Your could create tradebot by your own Wallet private key
Create your own strategy in the src/strategies/strategy
directory and modify .env
file. You can use the autoArima
strategy as an example.
import * as ARIMA from 'arima';
export function suggestion(data: {
currentPrice: number;
priceArray: number[];
spreadFee: number;
holdingStatus: string;
}) {
let suggestion = 'WAIT';
const arima = new ARIMA('auto');
arima.train(data.priceArray);
// const AbsspreadFee = Math.abs(data.spreadFee);
const arimaPredict = arima.predict(15);
const predict: number[] = arimaPredict[0];
// const predictProfit = AbsspreadFee * 2.8;
const currentPrice = data.currentPrice;
if (predict[predict.length - 1] > currentPrice) {
suggestion = 'BUY';
}
if (predict[predict.length - 1] < currentPrice) {
suggestion = 'SELL';
}
if (suggestion === 'WAIT') {
return suggestion;
}
if (data.holdingStatus === 'WAIT') {
return suggestion;
}
if (suggestion !== data.holdingStatus) {
return 'CLOSE';
}
return 'WAIT';
}
export function takeProfit(data: {
openPrice: number;
currentPrice: number;
spreadFee: number;
holdingStatus: string;
}) {
const AbsSpreadFee = Math.abs(data.spreadFee);
const openPrice = data.openPrice;
const currentPrice = data.currentPrice;
const takeProfit = AbsSpreadFee * 1.5;
const holdingStatus = data.holdingStatus;
if (holdingStatus === 'BUY') {
// Info: (20240328 - Jacky) Current Sell price is higher than the open Buy price
if (currentPrice - AbsSpreadFee - openPrice > takeProfit) {
return 'CLOSE';
}
}
if (holdingStatus === 'SELL') {
// Info: (20240328 - Jacky) Current Buy price is lower than the open Sell price
if (openPrice - (currentPrice + AbsSpreadFee) > takeProfit) {
return 'CLOSE';
}
}
return 'WAIT';
}
export function stopLoss(data: {
openPrice: number;
currentPrice: number;
spreadFee: number;
holdingStatus: string;
}) {
const AbsSpreadFee = Math.abs(data.spreadFee);
const openPrice = data.openPrice;
const currentPrice = data.currentPrice;
const stopLoss = AbsSpreadFee * 0.7;
const holdingStatus = data.holdingStatus;
if (holdingStatus === 'BUY') {
// Info: (20240328 - Jacky) Current Buy price is lower than the open Buy price
if (openPrice - (currentPrice + AbsSpreadFee) > stopLoss) {
return 'CLOSE';
}
}
if (holdingStatus === 'SELL') {
// Info: (20240328 - Jacky) Current Sell price is higher than the open Sell price
if (currentPrice - AbsSpreadFee - openPrice > stopLoss) {
return 'CLOSE';
}
}
return 'WAIT';
}
Warning
The strategy must have the same functions and parameters as the example above. However, it' free to combine the strategy as long as it's in the same format.
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
POST /tradebot
GET /tradebot
GET /tradebot
Parameters
name | type | required | default |
---|---|---|---|
id | string(UUID) | true | null |
GET /tradebot?id=tradebotId
Request URL
PUT /tradebot
Parameters
name | type | required | default |
---|---|---|---|
id | string(UUID) | true | null |
name | type | required | default |
---|---|---|---|
suggestion | string | false | null |
stopLoss | string | false | null |
takeProfit | string | false | null |
PUT /tradebot?id=tradebotId
"body": {
"suggestion": "string",
"tradeStrategy": "string",
"stopLoss": "string",
"takeProfit": "string",
}
Request URL
POST /tradebot/tradebotId
name | type | required | default | description |
---|---|---|---|---|
command | string | true | null | "run" or "stop" or "deposit or aiTrade" |
POST /tradebot/tradebotId
"body": {
"command": "run",
}
# unit tests
$ npm run test
# test coverage
$ npm run test:cov
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.