Trades folded into candlestick data as a live chart takes them, in the order given: inside the forming bar's interval its high, low, close and volume move and its open holds; past it a new bar opens at the trade's price, on the interval's boundary counted from origin (milliseconds since 1970 UTC; 1970 itself when left out, a Thursday, so give a Monday's origin for weeks from Monday). A trade before the last one taken is late and counted in the reply: inside the forming bar it is folded into its high, low and volume, and its open where it is the earliest, never its close; before it, it changes nothing. Candles as candlestick takes them, with lastTrade and openedAt as the last reply gave them (empty to begin); dates in UTC, YYYY-MM-DD or with THH:MM, THH:MM:SS or THH:MM:SS.sss, the last a bar of the interval. Each trade { t: milliseconds since 1970 UTC, price, size of naught or more }; the interval in milliseconds (60000 a minute, 86400000 a day). Returns the candles, to draw with render_chart as candlestick, and how many trades were taken and late.
The arguments candle_tick takes.| Argument | Type | Required | Notes |
|---|
candles | object: { dates, candles, lastTrade, openedAt } | No | — |
|---|
trades | array of { t, price, size } | Yes | — |
|---|
interval | number, above 0 | Yes | — |
|---|
origin | number | No | — |
|---|
An example call
{
"trades": [
{
"t": 0,
"price": 100,
"size": 10
},
{
"t": 15000,
"price": 102,
"size": 5
},
{
"t": 45000,
"price": 99,
"size": 8
},
{
"t": 61000,
"price": 103,
"size": 6
},
{
"t": 90000,
"price": 105,
"size": 4
},
{
"t": 125000,
"price": 101,
"size": 7
}
],
"interval": 60000
}
What comes back
{
"dates": [
"1970-01-01T00:00",
"1970-01-01T00:01",
"1970-01-01T00:02"
],
"candles": [
{
"o": 100,
"h": 102,
"l": 99,
"c": 99,
"v": 23
},
{
"o": 103,
"h": 105,
"l": 103,
"c": 105,
"v": 10
},
{
"o": 101,
"h": 101,
"l": 101,
"c": 101,
"v": 7
}
],
"lastTrade": 125000,
"openedAt": 125000
}
6 trades taken in time order, 0 late: 0 of them folded into the forming bar (its high, low and volume, and its open where one is the earliest), never its close, 0 before the forming bar, changing nothing