Coding trading bos

Hi, anyone coding his own trading bot here? I’m doing one for myself, let me know if you have exprience with this area or trading and want to collaborate/ need collaboration.


1 Like

Hi @ali
I have coded a trading bot for Binance. It’s been up and running for a few months, doing alright, but I’m refactoring some of the core functionality to calculate better trading margins.

I’d be keen see if anyone else is coding a bot; also what indicators are being used?
Also, if there are any math wizards here (as I am no math wiz), I’d be keen to discuss formulae.

1 Like

Hopefully, this is useful to someone out there with the same issue.

Leaving aside all the plumbing (connecting to web socket, receiving ticker data, trading using an API, etc.) the devil really is in the details.

I’m currently tweaking my bot to generically calculate trading margins regardless of currency.
So that the bot can detect a price change of 1% and make a trade.
Sounds simple right?

As an example, BTCUSDT trades (atm) around 7500.00 where as SUBBTC trades around 0.00005315.
This means that a 1% differential for BTCUSDT is 75.00, and for SUBBTC 0.00000053.

This is a huge difference when a bot tries to make a decision on whether to trade.
And really, I want to avoid the whole mess that is:

if (SUBBTC) apply x%
if (BTCUSDT) apply y%
if (OTHER) apply z%
... and so on

Another thing to consider is that BTCUSDT day trades within a range of 0.5% (usually) and SUBBTC day trades within a range of 3 or 4%.
Thus, a 1% diff for BTC is too big and for SUB is too small to be an effective indicator.

To generically calculate a margin requires some sort of weighting:

  1. Take the average of the range in price
  2. Take the average of the range %age and a specified %age
  3. Calculate a weighted factor based on these averages

The following C# snippet shows this.
Note: ‘_bufferMin’ and ‘_bufferMax’ are member variables whose value is calculated every minute when candlestick data comes from the exchange. (e.g. the min and max price over a 6 hour (buffer) period). ‘price’ represents the ticker price to compare, and ‘factor’ represents the percentage: 2.5% = 0.025 as a factor)

decimal? _bufferMin;
decimal? _bufferMax; 

decimal CalcWeightedPriceFactor(decimal price, decimal factor)
    if (_bufferMin.HasValue && _bufferMax.HasValue) 
        if (_bufferMin.Value != _bufferMax.Value) //to avoid divide by zero
            var range = _bufferMax.Value - _bufferMin.Value;
            var rangeAvg = (_bufferMax.Value + _bufferMin.Value) / 2;
            var rangeFactor = range / rangeAvg;
            var factorAvg = (factor + rangeFactor) / 2;
            var weighting = (factor / rangeFactor);
            var weightedFactor = weighting * factorAvg;    
            return price * weightedFactor;					
    return price * factor;  //i.e. backstop

A little verbose, but you get the idea.

1 Like