Эта страница пока не переведена на язык «Русский», поэтому показана на английском.
Moving to 3.0
3.0 is on npm (npm i @tradecanvas/chart). It lists
each change that can break code written for 2.x and what to do about it. For 1.x to 2.0, see Moving to 2.0.
Behaviour that changed
A confirmed bracket goes to the execution adapter
With an execution adapter connected (chart.connectExecution(adapter)), a confirmed bracket is now
sent to it as one order: the entry with its quantity, its stop-loss and its take-profit. In 2.x it stayed the bracketPlace event unless the adapter was connected with brackets: 'place', and the
chart warned once in the console that it was not sent.
- Your code places the event's bracket itself. Connect with
brackets: 'event', or the bracket is placed twice: once by the chart and once by you. - You passed
brackets: 'place'. Nothing to do; the option can go. - No adapter connected. Nothing changes: the bracket is the
bracketPlaceevent.
// 2.x: an event, unless asked // 3.0: an order, unless asked
chart.connectExecution(broker) chart.connectExecution(broker, { brackets: 'event' })
chart.connectExecution(broker, { brackets: 'place' }) → chart.connectExecution(broker) A bracket is sent with the quantity it is sized with. One with none is not confirmed: it stays on the chart, and executionError says so (reason: 'noQuantity'). The widget's bracket bar now has a
quantity field, so the brackets its toolbar starts have one; a bracket your code starts takes a size as the
third argument (see Trading):
chart.startBracket('buy', undefined, { quantity: 2 })
chart.startBracket('buy', undefined, { risk: 50 }) // the quantity that loses 50 at the stop Sell and Buy show on the chart with an execution adapter
With an execution adapter connected and the order ticket on, the widget now shows Sell and Buy under the chart's legend. A host that connects an adapter only to draw its orders and positions turns them off:
new ChartWidget(el, { features: { tradeButtons: false } }); With orderTicket off, or with no adapter, they never show. A host that turns every order switch
off by name has one more to name: tradeButtons is new, and on unless set.
The paper account fills a stop-limit within its limit
PaperExecutionAdapter filled a stopLimit order at its stop, as a stop order. It now
makes it a limit order at its price once the stop is reached: the order stays working (its type
reads 'limit') until the price is within the limit. A test that expected a position as soon as the
stop was reached moves the price within the limit first, or places a 'stop' order.
A price set by hand is on the market's grid
orderModify, positionModify, bracketPlace, the orderPlace of a draft order or of the
right-click menu, priceAxisAdd and chartContextMenu carried the price under the pointer as a pixel gives it
(62549.71592675613). They now carry it on the market's price step, else to the decimals the price axis
shows: what chart.roundPrice gives. A bracket and a draft order start on the grid too, whatever price they are started at, and an alert dragged lands on it. A line let go on the step it was on reports nothing. Code that rounded
these itself can stop.
On a market with a ceiling and a floor for the day, an order's own price is kept inside them too: dragged past one, it is reported at it.
Under a finger, no control is smaller than 32 px
On a device whose main pointer is coarse (a phone, a tablet), the widget's controls are now 32 px each way at
least, in every look and density: a compact widget on a tablet no longer has 24 px
buttons, and each row of the indicator legend is 32 px tall where it was 20. Under a mouse the drawing is as it
was and only what a press takes changes: 20 px each way at least. A page that measured the widget's parts on a
touch screen (a legend's height, a dialog's) reads larger numbers.
An order from the ticket waits for the adapter's answer
With an execution adapter connected, the order ticket no longer shuts as it places: it waits until the adapter's placeOrder resolves (it shuts) or rejects (it stays, and says why). An adapter whose placeOrder never settles leaves the ticket waiting: resolve with the order, or reject with the reason.
Three more things changed with it. Every orderPlace payload now carries a clientOrderId, and placeOrderIntent returns the order as sent (it returned nothing). A market order from the ticket carries
the ask for a Buy and the bid for a Sell as its price, where the feed gives both (it was the last price).
And an order asked for in one press, from the right-click menu or the depth ladder, is for the market's lot where it
has one (it was for 1, and the ladder's had no quantity).
Orders, positions and fills are drawn on their own symbol
An order, a position or a fill that names its symbol is drawn only while the chart shows that
symbol. On another it is kept: getOrders(), getPositions() and getFills() give the whole account, and chart.getSymbol() says which of it is drawn. The chart now names the
symbol it shows on every orderPlace payload and the paper account keeps it, so a position opened on
one symbol is not drawn on the next, where it was, with a profit counted from the wrong price. What names no
symbol is drawn on every symbol, as before: an adapter of your own for an account of several symbols names it on
its orders, positions and fills.
Three things changed with it. Every fill told by executionFill and getFills() has a symbol once the chart shows one, and ChartWidget no longer forgets the fills when its
symbol changes: the history and the realised profit are the account's, and the marks come back with their
symbol. setMarkPrice takes the symbol as a third argument, which the chart gives in a replay: fed
prices that name their symbol, the paper account works and values each symbol by its own; fed prices that name
none, it is one market, as it was. And with bars set by hand the chart knows no symbol until it is told: chart.setSymbol(symbol), which ChartWidget calls itself.
A press held on the chart shows the price popup
In ChartWidget, a mouse press held still on the plot for half a second shows the floating OHLCV tooltip
for the bar under the pointer, until the button is let go: the tooltip follows the pointer and the chart does not pan
meanwhile. A press held that long is therefore no longer a click, nor the start of a pan. The widget's crosshairTooltip feature is now 'hold' where it was false: pass chartOptions: { features: { crosshairTooltip: false } } for no popup, as before, or true for one under a pointer that hovers. The headless Chart is not changed: its tooltip follows the pointer
unless told otherwise, and takes 'hold' too.
One-press orders wait for a live price
With a feed of its own (adapter), ChartWidget no longer sends an order asked for in one
press (the right-click menu, the depth ladder), nor a bracket or a draft order confirmed, while that feed is not
connected: it says why instead. While the feed is not connected, or has told nothing for a minute
(feedQuietAfter), the ticket sends no market order, and the status bar says “No price updates” where
it said “Live” over a stalled stream. feedQuietAfter: 0 never calls a connected feed quiet; a feed
that is not connected holds orders back all the same.
One-press trades are confirmed, and a bid on the ladder is bought at
ChartWidget now asks before a position is closed or reversed (the account panel, the buttons on the
chart) and before an order from the right-click menu or the depth ladder is placed: they went out in one press. confirmOrders: false keeps one press. On the depth ladder a press on a bid now places a buy limit at that price, and a press on an ask a sell limit, where a bid was sold
into and an ask bought: orderPlace carries the other side from the same cell than it did. A test or a
script that pressed those cells, or expected an order at once, needs the confirmation's button
(.tcw-confirm .tcw-done-btn) or the option.
The widget's default look is Graphite
A ChartWidget with no ui is now drawn in the Graphite look, where it was Modern:
neutral grounds, corners of 3 px, a 40 px toolbar, and what is picked shown on a lighter ground, not on amber. The
chart's own colours change with it (GRAPHITE_DARK_THEME, GRAPHITE_LIGHT_THEME) unless theme is an object of yours. ui: 'modern' keeps the look before it, colours and all. The
stylesheet's default tokens are Graphite's, so CSS that set a few --tcw-* tokens over Modern's now
sets them over Graphite's. In every look the order ticket's button now names the order
(Buy 100 HPG), the order's value is the last line over it, and a position's row in the account panel
ends with its P&L and its Reverse and Close buttons after it, past its stop and target: a test that read the button's text or a column by its place
needs the new one.
Vietnamese shares are worth their price in dong
MARKET_HOSE, MARKET_HOSE_ETF, MARKET_HNX and MARKET_UPCOM write a price in thousands of dong (26.40 is 26,400 dong) and now say so: their contractMultiplier is 1,000. An order's value in the ticket, a position's profit in the account panel
and the amounts on the chart's tags are counted by it, so 100 shares at 26.40 read 2,640,000 where they read
2,640. On every market the amounts on the chart's tags (a position's profit, what a stop or a target would make)
are now counted by the market's multiplier, as the panel's were: a VN30F position's tag reads in dong, not in
points. scaleMarketPrices divides the multiplier by its factor, so scaleMarketPrices(MARKET_HOSE, 1000), with prices in dong, has a multiplier of 1. If you multiplied
by 1,000 yourself (in formatAmount, or in what you show beside the chart), stop. A PaperExecutionAdapter given no multiplier of its own now takes the market's from the
chart it is connected to (the chart calls the adapter's optional setMultiplier, when connected and
when the market changes), so its margin, its balance and its fills' profit are in the same money; one given a multiplier keeps it. A Long or Short Position drawing and a bracket sized by risk count
the quantity that risk buys by the multiplier too: 5,000,000 dong at risk with the stop 1.00 away is 5,000
shares, where it was 5,000,000. positionLevels(drawing, multiplier) takes the market's as its second
argument. A position keeps the multiplier it opened with (TradingPosition.multiplier, which the paper account
sets): a chart shown another market, or another symbol, revalues nothing that is open, and the panel and the
chart's tags count each position by its own. A market made by spreading a preset keeps the preset's
multiplier: { ...MARKET_HOSE, pricePrecision: 0, priceStep: 10 } for prices in dong still has
1,000, and reads a thousand times too much. Use scaleMarketPrices(MARKET_HOSE, 1000), or set contractMultiplier: 1 in the spread.
What is sent to a broker is as it was, but for a quantity worked out from a risk, as above.
A position's markPrice is what it is counted at
If your execution adapter gives a position a markPrice, the account panel's row and the chart's tag
now count the position at it, for a position of the chart's own symbol too; before, the price was read only for
a position of another symbol, and the chart's latest price counted the rest. So keep it current: say the
positions again as the mark moves. An adapter that stamps it once shows a row that stands still. Leave the field
out to have the chart's latest price as before. A markPrice of 0 is taken for none.
The order ticket opens in the dock, beside the chart
The widget's order ticket was a dialog over the chart, on the price it was filled in for. It is now a page of the dock, beside the chart: it hides no price, a press on the chart does not shut it, and it stays for the next order once one is sent, on the same side, kind and quantity. Its button is on the dock's rail, and widget.openPanel('orderTicket') opens it with a ticket at the market.
'orderTicket' is one more WidgetPanel: getOpenPanel() and onPanelChange report it, and a page of your own cannot take that id. On a phone, or with the dock off (features: { dock: false }), the ticket is the dialog it was. A host that wants the dialog at every width says so:
new ChartWidget(el, { ticketPlace: 'dialog' }); Types that grew
TimeInForce is now 'gtc' | 'day' | 'gtd' | 'ioc' | 'fok'. Code that handles every
member (a switch with no default, a Record<TimeInForce, …>) needs the three new
ones; an execution adapter of your own may refuse those it does not take.
FillReason has 'liquidation' too, for a position the paper account closed in a
stop-out, and ExecutionEventType has 'marginCall'. Neither happens unless the paper
account is given stopOutLevel or marginCallLevel, but code that handles every member
needs them.
Not changed
- Data, saved layouts and settings from 2.x load as before.
- Indicators, drawings, themes and style keys keep their names.