Blog

The bot can export market data: 5-minutes candles and trades for all active markets (BTC, USDT or ETH) to the local UDP port (IP 127.0.0.1).

The bot can also accept signals sent to UDP port.

This function is currently in beta testing.

To turn it on go to the Settings -> Advanced tab, put the checkbox "UDP Export"

The bot is sending market data in binary format, as arrays of count elements in each UDP packet (look format below) to the UDP port 2000. Use buffer size=65000. Candles are sent as whole array (up to 500 elements) once in 5 minutes. Trades are only new since last update but note that 1 data packet may contain more then 1 trade.

The bot is listening for signals on UDP port 1999, signals should be sent in plain text format. Received signals are handled in the bot buy special "UDP" strategy: (Dont forget to turn on  Settings -> Advanced ->  "UDP Export" checkbox):

 

Signal example: 'Key=Test1 Coin=NEO Order=buy BuyPrice=0.0071'.

Parameters:

  • Key=  the keyword by which the bot picks one of UDP strategies. The key must match the strategy "ChannelKey" property, in the example above its "Test1".
  • Coin=  the coin to buy
  • Order=
    • buy - buy order
    • sell - activate Panic Sell on coin bought by any strategy
  • BuyPrice=  limit buy order price. If ommited then the strategy settings will be used.

 

Code example: (download source with small compiled demo)

  // structures

  TOrderType = (O_SELL,O_BUY,O_BuyStop);

  TUpdateKind = (UK_Candles, UK_Trades);

  TUpdateHeader = packed record
    Version:          byte;         // 1 byte -  packet version, currently 1
    TimeStamp:        dword;        // 4 bytes -  Unix timestamp
    Kind:             TUpdateKind;  // 1 byte - candles (0) or trades (1) inside
    Coin:             string[7];    // 7 bytes - coin ticker name
    Count:            word;         // 2 bytes - elements count in the data array
    reserved1:        dword;        // 4 bytes currently unused  
    reserved2:        dword;        // 4 bytes currently unused     
  end;

  TTradeOrder = record   // 8-bytes aligned            
    ID:                       integer;
    Time:                     TDateTime;
    Price:                    double; 
    Quantity:                 double; 
    BuyerID:                  integer; 
    reserved:                 integer; 
    OrderType:                TOrderType; 
    FillType:                 byte; // 0 - PARTIAL, 1 - FULL
  end;

  TCandle = record
    OpenP,CloseP,MaxP,MinP:   double;
    Vol:                      double;
    Time:                     TDateTime;
  end;

  TTrades = array of TTradeOrder;
  TCandles = array of TCandle;

 

// Data reading and handling


procedure TfrmUDPTest.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;
  const AData: TIdBytes; ABinding: TIdSocketHandle);
var
  hdr:        TUpdateHeader;
  Trades:     TTrades;
  Candles:    TCandles;
begin
  move(AData[0], hdr, SizeOf(hdr));

  If hdr.Kind = UK_Trades then begin
    SetLength(Trades, hdr.Count);
    move(AData[SizeOf(hdr)], Trades[0], hdr.Count * SizeOf(TTradeOrder));
    If SelectedCoin = hdr.Coin
      then lPrice.Caption:=hdr.Coin + ' Last: ' + FloatToStr(Trades[hdr.Count - 1].Price);
  end;

  If hdr.Kind = UK_Candles then begin
    SetLength(Candles, hdr.Count);
    move(AData[SizeOf(hdr)], Candles[0], hdr.Count * SizeOf(TCandle));
    lLastCandle.Caption:=' Last candle: ' + hdr.Coin + ' 5m vol: ' + FloatToStr(Candles[hdr.Count - 1].Vol);
  end;

  lLastTrade.Caption:=Format('Last update: %s  time: %d', [hdr.Coin, hdr.TimeStamp]);
end;