Skip to content

Commit

Permalink
Merge pull request #26 from TeamWertarbyte/development
Browse files Browse the repository at this point in the history
2021.1.3
  • Loading branch information
saschb2b authored Jan 31, 2021
2 parents 5997fc8 + 4e42eab commit a6a1e5a
Show file tree
Hide file tree
Showing 14 changed files with 419 additions and 249 deletions.
3 changes: 2 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
BITTREX_API_KEY=
BITTREX_API_SECRET=
BITTREX_API_SECRET=
SENTRY_DSN=
99 changes: 18 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Cryptocurrency Trading Bot ![version](https://img.shields.io/badge/Version-2021.1.2-blue)
# Cryptocurrency Trading Bot ![version](https://img.shields.io/badge/Version-2021.1.3-blue)
I'm using this bot for a long time now and wanted to share it.


Feel free to make it your own. PRs are welcome!

## USE AT YOUR OWN RISK
A trading bot that does what you order him to do (use at your own risk)

I'm not responsible for anything
A trading bot that does what you order him to do (use at your own risk) I'm not responsible for anything

## EMA crossover strategy
It's using the ema crossover strategy. But instead of EMA 5 and EMA 20 I'm using EMA 9 and EMA 26
It's using the ema crossover strategy

https://www.theforexchronicles.com/the-ema-5-and-ema-20-crossover-trading-strategy/

Expand All @@ -30,83 +27,12 @@ Doge: DJ6JwaBJ6QwyaDLfYsNdre52sf1C7Abm5B

Litecoin: LSVno86JENvnEmdCrY6sVNGGe7KM2HyLKm

## Program Sequence

## Main loop
```
start = async () => {
const start = now();
log.info(`########## Started ichimoku ##########`);
await this.collectRevenue();
const markets: Market[] = await this.getMarkets();
const marketSummaries: MarketSummary[] = await this.getMarketSummaries(
markets
);
await this.evaluateMarkets(marketSummaries.map(({ symbol }) => symbol));
// await this.report();
log.info(`########## Finished ${(now() - start).toFixed(5)} ms ##########`);
};
```

## Collecting Revenue
```
await this.collectRevenue();
```
* Fetch you current balances
* Only checks assets where available coins are greater than 0
* Ignore assets that you want to HODL see config
* Iterate over every balance
* Fetch current market ticker for this balance (e.g. `ETH-USDT`)
* Calculates how much revenue is already earned (current value minus invest)
* When greate than invest try to sell that bit
* e.g. Current value 57 USDT with an invest of 50 USDT -> sell 7 USDT worth
* It can only sell when the quantity will be greater than the minimum trade size allowed by bittrex

## Evaluate Markets
```
const markets: Market[] = await this.getMarkets();
const marketSummaries: MarketSummary[] = await this.getMarketSummaries(
markets
);
await this.evaluateMarkets(marketSummaries.map(({ symbol }) => symbol));
```
* Filter the markets `getMarkets` and `getMarketSummaries`
* Only use markets using the `config.mainMarket` here `USDT`
* Only use market which are `ONLINE`
* Check against market summary to see if the quote volume is greater than 0 (market is being traded on)
* Use those filtered marked for the next step -> `evaluateMarkets`
* Iterate over every market
* Ignore HODL markets (just buy some manually and HODL on)
* Get candles
* Count EMA ticks. Positive and negative
* If you got some of that asset in your balance
* If it's on the blacklist it will sell it. E.g. Bittrex delisting coins
* If it got too many negative ticks it will sell it
* If you don't have any of that asset in you balance
* If it's not blacklisted and got the amount of positiv ticks it will buy

**Selling**: It will be a limit sell with `timeInForce: TimeInForce.FILL_OR_KILL` Meaning, either it gets sold directly or the order gets canceled and will be tried next round.

**Buying**: The positiv ticks need to be exact the value defined in the config. This will prevent buying into a market "too late"

## (optional) Report
```
// await this.report();
```
Enable this line to report your current state. You will also need to enter your url in `api/BittrexApi.ts report()`

This could be used to track your bot and how much your balances are worth over time.

## Requirements
Node.js

As package manager install yarn https://classic.yarnpkg.com/en/docs/install

## Usage
## Configuration

### Bittrex API key and API secret
How to get: https://support.coinigy.com/hc/en-us/articles/360001123973-How-do-I-find-my-API-key-on-Bittrex-com-
Expand All @@ -127,26 +53,37 @@ Change the configuration parameters to your liking `config.json`

For more details see the documentation in `./modules/configuration/Configuration.ts`

## Build and start
### (optional) Setup crash reporting with sentry
Create a free monitoring project https://sentry.io/

Set `SENTRY_DSN` as environment variable.

## Run and development

### Build and start
```
yarn
yarn start
```

This will create a `/dist` folder and start the containing `/dist/index.js` file

## Build bundle
### Build bundle
```
yarn
yarn build
```

This will create a `/dist` folder containing the created `.js` files. You could now deploy it on any server you like

## Development
### Development
```
yarn
yarn start:dev
```

This will start the bot in a watch mode. On every code change it will recompile and restart

## Discussion and wiki

Feel free to join the [discussion](https://github.com/TeamWertarbyte/crypto-trading-bot/discussions) and [wiki](https://github.com/TeamWertarbyte/crypto-trading-bot/wiki) here on github
8 changes: 7 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
"mainMarket": "USDT",
"minNegativeTicks": 2,
"refreshTimeout": 180000,
"tickInterval": "DAY_1"
"tickInterval": "DAY_1",
"emaConfiguration": {
"default": {
"s": 9,
"l": 26
}
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "crypto-trading-bot",
"version": "2021.1.2",
"version": "2021.1.3",
"scripts": {
"build": "tsc",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "eslint \"src/**/*.ts\" --fix",
"start": "tsc && node dist/src/index.js",
"start:dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"ts:generate": "typescript-json-validator ./src/modules/configuration/Configuration.ts Configuration"
"ts:config-generate": "typescript-json-validator ./src/modules/configuration/Configuration.ts Configuration"
},
"dependencies": {
"@sentry/node": "^6.0.3",
"@sentry/tracing": "^6.0.3",
"crypto-js": "^4.0.0",
"debug": "^3.0.1",
"dotenv": "^8.2.0",
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from 'fancy-log';

import * as Sentry from '@sentry/node';
import { BittrexApi } from './modules/api';
import Bot from './modules/bot';
import { getConfig } from './modules/configuration';
Expand All @@ -18,14 +18,25 @@ log.info('Loading configuration…');
const config = getConfig();
log.info('Successfully loaded configuration', config);

Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
debug: config.debug
});

const api = new BittrexApi(
process.env.BITTREX_API_KEY,
process.env.BITTREX_API_SECRET
);
const bot = new Bot(api, config);

const loop = async () => {
await bot.start();
try {
await bot.start();
} catch (e) {
log.warn(e);
Sentry.captureException(e);
}
setTimeout(() => loop(), config.refreshTimeout);
};

Expand Down
Loading

0 comments on commit a6a1e5a

Please sign in to comment.