Giter VIP home page Giter VIP logo

triangulararbitrage's Introduction

Triangular Arbitrage - Binance

  • Monitor multiple currencies in a single exchange via websockets.
  • Calculate rate for all possible triangular ab -> bc -> ca paths, via live bid quote.
  • Calculate and subtract fees from rate.
  • Sort and display top opportunities in descending order.
  • Store historic opportunity information in DB, for later aggregation & analytics.

Contributions

My focus is currently not on further developing this project, but I will review pull requests. If you'd like to help, pull requests are openly welcome.

Contributions & Thanks

If you found this project interesting or useful, create accounts with my referral links:

Or buy me coffee using any of these:

  • BTC: 1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk
  • ETH (ERC20): 0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da

Related projects

Check out my related projects:

Setup

Install Dependencies

Clone & Install Repo

git clone https://github.com/tiagosiebler/TriangularArbitrage.git
cd TriangularArbitrage
npm install

Configuration

Misc Settings

See conf.ini

Usage

npm start

The result of this is a live stream from a number of pairs:

Top Potential Arbitrage Triplets, via: BNB,ETH,USDT

Step A    Step B    Step C    Rate      Fees BnB  (Rate - BnB Fee)    Fees Normal      (Rate - Fee)
BTC       BNB       GTO       10.420%   0.521%    9.899%              1.042%           9.378%
BTC       BNB       WAVES     2.558%    0.128%    2.430%              0.256%           2.302%
BTC       BNB       OST       1.536%    0.077%    1.459%              0.154%           1.382%
BTC       BNB       BRD       1.006%    0.050%    0.956%              0.101%           0.905%
BTC       BNB       BCPT      0.946%    0.047%    0.898%              0.095%           0.851%
BTC       ETH       EOS       0.663%    0.033%    0.630%              0.066%           0.596%
BTC       ETH       DLT       0.638%    0.032%    0.606%              0.064%           0.574%
BTC       BNB       WABI      0.633%    0.032%    0.601%              0.063%           0.569%
BTC       BNB       DLT       0.629%    0.031%    0.597%              0.063%           0.566%
BTC       ETH       MANA      0.553%    0.028%    0.525%              0.055%           0.497%
BTC       ETH       AMB       0.540%    0.027%    0.513%              0.054%           0.486%
BTC       BNB       LSK       0.540%    0.027%    0.513%              0.054%           0.486%
BTC       BNB       NEO       0.525%    0.026%    0.499%              0.053%           0.473%
BTC       ETH       BTG       0.522%    0.026%    0.496%              0.052%           0.470%
BTC       ETH       POWR      0.502%    0.025%    0.477%              0.050%           0.452%
BTC       ETH       CDT       0.487%    0.024%    0.462%              0.049%           0.438%
BTC       ETH       LEND      0.427%    0.021%    0.406%              0.043%           0.384%
BTC       USDT      LTC       0.402%    0.020%    0.382%              0.040%           0.362%
BTC       ETH       DGD       0.396%    0.020%    0.377%              0.040%           0.357%
BTC       ETH       MTL       0.382%    0.019%    0.363%              0.038%           0.344%
BTC       BNB       AION      0.361%    0.018%    0.343%              0.036%           0.325%
BTC       ETH       LTC       0.356%    0.018%    0.338%              0.036%           0.320%
BTC       BNB       POWR      0.356%    0.018%    0.338%              0.036%           0.320%
BTC       ETH       XMR       0.327%    0.016%    0.311%              0.033%           0.294%
BTC       USDT      NEO       0.295%    0.015%    0.281%              0.030%           0.266%
BTC       ETH       SALT      0.287%    0.014%    0.273%              0.029%           0.258%
BTC       BNB       XZC       0.285%    0.014%    0.271%              0.028%           0.256%
BTC       ETH       QTUM      0.250%    0.012%    0.237%              0.025%           0.225%
BTC       ETH       BAT       0.237%    0.012%    0.225%              0.024%           0.213%
BTC       ETH       FUN       0.236%    0.012%    0.224%              0.024%           0.212%
BTC       ETH       DASH      0.232%    0.012%    0.220%              0.023%           0.209%
BTC       ETH       OMG       0.228%    0.011%    0.216%              0.023%           0.205%
BTC       ETH       BCPT      0.223%    0.011%    0.212%              0.022%           0.201%
BTC       ETH       LSK       0.207%    0.010%    0.197%              0.021%           0.186%
BTC       ETH       ADX       0.206%    0.010%    0.196%              0.021%           0.186%
BTC       ETH       GTO       0.191%    0.010%    0.182%              0.019%           0.172%
BTC       USDT      BCC       0.169%    0.008%    0.161%              0.017%           0.152%
BTC       USDT      ETH       0.161%    0.008%    0.153%              0.016%           0.145%
BTC       ETH       CMT       0.159%    0.008%    0.151%              0.016%           0.143%

