pub struct Trading {
pub quantity: f64,
pub presets: Vec<OrderPreset>,
pub account_panel: AccountPanel,
pub display: TradingSettings,
/* private fields */
}Expand description
The trading controls of one chart, connected to the host’s Broker.
Call poll every frame, show_ticket before laying out
the chart, so the order ticket takes its panel beside it, and show after the
chart. Open the order ticket with open_ticket, for example from the
chart menu’s Order entries, and route
the chart’s Buy and Sell buttons (Chart::take_quote_action) to trade.
Orders reach the broker only from the ticket’s submit button, or once the user confirms them
in the depth ladder, or at once from Buy and Sell and the ladder when the user turned on
TradingSettings::instant_orders.
use egui_charts::model::OrderSide;
use egui_charts::widget::QuoteSide;
trading.poll(ui.ctx(), toasts);
trading.show_ticket(ui, chart);
chart.show(ui);
if let Some(side) = chart.take_quote_action() {
if side == QuoteSide::Ticket {
trading.open_ticket(egui_charts::model::OrderRequest::new(chart.symbol(),
OrderSide::Buy, trading.quantity, egui_charts::model::OrderType::Market));
} else {
let side = if side == QuoteSide::Buy { OrderSide::Buy } else { OrderSide::Sell };
trading.trade(chart.symbol().to_owned(), side);
}
}
trading.show(ui, chart);Fields§
§quantity: f64The quantity the ticket opens with, and that instant orders and the chart menu’s orders use. Positive, in the symbol’s trading units. The chart’s legend shows it under the quote buttons’ spread, where a click opens a calculator that changes it.
presets: Vec<OrderPreset>The quantity and brackets the user saved in the ticket. Persist them in the host.
account_panel: AccountPanelThe account panel’s names and the history it lists.
display: TradingSettingsThe chart settings’ trading options: what show draws, whether Buy and
Sell trade at once, which events raise notifications and whether fills ask for a sound.
Copy the chart settings’ trading
options here when the user applies them.
Implementations§
Source§impl Trading
impl Trading
Sourcepub fn show_account_panel(
&mut self,
ui: &mut Ui,
chart_symbol: &str,
) -> Option<AccountPanelAction>
pub fn show_account_panel( &mut self, ui: &mut Ui, chart_symbol: &str, ) -> Option<AccountPanelAction>
Shows the account panel in ui, such as a bottom panel of the terminal, for a chart
showing chart_symbol. Returns what the user asked of the host; cancelling, changing and
closing go to the broker after the user confirms them in show.
Source§impl Trading
impl Trading
Sourcepub fn poll(&mut self, ctx: &Context, toasts: &mut Toasts)
pub fn poll(&mut self, ctx: &Context, toasts: &mut Toasts)
Applies the broker’s pushes and answers, reconnects a lagged stream, and reports refused
orders and fills in toasts. Call it every frame, even while the chart is hidden.
Sourcepub fn take_execution_sound(&mut self) -> Option<String>
pub fn take_execution_sound(&mut self) -> Option<String>
The sound to play for the fills since the last call, when the user turned on
TradingSettings::play_execution_sound: the name the user chose, or empty for the
host’s first sound. The host plays it; call this after poll.
Source§impl Trading
impl Trading
Sourcepub fn show_ticket(&mut self, ui: &mut Ui, chart: &Chart)
pub fn show_ticket(&mut self, ui: &mut Ui, chart: &Chart)
Draws the order ticket, while it is open, as a panel at the right of ui for the chart’s
symbol. Call it before laying out the chart, so the chart takes the space left. Sends the
order the user submits, and the orders the user places from the depth ladder; a change to a
working order or the position waits for the confirmation show asks for.
Sourcepub fn export_image(
&self,
chart: &Chart,
ctx: &Context,
options: &ImageExportOptions,
) -> Result<ChartImage, ExportError>
pub fn export_image( &self, chart: &Chart, ctx: &Context, options: &ImageExportOptions, ) -> Result<ChartImage, ExportError>
Exports the chart with its visible trading overlays when
TradingSettings::include_in_image is enabled. Account data and display settings
stay unchanged; the host delivers the returned frame.
Sourcepub fn export_png(
&self,
chart: &Chart,
ctx: &Context,
options: &ImageExportOptions,
) -> Result<Vec<u8>, ExportError>
pub fn export_png( &self, chart: &Chart, ctx: &Context, options: &ImageExportOptions, ) -> Result<Vec<u8>, ExportError>
Encodes Self::export_image as PNG bytes for host file, clipboard or sharing delivery.
Sourcepub fn export_svg(
&self,
chart: &Chart,
ctx: &Context,
options: &ImageExportOptions,
) -> Result<String, ExportError>
pub fn export_svg( &self, chart: &Chart, ctx: &Context, options: &ImageExportOptions, ) -> Result<String, ExportError>
Writes Self::export_image as SVG, as Chart::export_svg does.
Sourcepub fn draw_export(&self, ui: &mut Ui, chart: &mut Chart)
pub fn draw_export(&self, ui: &mut Ui, chart: &mut Chart)
Draws a frozen chart and its opted-in trading overlays inside an image layout callback.
Use with Chart::export_layout_image and Chart::export_snapshot for several charts.
Source§impl Trading
impl Trading
Sourcepub fn set_quote(&mut self, symbol: &str, quote: Quote)
pub fn set_quote(&mut self, symbol: &str, quote: Quote)
Sets the latest quote of symbol, such as the one WatchlistPanel::quote holds for the
chart’s symbol. While the chart shows symbol, the ticket enters a market buy at the
quote’s ask and a market sell at its bid; without them, at the last price.
Sourcepub fn set_instrument(&mut self, instrument: Instrument)
pub fn set_instrument(&mut self, instrument: Instrument)
Describes instrument to the trading panels: its price decimals write the prices of its
symbol in the account tables, and its pip size gives the ticket a pip value when the
broker’s TradingRules::pip_value is absent. The chart’s own instrument is used for the
symbol it shows, so call this for the other symbols of the account, such as those of
positions and working orders. Its logo marks the symbol in the account tables and notices.
A symbol without an instrument shows two decimals.
Sourcepub fn set_formatter(&mut self, formatter: Option<Arc<dyn TradingFormatter>>)
pub fn set_formatter(&mut self, formatter: Option<Arc<dyn TradingFormatter>>)
Writes the prices, quantities, spreads and pip values of the ticket, the depth ladder and
the account tables with formatter, where it returns text. None restores the built-in
text.
Sourcepub fn set_service(&mut self, service: Arc<dyn Broker>)
pub fn set_service(&mut self, service: Arc<dyn Broker>)
Connects to service, dropping the previous account’s state.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnects from the broker, dropping the account’s state.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether a broker is set and connected: the last status it pushed on the current stream is
FeedStatus::Live, or it pushed none. False while it reports that it is
Connecting or Disconnected, and
without a broker; has_broker tells whether one is set.
Sourcepub fn has_broker(&self) -> bool
pub fn has_broker(&self) -> bool
Whether a broker is set, from set_service until
disconnect, connected or not.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
The order types and features the account accepts; none before the broker reports them.
Sourcepub fn open_ticket(&mut self, request: OrderRequest)
pub fn open_ticket(&mut self, request: OrderRequest)
Opens the order ticket filled from request, for the user to check and submit.
Sourcepub fn toggle_ticket(&mut self, symbol: String)
pub fn toggle_ticket(&mut self, symbol: String)
Opens the order ticket for symbol, or closes it when it is open, as the toolbar’s Trade
button does.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Trading
impl !UnwindSafe for Trading
impl Freeze for Trading
impl Send for Trading
impl Sync for Trading
impl Unpin for Trading
impl UnsafeUnpin for Trading
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more