Giter Site home page Giter Site logo

socktrader / socktrader Goto Github PK

View Code? Open in Web Editor NEW
395.0 18.0 58.0 8.75 MB

🚀 Websocket based trading bot for 💰cryptocurrencies 📈

License: GNU General Public License v3.0

TypeScript 99.60% JavaScript 0.23% Dockerfile 0.15% Shell 0.02%
nodejs websockets cryptocurrencies trading-bot trading crypto candlesticks trading-platform trading-algorithms trading-strategies

socktrader's Introduction

SockTrader logo

SockTrader v2

Cryptocurrency trading bot

License: GPL v3 Build status

Join the community Slack

What is "SockTrader"?

SockTrader is an open source cryptocurrency trading bot. You can use it to automatically buy and/or sell cryptocurrencies based on a strategy that you've programmed. The strategy basically contains a set of rules that will define when and how the bot should act in the cryptocurrency market. These rules can be based on technical analysis (what is technical analysis?) or you could simply tell the bot to buy/sell at certain price levels. In fact, it's up to you to decide the rules of the game!

The name "SockTrader" comes from websocket based trading bot. Which means that SockTrader will try to make use of a realtime connection with the exchange. This has the advantage that one can act very quickly in a changing market with low latency.

Looking for SockTrader v1?

The dashboard is currently incompatible with SockTrader v2. Use SockTrader v1 instead

Features

  • 🚀 Realtime super-fast websocket trading.
  • 📈 50+ Technical indicators. (docs)
  • 🌈 Written in TypeScript!
  • 🌿 Unit tested source code.
  • 📝 Paper trading a strategy on LIVE exchange data.
  • 🏡 Backtesting engine with local data.
  • 🚢 Run SockTrader inside a docker container.
  • More features soon..

Getting started

Quickstart

  1. Git clone git clone [email protected]:SockTrader/SockTrader.git && cd SockTrader
  2. Install NodeJS dependencies. npm i
  3. Copy config/default.json to config/local.json and edit.
  4. Start postgres database docker-compose up
  5. Run the MovingAverageStrategy on LocalExchange. npm run start:backtest

Connect your Binance account

You feel like your strategy is production ready? Good! We'll help you to connect your SockTrader strategy to your Binance account.

  1. Copy config/default.json to config/local.json
  2. Go to your Binance account under API Management, create a new API key
  3. Provide the apiSecret and apiKey in config/local.json
  4. Don't forget to change the exchange in your strategy to new Binance() and you're good to go!

API key restrictions

By default, the newly created API key does not allow you to place orders, only reads are allowed. To get started:

  1. Go to your Binance account
  2. Under API restrictions enable 'Enable Spot & Margin Trading'

Join the community

Slack

Contributors

DISCLAIMER

Using a trading bot does not mean guaranteed profit.
Also, trading crypto currency is considered high risk.
Losses are possible, which SockTrader cannot be held responsible for.

socktrader's People

Contributors

cwouter avatar dependabot[bot] avatar greenkeeper[bot] avatar nathanwaddell121107 avatar semantic-release-bot avatar thijs-raets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socktrader's Issues

[BUG] instructions not complete or problem with websocket connection

Very interesting project. I'd like to add some functionalities and work with it (I'm doing a bot with nodejs by my own, inspired by some on github). I found really interesting the part with tradingview chart connected with the trading system.
Anyway, before spend some time and developing, I'd like to see something.
I made a backtest as the examples [OK].
I run unit tests [OK].
I run the web-server as dev (as sudo because it needs root privileges to open ports below 1024).
Then I downloaded Dashboard project, run it, after some seconds it open a blank page with a top bar with title "SockTrader", and in the right part the status (X) and a button "Start". I found some errors on console, it seems it cannot connect via "WebSocket connection to 'ws://localhost:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED" (the web-serve was live).
Maybe instructions are not complete to run it (?)
Is it possible to see the tradingview part if already working? (if you tell me the library used and the cost is not too much I'd like to try it buying the license)

Thanks

Add fees and slippage

Requirements

  • Add configurable amount of fee in config file.
  • Add configurable amount of slippage in config file.
  • Fee should be correctly calculated and subtracted from wallet.
    • calculate fee during live trading?
    • or use fee calculated by exchange? (if possible)

Use configurable transports to decide where the output should go to

The tradingbot currently logs (hardcoded) to a file and the console. We could improve this so that the user can decide (by changing the config.ts file) where the ouput should go to.

Later on we can extend this by adding extra transports for Kafka, RabbitMQ, ElasticSearch, Loggly, Webhooks, AWS, etc..

Support partially filled orders in wallet

Current situation

The wallet ignores partially filled orders and will not reflect the intermediate balance. The final balance will be updated once the order is completely filled.

Expected situation

Intermediate results should be reflected in the wallet balance. The balance of each asset should be reserved and released correctly. More info in example below

Given

  • User has wallet with 10 bitcoins and 1000USD
  • Current bitcoin price is 100USD
  • No trading fees

Expected

  • User creates buy order of 5 bitcoins
  • Wallet = 10 bitcoins and 500USD (500USD will be reserved)
  • Only 1 bitcoin has been filled
  • Wallet = 11 bitcoins and 500USD (1 bitcoin has been released)
  • The remaining order has been cancelled
  • Wallet = 11 bitcoins and 900USD (the remaining USD has been released)

An order stream should first emit a 'new' order before a 'filled' order

The testOrderStream test in exchanges.spec.ts is currently incorrect.

When creating a limit order the OrderStream should first create a new order, and later on update (or eventually mark as filled) this order.

Current:

<Order>{
  side: OrderSide.BUY,
  createTime: new Date('2020-02-24T14:00:00'), // note: order.create != trade.create
  status: OrderStatus.FILLED,
  symbol: 'BTCUSDT',
  type: OrderType.LIMIT,
  ...
}

Expected:

// order create
<Order>{
  side: OrderSide.BUY,
  createTime: new Date('2020-02-24T14:00:00')
  status: OrderStatus.NEW,
  symbol: 'BTCUSDT',
  type: OrderType.LIMIT,
  ...
}

// order update
<Order>{
  side: OrderSide.BUY,
  createTime: new Date('2020-02-24T15:00:00')
  status: OrderStatus.FILLED,
  symbol: 'BTCUSDT',
  type: OrderType.LIMIT,
  ...
}

Use central state management

The state of each class should be stored in a central store (redux for example). This would make it possible to serialize the state to disk and resume later on from the last known state.

Related to: #27

[REQ] Publish docker image to docker hub

💩 Is your feature request related to a problem? Please describe.

It should be easy to start, run and control SockTrader regardless of the host environment.

🏗️ Describe the solution you'd like

Create Dockerfile

  • Dockerfile that builds and runs @socktrader/cli
  • Add environment variables to configure database connection
  • use ENTRYPOINT to run container as an executable

Automatic builds

  • Make sure that a pull request should not break the Dockerfile

Automatic publish

  • It should be automatically pushed to docker hub when merged to master
  • The version should be defined by semantic-release in dry-run mode
  • It should not publish a new version when no package has been changed

Some technical guidance:

Test behaviour of concurrent strategies on the same exchange

SockTrader should be able to run concurrently in a microservices environment. Which means that we should be able to spawn multiple docker containers of SockTrader with different strategies and timeframes.

We should definitely test the behaviour when one strategy is creating orders and the second strategy is receiving exchange events of the newly created orders.

Possible solution

  • We could try to tag orders with a unique strategy id.
  • We could encode a unique strategy id into the order id.
  • Keep a local record of all orders and the strategy that created them.

[BUG] A possible glitch or sequence reset on HitBTC exchange causes sequences to be dropped.

Describe the bug
A (papertrading) tradingbot instance is dropping orderbook updates since 2019-12-31T15:40:29.913Z. First line in the log says: "Sequence dropped: 624086, last one: 26941144".

This might occur because of incorrect response from the exchange (glitch). Or a sequence number reset.. possibly because of NYE?

Possible solution
A hardcoded threshold will allow huge changes in the sequence to be applied.

Add warm up phase to a strategy.

The HitBTC API sends an initial batch of 100 candles. This initial set of data should be ignored by the strategy. Otherwise it might trigger false signals based on historical data.

We can circumvent this behaviour by using it as "warm up" data. This means that "updateCandles" will be triggered once the exchange is sending real time data.

[BUG] https://cryptocointrader.be/ points at localhost:3000 to get list data

https://cryptocointrader.be/ - this doesn't load correctly See console error log:

localhost:3000/data/list:1 Failed to load resource: the server responded with a status of 404 (Not Found)
candles.ts:57 Error: Request failed with status code 404
    at e.exports (createError.js:17)
    at e.exports (settle.js:19)
    at XMLHttpRequest.d.onreadystatechange (xhr.js:60)
(anonymous) @ candles.ts:57
localhost:3000/strategy/list:1 Failed to load resource: the server responded with a status of 404 (Not Found)

Can you fix it so it doesn't point at localhost:3000 - it should point to the webserver host.

Resume trading with last known state after application restart

Backtesting

No need to remember anything

Paper trading

The application should remember:

  • open orders (at least price, side and amount)
  • wallet status (amount of each asset)

Live trading

The application should fetch the open orders from the exchange.
We can ignore the wallet, since we're not keeping a wallet status during live trading.

Log total wallet value on on each candle update (backtest)

Add functionality to assetValueLogger to log the total wallet value on each candle update. This could be useful during backtesting

TODO:

  • A new config property should be added: logOnUpdateCandles?: boolean; so that this can be configured by the user.
  • Conditionally call this.logAssetValue() in onUpdateCandles.

Simplify SockTrader for microservices architecture

Goal

To simplify the core API of SockTrader we should assume that 1 SockTrader (nodeJS) process should talk to 1 exchange using 1 strategy. This would make the application API overall easier and less error prone.

TODO:

  • refactor "addStrategy" in "setStrategy"
  • no need to share exchange data between strategies in "subscribeToExchangeEvents"
  • see if we can remove lodash dependencies
  • remove logrotate. (Should be handeld by another process.)

Add bitfinex exchange with websocket support

Todo

  • Write exchange class for Bitfinex similar to the HitBTC implementation
  • The class should also extend BaseExchange
  • Write a BitfinexMapper similar to the HitBTC implementation. This class will listen for exchange events, adapt data so that it matches the generic data standard and call the corresponding functions on the exchange.

Exchange documentation: https://docs.bitfinex.com/v2/docs/ws-public

Refactor backtest and papertrade decorators

#20 The solution of the "selfGeneratingOrders" decorator turned out to be quite a dirty solution. I am thinking about to refactor it so that the local exchange can either accept candles (like it does right now) or a "sub exchange". This sub exchange will provide the necessary data (candles etc..) for the local exchange to calculate the wallet reserves or generate local reports

backtesting = candles from a data file
papertrading = sub exchange

[REQ] Implement CCXWS as exchange

It should be interesting to see if we can implement CCXWS (Github) as a single exchange in SockTrader.

However I've noticed that it lacks a few important websocket events:

  • Orders & Trades
  • Wallet updates

An in-range update of @types/sinon is breaking the build 🚨

The devDependency @types/sinon was updated from 7.0.3 to 7.0.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Sort candles before starting a backtest

Currently, the local exchange has a "sortCandles" method. This method should be moved to the candle normalizer. The trading bot assumes that it will always receive clean data that is ordered correctly.

Update wallet during paper trading

Paper trading signals are only logged currently. Trading actions should also be reflected on the wallet so that a possible profit / loss can be calculated properly.

We currently have inconsistent behaviour between a local exchange and a remote exchange. Mainly because of small architectural differences between paper trading and backtesting. This will also be ironed out in this issue.

Trade decimal quantities of assets

Context

In JavaScript some floating point rounding issues might occur after applying arithmetic operations on numbers. More information can be found here and here

This might prevents us from trading accurate decimal quantities in SockTrader.
Possible libraries:

Acceptance criteria

  • calculation logic in wallet and analyzers use library for correct decimal handling
  • add unit testing to prove that no rounding issues occur

[REQ] Margin trading feature

Hello

I think a very nice feature could be Margin trading support (for now just backtesting), so not just buy and sell, but long, short and leverage.
An initial implementation could simply transform a current sell in a closing eventual long position and open a short one.

Thanks

Create an exchange using a factory function

Creating an exchange in SockTrader starts to get more complex. We should abstract this in a separate function / class.

An exchange can be created in 3 "different modes":

  • PaperTrading: data coming from remote exchange but reports are handled internally
  • BackTest: data coming from a local data file and reports are handled internally
  • Live: data and reports are coming from remote exchange

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.