Docker Setup

Install Dependencies

Clone repo

git clone https://github.com/tiagosiebler/TriangularArbitrage.git
cd TriangularArbitrage

Usage

If you are running for the first time or when you have made no changes to code or config

docker-compose up

If you have made any config or code changes

docker-compose kill
docker-compose build
docker-compose up

triangulararbitrage's People

Contributors

arrandir avatar devfubar avatar qbkjovfnek avatar tiagosiebler 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  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

triangulararbitrage's Issues

How to run bot ?

How to launch the robot ?, It does not perform any operation, it is not yet functional ??

Rank B-paths (BNB/ETH/USDT) over time, so enough volume for multiple top C-paths can be sent through step B

B-paths are always one of the main currencies/silos (BNB/ETH/USDT).

Over time we can rank which B-paths present the top opportunities over a given amount of time. That can be used to estimate a high probability if we take enough volume through A->B, we have enough to take several profitable C-routes back to A(BTC) in parallel - rather than being limited by the max profitable volume via one single C-route.

Skim through the top opportunities, even if there’s not much volume in them per currency pair, overall we could use several to get from step B back to A(BTC) with more volume than we could send through only one

Martingale trading / DCA

We know what pairs can be traded now and the expected profits in terms of probability but we now like to delay losses. To do this we have to integrate a martingale feature (more info: https://goo.gl/rx48rA).

In fact this means that we double the amount that we have trade if we have lost a trade.

In relation to Profit Trailer the script should work with different DCA tier levels, for example:

max_buy_times = 6

#--------------------------------------------------------------#
#BUY SETTINGS #

DCA MEAN DOLLAR COST AVERAGING THIS STRATAGY BUYS MORE COINS #IF THE INTIAL BUY PRICE DUMPS A CERtAN PERCANTAGE TO BRING UP #THE AVERAGE LOSS OF THE COIN MEAKIN IT EASIER FOR IT TO REVOCER #AND MAKE A PROFIT

buy_strategy = ANDERSON
buy_style = DOUBLEDOWN
buy_trigger_1 = -1.5
buy_trigger_2 = -3.5
buy_trigger_3 = -7.5
buy_trigger_4 = -9.5
buy_trigger_5 = -12.5
buy_trigger_6 = -17.5

Means: if the Technical analysis show we have to buy and we lose 1.5%. We double the bet and buy more. We do this in max. 6 tiers / levels. NOTE: bets are only doubled if the technical analyses also tells us to buy so it will be a double check: price is dropped at least a X percentage AND TA tells us too buy

Probabilistic programming for selecting the best technical analysis

We will use different strategies to trade with but the more strategies tells us that we need to buy at the same time, the higher the probability.

For this we need a kind of nested / ranked model to define if we should buy or not (more confirmation is a positive buy call).

Additional we can integrated some Probabilistic programming;
https://github.com/omphalos/bayesian-bandit.js

More background on wiki: https://en.wikipedia.org/wiki/Probabilistic_programming_language

Start technical analysis (phase 2)

In the config we need a setting:

Activate_TA = true/false.

True: if activated the arbitrage tool will make use of the next level of trading opportunities. Meaning; if the arbitrage fails we will also start trading with technical strategies.

Also the DCA feature will now be activated. More details about the working will be added in the next project phase 2.

Paper trading requirements

Now we can see the:

  • Best performing pairs (calculated in issue 6)
  • Trend directions (calculated in issue 9)
  • Know the volume and orderbooks (calculated in issue 6)

We need to know what the probability is for each pair combination to trade with. For this we need a paper trading solutions. Meaning a test tracking of the trades.

To set this up we have to do:

  • Simulate the trading for the pairs that we should trade.
  • Calculate a random delay (dynamic percentage or random) to simulate order delays
  • Log the trades per pair
  • Log where the pairs fail (step a-b, b-c, c-a)
  • Log the amount that is won/lose
  • Log the prices and orderbooks that where available for each trade
  • Trading time between each pair

This script feature should do this calculation all the time in the background (example every 5 minutes with the new ticks) and save the results in the background.

Based on the logging an automatic calculation should be made to see:

  • The probability for each pair combination to succeed/lose
  • Profit per pair / combination
  • Calculate the minimal amount that is needed for every pair / combination that is required to make a positive arbitrage. This can be done by automatically checking the best fitting price based on the differences of the log prices within the trades

Now this is done we need the final logging calculation. This calculation should compare the best traded pairs with each other for calculating:

  • Sharpe ratio: per pair combination so we can see what pair is positive (code for this below)
  • Sortino ratio: per pair combination
  • See the mean time of delay / trading time
  • Summarize the best performing pairs and their probabilities for trading a positive result (percentages can be used in a later stage in monte carlo sims)

(check point 2 and 3 in this OneNote: https://goo.gl/FpsLLK)

Additional information that can be useful: https://goo.gl/xsXDsS

Spotting trends

We only want to trade coins in the correct direction. The means:

  • If we buy: we expect the price should go down
  • If we sell: we expect the price go up

Because: the larger the differences between the price, the bigger the opportunity for arbitrage.

This means we need to spot trends for pairs. To get this work we can integrate the Hilbert Transform trend vs Cycle models.

the sign of cross rate calculation is wrong

I run a script and was surprised to see abnormally huge arbitrage opportunities. So I decided to pick a case and manually check rate calculation. My findings are below.

The script reported 10.58% rate for the sequence BTC -> BNB -> RCN.

Respective orderbooks were:

  • RCN/BNB: 0.003659 / 0.004078
  • RCN/BTC: 0.00000786 / 0.00000792
  • BNB/BTC: 0.00213080 / 0.00213140

Arbitrage steps were:

  1. buy BNB for BTC (ask is 0.00213140)
  2. buy RCN for BNB (ask is 0.004078)
  3. sell RCN for BTC (bid is 0.00000786 which then gets inverted)

The cross rate calculated is 0.00213140 * 0.004078 / 0.00000786 = 1.1058332316 (10.58%)

The issue is that at steps 1-2 I'm supposed to buy RCN (for BTC via BNB) and the cross rate would be 0.00213140 * 0.004078 = 0.00000869.
At step 3 I'm supposed to sell this RCN for 0.00000786 or 10.58% cheaper.

So the rate is properly calculated, the only issue is that in this case it represents 10.58% loss, not 10.58% win opportunity.

Mechanism for monitoring order books - websockets available?

  • Are there websockets for monitoring order books for key tickers passively?
  • Or do we have to proactively request that information on demand?
  • if websockets, design passive monitor (similar to current 1-sec all-currencies ticker stream), so info is available when needed, rather than query on demand.

Is tradeInfo object correct?

I check the structure of candidate object's attribute a, b and c. There's a tradeInfo object content side, symbol, quantity.

screen shot 2018-06-30 at 12 37 25 pm

I print it in TradeCore and I find

screen shot 2018-06-30 at 12 25 31 pm

the side sames incorrect, If I trade by this, In the first, I sell bnb buy eth, then buy qlc sell bnb and then sell qlc buy eth, eventually, I use 2 time bnb, get 2 time eth(ignore quantity). I think after arbitrage, all trade done. I use 1 bnb should get maybe 1.1 bnb, that 0.1 bnb is profit. But trade by this, its not balance. Or each arbitrage candidate not alone?

ADA boosting - select best indicators

ADA Boosting is a solution to combine different indicators / strategies via an algo and to find the best / weak combinations.

Example code:
https://github.com/mtaxot/adaboost-trading-system

Aim: to allow automatic scanning to combine different indicators / strategies in the background. If certain combinations have a> 70% prediction value, they must be automatically converted to strategies to be able to trade.

Background: http://andromeda.rutgers.edu/~jmbarr/NYComp/CreamerEEA.pdf

timeout error

events.js:182
throw er; // Unhandled 'error' event
^

Error: connect ETIMEDOUT 31.13.68.1:9443
at Object.exports._errnoException (util.js:1016:11)
at exports._exceptionWithHostPort (util.js:1039:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache_logs\2018-11-07T02_56_51_375Z-debug.log

why Is not creating orders on exchange?

What I'm doing wrong? I setup the config.ini, .keys and the the column "(rate - fee)" already shows 3.25%

my config.ini:


#####################################
#### Calculation Settings ##########
##################################

# Pair ranking
#####################################
#### Calculation Settings ##########
##################################

# Pair ranking
pairRankerTable=pair_ranking
minimalProfit=1.02
#default 15 minutes, in MS
pairTimer=900000
#other configs
ALL_trading_enabled=true
#Example for max cost
ALL_max_cost = 0.010
#Define the minimum volume for each pair
ALL_min_buy_volume=200
#Define minimum buy price
ALL_min_buy_price=0.00000500
#Define max trading pairs
ALL_max_trading_pairs=50
#Define minimum profit in procentage
ALL_min_profit=.7

Shadow scanner

Now there is made a selection in the tool to check for the best and worst pairs to trade on we still need to scan the markets on the background to see if the pairs will change in performance.

A bad pair can be running good in a later timeframe for example.

To make sure bad pairs dont are traded by exident it can be a good idea to update the blacklist/toplist every hour based on the results of the last hour.

This means good/bad pairs should still be checked in the last hour.

Mean, sDev and Z-score calculation

Calculate the mean, standard deviation, and z-score of the pair ratio / spread.

This because we like to know what the mean price is of the pair (so we can see if the arbitrage opportunity can still be succesful if the trade fail and we wait till the next opportunity come back on track.

For more details and examples how and why to implement this part check:
https://goo.gl/SpLq92

Open source code for this tutorial can be found here:
https://goo.gl/FtywPs

Auto trading

Does the bot open and close orders automatically?

Thanks for the great work

Calculate price differences

Calculate the price changes between the top performing pairs top see if the price change a lot over time.

This will give more insight in the solutions to:

  • Wait trading for the best price
  • Or just always trade and keep in mind that the price can change in the trading time so loses can be made (but makes trading faster and ensure no orders will stuck)

Correlation and Cointegration

To get even a higher edge in the pair trading we have to calculate the cointegration between the coins.

Background:
Correlation – If two stocks are correlated then if stock A has an upday then stock B will have an upday
Cointegration – If two stocks are cointegrated then it is possible to form a stationary pair from some linear combination of stock A and B

A good example is give here (plus code, check both links):
http://gekkoquant.com/2012/10/21/statistical-arbitrage-correlation-vs-cointegration/
http://gekkoquant.com/2012/12/17/statistical-arbitrage-testing-for-cointegration-augmented-dicky-fuller/

Coins with a higher cointegration should get a higher ranking to trade first with

Setup modulair strategy structure

To create a flexible strategy model we have to make sure we can integrate new strategies very easy. This can be done by setup the strategy structure like this:

  • Library folder: will contain technical analysis libraries like: https://goo.gl/PRzBjG
  • Indicator folder: based on the information in the library folder we setup indicators that we like to use for strategies (like RSI, MACD, EMA, etc.)
  • Strategy folder: will contain all the strategies and preconditions when to buy.

it is not understood how it works

Hello, can someone explain to me how would be the operation in vase to the table that is displayed after running npm star?. We buy B and immediately change it to C?, And at what price do we buy B and C ?, and when we have already bought C what do we do? We change by BTC ?? if so, do not count the commissions to go from C to BTC ?? .. Please someone to put a short description of how it would be a full arbitrage operation with this program based on the table shown when we run the program. Thank you very much.

Chart building

Now paper trading is done and we have the stats for each trading combination we like to keep this information stored in the background so we can build some stats. Because we dont have to log everything we only like to know:

  • Best performing and probabilities for pair combinations per hour / Plus worst (for building a blacklist)

This information should be saved locally. Now the tool should have a script running in the background while running to check if there are differences are in the pair combinations based on:

  • Day time
  • Week day

If the percentage of some pairs is higher/lower on specific day times or week days these pairs should get an extra highlighted ranking. Meaning that these pairs should be trades before lower ranked pairs.

Define configuration settings for default

In the config we need some settings like (profit trailer inspiration):

NOTE: some settings will not be active on arbitrage trading (like spread, take profit etc).

#(means trade all or define what to trade like BTC-ETH, BTC-NEO, BTC-DASH)
ALL_trading_enabled = true

#THIS IS THE PRICE IN BTC YOU WILL MAKE THE FIRST BUY AT
ALL_max_cost = 0.0025

#THIS IS THE MINIMUM VALUE OF ANY COIN THAT YOU WOULD LIKE TO TRADE

ALL_min_buy_volume = 300

#THIS IS THE AMOUNT OF COINS YOU WANT TO TRADE AT ONCE (START SMALL)

ALL_max_trading_pairs = 2

#This prevents the bot from buying low Satoshi coins--AKA PUMPS
ALL_min_buy_price = 0.00005

#THIS IS OUR BUY STRATEGY. Define the trailing buy
ALL_trailing_buy = 0.35

#THIS IS OUR SELL STRATEGY. Define the trailing take profit (stop)
ALL_sell_strategy = GAIN
ALL_sell_value = .89
ALL_trailing_profit = 0.33

#Enable DCA for all pairs with a balance
ALL_DCA_enabled = -1.5

#PLACE ANY COINS THAT YOU WANT TO HOLD LONG TERM HERE BEFORE STARTING THE BOT
EOSBTC_trading_enabled=false
NEOBTC_trading_enabled=false

#Max spread % between lowest ask and highest bid to allow a new buy order if spread is too big, most likely there was a coin dump/pump and you are buying too high (only use this for technical analyse trading and not in the arbitrage)
ALL_max_buy_spread = 1

SETTINGS FOR DCA (default)

enabled = true
max_cost = 0
max_buy_times = 6

#--------------------------------------------------------------#
#BUY SETTINGS #

DCA MEAN DOLLAR COST AVERAGING THIS STRATAGY BUYS MORE COINS #IF THE INTIAL BUY PRICE DUMPS A CERtAN PERCANTAGE TO BRING UP #THE AVERAGE LOSS OF THE COIN MEAKIN IT EASIER FOR IT TO REVOCER #AND MAKE A PROFIT

buy_strategy = ANDERSON
buy_style = DOUBLEDOWN
buy_trigger_1 = -1.5
buy_trigger_2 = -3.5
buy_trigger_3 = -7.5
buy_trigger_4 = -9.5
buy_trigger_5 = -12.5
buy_trigger_6 = -17.5

#THIS TELLS THE BOT TO WAIT TIll IT FALLS ANOTHER .1 in Value #Before it buys protecting you from further drops in value #before buying.

trailing_buy = 0.0777

pending_order_wait_time = 0
ignore_sell_only_mode = true

#--------------------------------------------------------------#
sell_strategy = GAIN
sell_value = .86
trailing_profit = 0.25
#--------------------------------------------------------------#

#SAFTEY SETTINGS#

max spread % between lowest ask and highest bid to allow a new buy order

if spread is too big, most likely there was a coin dump/pump and you are buying too high

max_buy_spread = 2

stop_loss_trigger = 0

Advisory log

Now all the basics are integrated we can start with the real trades but before we can start with this we like to know what the minimum amount is that is advised to start with.

Based on the logging and predictions we should have a calculation where we can give an input with the max amount we like to start trading with. Also we should enter the risk level percentage that we find acceptable to start trading in each arbitrage trade (default 1% of your start amount). And the max level for martingale. The output of the calculator should show:

  • Minimal/maximum pairs that should be traded at the same time
  • Risk level of this settings

[Bounty][0.005-0.01 BTC] Enhance project to perform live trades

Hello , if this project can do :
fully automatic monitoring and auto multiply total amount of btc(binance minimum order limit is 0.001 Btc) and auto order 3 or more profit road(after calc the higher profit of triangular arbitrage pair like :
road1 :BTC-XX1-ETH-BTC 0.02% profit
road2 : BTC-XX2-ETH-BTC 0.018% profit
road3 : BTC-XX3-BNB-BTC 0.011% profit ) on few second and 24/7. running without problem or crash , i will donate 0.005-0.01 BTC , Hope someone can do this work , Thanks You !

Possible inconsistency in DB data for arbitrage_ticks

If you look at the ticks_arbitrage table at a random row. You can see that (for example) the 'a_step_from: BTC' and 'a_step_to:ETH' . But if you collapse the A: Object then stepFrom: ETH and StepTo: BTC so it is the otherway around, that does not seem right? Step B and Step C do not have this issue. I already checked the code and that seems correctly, as a_step_from is assigned to StepFrom... but the output does not match

Example object:

    "a" : {
        "e" : "24hrTicker",
        "E" : 1514987934215.0,
        "s" : "BNBBTC",
        "p" : "-0.00003470",
        "P" : "-5.538",
        "w" : "0.00058985",
        "x" : "0.00062672",
        "c" : "0.00059186",
        "Q" : "9.00000000",
        "b" : "0.00059013",
        "B" : "476.00000000",
        "a" : "0.00059185",
        "A" : "203.00000000",
        "o" : "0.00062656",
        "h" : "0.00063062",
        "l" : "0.00052900",
        "v" : "4510157.00000000",
        "q" : "2660.31029749",
        "O" : 1514901534215.0,
        "C" : 1514987934215.0,
        "F" : 3924337,
        "L" : 4037342,
        "n" : 113006,
        "_id" : ObjectId("5a4ce19eb0de5e54e65c95b7"),
        "key" : "BTC",
        "startsWithKey" : true,
        "endsWithKey" : false,
        "flipped" : false,
        "rate" : "0.00059013",
        "stepFrom" : "BNB",
        "stepTo" : "BTC"
    },
    "a_symbol" : "BNBBTC",
    "a_step_from" : "BTC",
    "a_step_to" : "BNB",

internal stepFrom mismatches external a_step_from, why?

Quick start for strategies in NodeJs

Why create everything ourself if we can reuse working strategies.

For a quick start we integrate the current strategies. Note that some preconditions should be added later as these strategies itself are not working good for the full 100% (some stuff should be combined) but first focus on the integrations:

https://goo.gl/rTGJhp

Auto trade

I see that it shows great arbitrage opportunities. Does it have functionality to auto trade because only bot can react so fast. A found that there is a config already for auto trading (docs/brainstorm/config.md)?.

Prevent maximum arbitrage amount

To implement a part of the risk management we have to configure what the maximum amount (x%) is to trade with in the arbitrage part; for the symbols:

  • BTC
  • ETH
  • BNB

Reason; if we don't check this max there will be a moment we don't have coins 'free' anymore for doing the arbitrage. Also; if pairs fail in the arbitrage process the amount will be locked in other coins.

The available free amount will be used for the next trading levels (2 and 3) where we start working with the DCA levels.

Error in PairRanker.js

C:\Users\work\Documents\GitHub\TriangularArbitrage\lib\PairRanker.js:27
while (!check && k < 5 && candidates[0].rate > parseFloat(process.env.minimalProfit)) {
^

TypeError: Cannot read property 'rate' of undefined
at PairRanker.getPairRanking (C:\Users\work\Documents\GitHub\TriangularArbitrage\lib\PairRanker.js:27:42)
at Object.ctrl.storage.streamTick (C:\Users\work\Documents\GitHub\TriangularArbitrage\lib\BotCore.js:18:41)
at CurrencyCore.events.onAllTickerStream.stream (C:\Users\work\Documents\GitHub\TriangularArbitrage\lib\CurrencyCore.js:324:24)
at WebSocket.ws.on (C:\Users\work\Documents\GitHub\TriangularArbitrage\node_modules\binance\lib\ws.js:21:13)
at emitOne (events.js:96:13)
at WebSocket.emit (events.js:188:7)
at Receiver._receiver.onmessage (C:\Users\work\Documents\GitHub\TriangularArbitrage\node_modules\ws\lib\WebSocket.js:141:47)
at Receiver.dataMessage (C:\Users\work\Documents\GitHub\TriangularArbitrage\node_modules\ws\lib\Receiver.js:389:14)
at perMessageDeflate.decompress (C:\Users\work\Documents\GitHub\TriangularArbitrage\node_modules\ws\lib\Receiver.js:349:40)
at _decompress (C:\Users\work\Documents\GitHub\TriangularArbitrage\node_modules\ws\lib\PerMessageDeflate.js:306:9)

fees explained

I'm not sure I fully understand why fee percentages would be different among arbitrage triplets.

If a fee for a trade is 0.1% then 3 steps should cost a constant fee of 0.1%*3 = 0.3%. Why would they differ?

Issue when launching

Sorry for this nb question. Probably something that I've missed during the installation of MongoDB but any help will be appreciated.
I get the following error:
npm-debug.log

/Users/HoneyGuide1/TriangularArbitrage/index.js:71
require('./lib/DBCore')(logger, (err, db)=>{
^^
SyntaxError: Unexpected token =>
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

npm ERR! Darwin 17.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! This is most likely a problem with the TriangularArbitrage package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get their info via:
npm ERR! npm owner ls TriangularArbitrage
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/HoneyGuide1/TriangularArbitrage/npm-debug.log

Automatically select the best performing pairs

We like to give ranking numbers to the best performing pairs and worst performing pairs so we can make an automated top list of the trading pairs.

To do this:
While running the tool a log of data should be collected. In this selection we need to check:

  • Pair combinations that are best performing (means in the top 10 many times); pairs with high performing results should get a +1 rank, bad coin combinations -1.

  • How long does the arbitrage opportunity exist: we like to know how fast we have to trade so we must know how long the opportunity over all the pair combinations (A-B-C-D) will exist to be able making a positive profit on the trades. Minimal profit should be configured dynamically in the configuration file but should be 2% as default.

  • Check the mean price of pair combinations over time to see if there is a stable price over time for trading (pairs with a stable price can be traded with some delay but unstable prices have more risk); pairs with stable prices should get a +1 rank, bad coin combinations -1.

NOTE: mean price should be also check the orderbook (ask/bid prices) to see if there is much spread between the prices. The spread distance can be calculated with the Standard deviation (more information below). For a good point of view we can add more ranking to pairs that are in line with the following basic strategies:

If spread(t) >= Mean Spread + 2Standard Deviation then go Short
If spread(t) <= Mean Spread – 2
Standard Deviation then go Long

(if direction to buy / sell is in line with the expectation of the arbitrage we rank the pair a higher +1 or -1)

Background for the sDev
Statistically, in a normal bell curve distribution of prices; 68% of prices should fall within +/- one standard deviation of the mean, 95% of prices should fall within +/- two standard deviations of the mean, and 99.75% of prices should fall within +/- three standard deviations of the mean.

Logging of the coins should taken 15 minutes max. After this we flush all information >15 minutes.

NOTE: make flush time dynamic in the configuration file.

Real trading

We now have the complete basic settings to start real trades. Optimization, AI etc. is the next job but there is a moment you have to step into the big world of trading :)

In the config we need a value; true/false for real trading to activate.

How trading should work

Based on the settings in the config the tool will start scanning.

  • Based on the ranking of the best pairs a trade will be started with the maximum defined amount in the config.
  • In the config should be defined how we buy/sell. As we have 2 options:
  1. Sell/buy strategy = Marketprice: the tool see an opportunity and buy and sell the pairs always for the Marketprice. Risk is that the prices will change but we will never stay with dust.

  2. Sell/buy strategy = Limitprice: the tool calculate the maximum buy price and minimal sell price for each pair and place limit orders. This will ensure we always sell for the price we need to make profit as calculated in the arbitrage. Risk; prices can change and we can't sell the coins anymore.

IN CASE 2 WE NEED THE NEXT TRADING SOLUTION

a. We wait 5 minutes (make time dynamic in config) to see if the price change and the opportunity come back.
b. After wait time the scanner will start finding arbitrage opportunities for the failed coin. The arbitrage loop should end again at the failed coin:

example; we start A-B-C-A. But the process fails at B. Now the scan should start looking to opportunities to B-C-A-B.

Reason for this setup: as we can define the coins we like to trade with we only buy coins that we already would buy ourself. In the worst case we end with more coins than that we started.

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.