Skip to content

CAFECA-IO/auto-trade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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-trade

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.

Description

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.

Installation

  1. Clone this repository:
git clone https://github.com/CAFECA-IO/auto-trade/tree/develop
cd auto-trade
  1. Install dependencies:
npm install
  1. 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

Change strategy

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.

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

API usage

Create Tradebot

Request URL

POST /tradebot

Get All Tradebot

Request URL

GET /tradebot

Get Tradebot by ID

Request URL

GET /tradebot

Parameters

name type required default
id string(UUID) true null

Request Example

GET /tradebot?id=tradebotId

Update Tradebot

Request URL

PUT /tradebot

Parameters

name type required default
id string(UUID) true null

body

name type required default
suggestion string false null
stopLoss string false null
takeProfit string false null

Request Example

PUT /tradebot?id=tradebotId
"body": {
  "suggestion": "string",
  "tradeStrategy": "string",
  "stopLoss": "string",
  "takeProfit": "string",
}

Command Tradebot

Request URL

POST /tradebot/tradebotId

body

name type required default description
command string true null "run" or "stop" or "deposit or aiTrade"

Request Example

POST /tradebot/tradebotId
"body": {
  "command": "run",
}

Test

# unit tests
$ npm run test

# test coverage
$ npm run test:cov

Support

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.

License

Nest is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages