Documentación

Historial de ticks

DatosSin autenticación

Obtenga datos históricos de Tick para un símbolo. Solo cambió el valor predeterminado del parámetro count .

Comparación rápida

AspectoLegacy APINew APIAcción
Endpointticks_historyticks_historyNinguno
Requiere autenticaciónNoNoNinguno
Predeterminado count50001000Establezca count de forma explícita

Cambios importantes

1. Valor predeterminado de count modificado

El parámetro count no cambió, pero su valor predeterminado cuando no lo envía es menor en la New API.

  • Legacy: count tiene un valor predeterminado de 5000 ticks por solicitud.
  • New: count tiene un valor predeterminado de 1000 ticks por solicitud.

Cambio obligatorio: Si necesita más de 1000 ticks y no envía count, envíelo explícitamente.

Estructura de solicitud

Legacy APIejemplo de solicitud
{
  "ticks_history": "frxEURUSD",
  "end": "latest",
  "start": 1234567890,
  "style": "ticks",
  "count": 100,
  "adjust_start_time": 1,
  "subscribe": 1
}
New APIejemplo de solicitud
{
  "ticks_history": "frxEURUSD",
  "end": "latest",
  "start": 1234567890,
  "style": "ticks",
  "count": 100,
  "adjust_start_time": 1,
  "subscribe": 1
}

Estructura de respuesta

Legacy APIejemplo de respuesta
{
  "echo_req": {
    "ticks_history": "frxEURUSD",
    "end": "latest",
    "start": 1234567890,
    "style": "ticks",
    "count": 100,
    "adjust_start_time": 1,
    "subscribe": 1
  },
  "history": {
    "prices": [
      1.085,
      1.0851
    ],
    "times": [
      1234567890,
      1234567891
    ]
  },
  "msg_type": "history",
  "pip_size": 5,
  "subscription": {
    "id": "c84a793b-8a87-7999-ce10-9b22f7ceead3"
  }
}
New APIejemplo de respuesta
{
  "echo_req": {
    "ticks_history": "frxEURUSD",
    "end": "latest",
    "start": 1234567890,
    "style": "ticks",
    "count": 100,
    "adjust_start_time": 1,
    "subscribe": 1
  },
  "history": {
    "prices": [
      1.085,
      1.0851
    ],
    "times": [
      1234567890,
      1234567891
    ]
  },
  "msg_type": "history",
  "pip_size": 5,
  "subscription": {
    "id": "c84a793b-8a87-7999-ce10-9b22f7ceead3"
  }
}

Ejemplos de código

async function getTicksHistory(symbol) {
  const request = {
    ticks_history: symbol,
    end: "latest",
    start: Date.now() / 1000 - 86400,
    style: "ticks",
    count: 100,  // Defaults to 5000 when omitted
    adjust_start_time: 1,
    subscribe: 1
  };

  ws.send(JSON.stringify(request));

  ws.onmessage = (event) => {
    const response = JSON.parse(event.data);

    // echo_req is guaranteed
    console.log('Request:', response.echo_req);

    if (response.msg_type === 'history') {
      // history.prices and history.times are optional
      if (response.history) {
        if (response.history.prices) {
          console.log('Prices:', response.history.prices);
        }
        if (response.history.times) {
          console.log('Times:', response.history.times);
        }
      }
    }

    if (response.msg_type === 'candles') {
      // Each candle property is optional
      response.candles?.forEach(candle => {
        const close = candle.close ?? null;
        const open = candle.open ?? null;
        const high = candle.high ?? null;
        const low = candle.low ?? null;
        console.log({ open, high, low, close });
      });
    }
  };
}
Click to open live chat support. Get instant help from our support team.