<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TJ Alam</title>
    <description>The latest articles on DEV Community by TJ Alam (@tjalam).</description>
    <link>https://dev.to/tjalam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280677%2Fefb7bf80-0155-4c75-bc5c-a6bc0ca9b1f8.png</url>
      <title>DEV Community: TJ Alam</title>
      <link>https://dev.to/tjalam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tjalam"/>
    <language>en</language>
    <item>
      <title>How to Build a Trading Platform: 8 Steps From Idea to Launch</title>
      <dc:creator>TJ Alam</dc:creator>
      <pubDate>Sun, 06 Dec 2026 04:38:27 +0000</pubDate>
      <link>https://dev.to/tjalam/how-to-build-a-trading-platform-8-steps-from-idea-to-launch-1cin</link>
      <guid>https://dev.to/tjalam/how-to-build-a-trading-platform-8-steps-from-idea-to-launch-1cin</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://tjalam.com/blog/how-to-build-a-trading-platform" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;

&lt;p&gt;You build a trading platform by making eight decisions in order: who it is for, which broker or exchange sits underneath, what the first version leaves out, how the system is laid out, where prices come from, how orders are tracked, how it is tested, and how it goes live. Most failed builds skipped the first three and started with screens.&lt;/p&gt;

&lt;p&gt;This guide is written from the developer's side. It covers web platforms built on a broker or exchange API, which is how most new trading products start. It is about software, and none of it is financial or investment advice.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;The decision&lt;/th&gt;
&lt;th&gt;What you have at the end&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1. Users&lt;/td&gt;
&lt;td&gt;Who trades on it and what they do first&lt;/td&gt;
&lt;td&gt;A one-page product brief&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2. Broker&lt;/td&gt;
&lt;td&gt;Build on a broker or exchange API, or hold a licence yourself&lt;/td&gt;
&lt;td&gt;A named broker or exchange and account model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3. Scope&lt;/td&gt;
&lt;td&gt;What version one includes and what waits&lt;/td&gt;
&lt;td&gt;A feature list with a fixed quote&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4. Architecture&lt;/td&gt;
&lt;td&gt;How the services, database and real-time layer fit together&lt;/td&gt;
&lt;td&gt;A diagram and clickable screens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5. Market data&lt;/td&gt;
&lt;td&gt;Which feed, how it reconnects, how much history&lt;/td&gt;
&lt;td&gt;Live prices on a staging site&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6. Orders&lt;/td&gt;
&lt;td&gt;How order state, fills and positions are tracked&lt;/td&gt;
&lt;td&gt;Orders that match the broker's records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7. Testing&lt;/td&gt;
&lt;td&gt;Paper trading, automated tests and failure drills&lt;/td&gt;
&lt;td&gt;A platform that has run on live data without real money&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8. Launch&lt;/td&gt;
&lt;td&gt;Hosting, monitoring, alerts and rollback&lt;/td&gt;
&lt;td&gt;A live platform and a handover&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 1: Decide who it is for
&lt;/h2&gt;

&lt;p&gt;A platform for a trading educator's members is a different product from a platform for a fund's own desk, even when both show charts and take orders. Write down who the user is and what they should be able to do in their first five minutes. That one page decides more than any feature list.&lt;/p&gt;

&lt;p&gt;Useful questions: do users bring their own broker account or use yours? Do they place orders by hand, follow signals, or run strategies? Do they pay you, and for what? Who inside your business needs an admin view, and what do they need to see?&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Choose a broker API or become a broker
&lt;/h2&gt;

&lt;p&gt;This is the decision that sets cost and timeline. Most new trading products don't hold a brokerage licence. They build on a licensed broker's API, or on a crypto exchange's API, and the licensed firm holds client accounts and executes the orders. Your platform owns the product: the screens, the rules, the signals and the experience.&lt;/p&gt;

&lt;p&gt;Holding your own licence means your own compliance stack: identity checks, record keeping, reporting and the staff to run them. That can be the right call for a funded company, and it is a different project.&lt;/p&gt;

&lt;p&gt;Then pick the account model. Users can connect their own broker or exchange accounts with API keys, you can open client accounts under a broker's partner programme, or the platform can be read-only. Regulation depends on your country and model, so confirm your position with counsel before the build.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/broker-api-integration" rel="noopener noreferrer"&gt;Broker and exchange API integration&lt;/a&gt;· &lt;a href="https://tjalam.com/blog/hiring-fintech-developers-what-to-check" rel="noopener noreferrer"&gt;Hiring fintech developers: what to check&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Scope a first version
&lt;/h2&gt;

&lt;p&gt;A first version should prove one thing: that your users will use the product. Everything that doesn't serve that can wait. A sensible first version is usually one market, one broker or exchange and the features in the first list. The second list is what normally waits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In: sign-up and login, one broker or exchange connection, live prices, an order ticket, open positions and P&amp;amp;L, order history, an admin panel&lt;/li&gt;
&lt;li&gt;In: a paper-trading mode, risk limits and an audit log, because they are cheap early and expensive to add later&lt;/li&gt;
&lt;li&gt;Waits: a second broker, a mobile app, options and futures, social features, advanced charting tools, performance fees&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/trading-platform-development" rel="noopener noreferrer"&gt;Custom trading platform development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Lay out the architecture
&lt;/h2&gt;

&lt;p&gt;A trading platform has four parts that matter: a web app for users, an API that owns accounts and business rules, a real-time service that carries prices and order updates, and an integration layer that talks to the broker. Keep the broker behind that layer, so a second broker later is an addition and not a rewrite.&lt;/p&gt;

&lt;p&gt;Start as one deployable system with clear modules. Splitting into many services before you have users adds operations work and no speed. Agree the clickable screens at this step too, so the product is settled before the heavy build.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/blog/custom-trading-platform-architecture" rel="noopener noreferrer"&gt;How to architect a custom trading platform that scales&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Get market data right
&lt;/h2&gt;

&lt;p&gt;Prices arrive over WebSocket streams, and streams drop. The data layer needs automatic reconnection, a fresh snapshot after every reconnect, and throttling so a busy market doesn't freeze the browser. Decide early how much history you need: charts need candles, and backtests need far more.&lt;/p&gt;

&lt;p&gt;Check the data licence as well as the feed. Data that is free for your own use is often not free to show to your users.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/blog/real-time-market-data-websockets-guide" rel="noopener noreferrer"&gt;Real-time market data with WebSockets&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Track orders like money depends on it
&lt;/h2&gt;

&lt;p&gt;Order handling is where trading platforms differ from other web apps. An order can be accepted, partly filled, filled, cancelled or rejected, and the news can arrive late, twice or out of order. The platform keeps its own record of every order and updates it from the broker's events.&lt;/p&gt;

&lt;p&gt;Three habits prevent most incidents. Send every order with a unique client order ID, so a retry can never place it twice. Reconcile positions against the broker's records on a schedule and after every reconnect. Log every order and every admin action, so any dispute can be answered from the record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Test with paper money first
&lt;/h2&gt;

&lt;p&gt;Automated tests cover the parts that cost money when they fail: order states, position sizing, risk limits and reconciliation. Then the whole platform runs in paper mode on live market data, long enough to see a volatile session and a broker outage.&lt;/p&gt;

&lt;p&gt;Run failure drills on purpose. Cut the data stream, restart the server with orders open, and send the same order twice. A platform that has only been tested on a calm day has not been tested.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/backtesting-engine-development" rel="noopener noreferrer"&gt;Backtesting engine development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Launch, monitor and hand over
&lt;/h2&gt;

&lt;p&gt;Launch on your own cloud account, with monitoring on the things users feel: stream health, order latency, error rates and reconciliation differences. Alerts go to a person, and there is a kill switch that stops new orders without taking the site down.&lt;/p&gt;

&lt;p&gt;Start with a small group of users before opening the doors. Handover means the source code in your repository, deployment notes and a walkthrough, so the platform is yours to run with or without the original developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  How long it takes and what it costs
&lt;/h2&gt;

&lt;p&gt;A focused first version on one broker or exchange takes weeks, not quarters, and starts from $20,000 at Digi Flock Enterprises. Scope moves both numbers: each extra broker, asset class or user type adds work. The cost guide has the full price table and what each price covers.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/blog/trading-platform-development-cost" rel="noopener noreferrer"&gt;How much does it cost to build a trading platform?&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Build, buy or white-label?
&lt;/h2&gt;

&lt;p&gt;Not every trading product should be built. A white-label platform is faster when your product matches what it offers and your edge is in marketing or community. Building wins when the product itself is the edge: your own signals, rules, user experience or business model.&lt;/p&gt;

&lt;p&gt;There is a middle path: license the regulated or commodity parts, and build the layer your users see. A custom front end on a broker API is that path, and so is a custom dashboard on a licensed prop trading platform.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/blog/white-label-vs-custom-trading-platform" rel="noopener noreferrer"&gt;White-label vs custom trading platform&lt;/a&gt;· &lt;a href="https://tjalam.com/copy-trading-platform-development" rel="noopener noreferrer"&gt;Copy trading platform development&lt;/a&gt;· &lt;a href="https://tjalam.com/prop-firm-software-development" rel="noopener noreferrer"&gt;Prop firm software development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Five mistakes that sink trading platform builds
&lt;/h2&gt;

&lt;p&gt;The same problems come up in most rescue projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starting with screens before the broker and account model are decided&lt;/li&gt;
&lt;li&gt;A first version with three brokers, a mobile app and every chart tool&lt;/li&gt;
&lt;li&gt;Trusting the platform's own position numbers without reconciling against the broker&lt;/li&gt;
&lt;li&gt;No paper mode, so every test risks real money&lt;/li&gt;
&lt;li&gt;API keys stored in plain text or with withdrawal rights&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/contact" rel="noopener noreferrer"&gt;Book a scoping call&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I'm TJ Alam. I build custom trading platforms, bots and broker integrations at &lt;a href="https://tjalam.com" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;. The &lt;a href="https://tjalam.com/blog/how-to-build-a-trading-platform" rel="noopener noreferrer"&gt;full version of this guide&lt;/a&gt; stays up to date there.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>trading</category>
      <category>fintech</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Securing Fintech Applications: An OWASP-Aligned Checklist</title>
      <dc:creator>TJ Alam</dc:creator>
      <pubDate>Sun, 06 Dec 2026 04:31:43 +0000</pubDate>
      <link>https://dev.to/tjalam/securing-fintech-applications-an-owasp-aligned-checklist-3h6n</link>
      <guid>https://dev.to/tjalam/securing-fintech-applications-an-owasp-aligned-checklist-3h6n</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://tjalam.com/blog/securing-fintech-applications-owasp" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Broken access control: the most common finding in fintech audits
&lt;/h2&gt;

&lt;p&gt;Almost every fintech security review we've been part of turns up at least one access control gap - usually an API endpoint that checks whether a user is authenticated but not whether they own the specific resource being requested (an account, a transaction, a document). Every endpoint that accepts a resource ID must independently verify ownership or permission server-side, regardless of what the frontend already filtered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication and session management
&lt;/h2&gt;

&lt;p&gt;For financial applications, we treat multi-factor authentication as a baseline requirement, not an add-on. Sessions should have reasonable expiry, be invalidated on password change, and sensitive actions (changing bank details, large withdrawals) should require step-up authentication even within an already-authenticated session.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enforce MFA for account access and require step-up auth for high-risk actions&lt;/li&gt;
&lt;li&gt;Use short-lived access tokens with refresh tokens rather than long-lived sessions&lt;/li&gt;
&lt;li&gt;Invalidate all active sessions on password or email change&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sensitive data exposure
&lt;/h2&gt;

&lt;p&gt;Encrypt sensitive data at rest (PII, bank details, KYC documents) and in transit (TLS everywhere, including internal service-to-service calls where feasible). Avoid logging sensitive fields - a surprising number of data leaks trace back to application logs, not database breaches. Mask card numbers, account numbers, and SSNs in both logs and UI by default, showing only the last few digits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Injection and input validation
&lt;/h2&gt;

&lt;p&gt;Use parameterized queries or an ORM everywhere - no string concatenation into SQL, ever. Validate and sanitize all input server-side even if the frontend already validates it; the frontend is not a trust boundary. This applies doubly to any endpoint that accepts free text later rendered elsewhere (support tickets, chat messages) to prevent stored XSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third-party and dependency risk
&lt;/h2&gt;

&lt;p&gt;Run automated dependency vulnerability scanning (npm audit, Snyk, or similar) as part of CI, and review the actual permission scope granted to any third-party integration (payment processor, analytics tool) before enabling it. A compromised low-value dependency has been the root cause of several major fintech breaches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Logging, monitoring, and incident response
&lt;/h2&gt;

&lt;p&gt;Security is not just prevention - you need visibility to detect issues you didn't prevent. Log authentication events, permission failures, and unusual access patterns (e.g., rapid sequential access to many different accounts) and alert on them. Have a documented incident response plan before you need one, including who gets notified and how customer communication is handled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build security in from day one
&lt;/h2&gt;

&lt;p&gt;Retrofitting security into a fintech application after launch is far more expensive than designing it in from the start. Every project we scope includes a security review checklist during the design phase, not just before launch - it's much cheaper to fix an access control model on paper than to migrate a live production schema.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/full-stack-development" rel="noopener noreferrer"&gt;Full stack fintech development&lt;/a&gt;· &lt;a href="https://tjalam.com/trading-platform-development" rel="noopener noreferrer"&gt;Custom trading platform development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The OWASP Top 10 mapped to fintech features
&lt;/h2&gt;

&lt;p&gt;The OWASP Top 10 lists risk categories, not features. The table maps each category to where it usually appears in a financial product and the first thing to check.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Risk category&lt;/th&gt;
&lt;th&gt;Where it shows up&lt;/th&gt;
&lt;th&gt;First check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Broken access control&lt;/td&gt;
&lt;td&gt;Account, transaction and statement endpoints that take an ID&lt;/td&gt;
&lt;td&gt;Request another user's record with your own session; it must fail&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cryptographic failures&lt;/td&gt;
&lt;td&gt;Stored bank details, KYC files, API keys&lt;/td&gt;
&lt;td&gt;Encryption at rest, TLS on every hop, keys in a secrets manager&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Injection&lt;/td&gt;
&lt;td&gt;Search, reports and admin filters&lt;/td&gt;
&lt;td&gt;Parameterised queries only; no SQL built from strings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insecure design&lt;/td&gt;
&lt;td&gt;Withdrawals, transfers, promotional credits&lt;/td&gt;
&lt;td&gt;Limits, idempotency keys and a second approval on large amounts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security misconfiguration&lt;/td&gt;
&lt;td&gt;Cloud storage, admin panels, debug modes&lt;/td&gt;
&lt;td&gt;No public buckets; admin behind single sign-on and an IP allowlist&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vulnerable and outdated components&lt;/td&gt;
&lt;td&gt;npm and pip packages, vendor SDKs&lt;/td&gt;
&lt;td&gt;Lockfiles, automated scanning, a review before adding a package&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Authentication failures&lt;/td&gt;
&lt;td&gt;Login, password reset, API tokens&lt;/td&gt;
&lt;td&gt;MFA, rate limits on login and reset, short-lived tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Software and data integrity failures&lt;/td&gt;
&lt;td&gt;Webhooks from payment providers and brokers&lt;/td&gt;
&lt;td&gt;Verify signatures; reject unsigned or replayed events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logging and monitoring failures&lt;/td&gt;
&lt;td&gt;Admin actions, failed logins, payouts&lt;/td&gt;
&lt;td&gt;Alerts on spikes; logs that application admins cannot edit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server-side request forgery&lt;/td&gt;
&lt;td&gt;URL fetchers, PDF renderers, outgoing webhooks&lt;/td&gt;
&lt;td&gt;Allowlist outbound hosts; block internal addresses&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Business logic: the bugs scanners miss
&lt;/h2&gt;

&lt;p&gt;Automated scanners find missing headers and outdated packages. They do not find a withdrawal that can be made twice. The most expensive fintech bugs live in business logic, and they have to be designed out and tested by hand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Race conditions on balances: two withdrawals sent at the same moment both pass the balance check. Use a database transaction with a row lock, or a single conditional update that fails when the balance is too low&lt;/li&gt;
&lt;li&gt;Negative and zero amounts accepted where only positive ones make sense&lt;/li&gt;
&lt;li&gt;Rounding on currency conversion that can be repeated for a small profit each time&lt;/li&gt;
&lt;li&gt;Promotions or referral credits that can be claimed more than once&lt;/li&gt;
&lt;li&gt;A price shown in a quote that changes before execution without the user confirming again&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Webhooks and money movement
&lt;/h2&gt;

&lt;p&gt;Payment providers and brokers report events by calling your server. Treat every call as untrusted until proven otherwise. Verify the signature with the provider's secret, reject events with old timestamps, and store each event ID so a replayed or duplicated event is processed only once.&lt;/p&gt;

&lt;p&gt;Never credit an account because of a redirect URL or a value sent from the browser. Confirm the payment with the provider's API, using the amount and currency the provider reports, before you change a balance.&lt;/p&gt;

&lt;h2&gt;
  
  
  API keys and trading credentials
&lt;/h2&gt;

&lt;p&gt;Trading products often hold users' broker or exchange API keys. Those keys can place orders, so they deserve the same care as passwords and more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask users for trade-only keys and refuse keys with withdrawal permission&lt;/li&gt;
&lt;li&gt;Encourage IP allowlisting on the exchange side, limited to your servers' addresses&lt;/li&gt;
&lt;li&gt;Encrypt each key with a key management service; never store keys in plain text or logs&lt;/li&gt;
&lt;li&gt;Never send a stored key back to the browser, even masked in full&lt;/li&gt;
&lt;li&gt;Let users revoke and replace keys in one step, and rotate your own keys on a schedule&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/broker-api-integration" rel="noopener noreferrer"&gt;Broker API integration&lt;/a&gt;· &lt;a href="https://tjalam.com/crypto-trading-bot-development" rel="noopener noreferrer"&gt;Crypto trading bot development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A pre-launch security checklist
&lt;/h2&gt;

&lt;p&gt;Run through this before the first real user, and again before every major release:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every endpoint that takes an ID checks ownership on the server&lt;/li&gt;
&lt;li&gt;MFA is on for users and required for every admin&lt;/li&gt;
&lt;li&gt;Secrets live in a secrets manager, not in the repository or environment files on laptops&lt;/li&gt;
&lt;li&gt;Dependency scanning runs in CI and blocks known critical issues&lt;/li&gt;
&lt;li&gt;Webhook signatures are verified and event IDs are de-duplicated&lt;/li&gt;
&lt;li&gt;Balance changes happen inside transactions, and amounts are never floating point&lt;/li&gt;
&lt;li&gt;Logs contain no card numbers, passwords, tokens or full account numbers&lt;/li&gt;
&lt;li&gt;Backups are encrypted and a restore has actually been tested&lt;/li&gt;
&lt;li&gt;An outside penetration test is booked before institutional customers or a large launch&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;I'm TJ Alam. I build custom trading platforms, bots and broker integrations at &lt;a href="https://tjalam.com" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;. The &lt;a href="https://tjalam.com/blog/securing-fintech-applications-owasp" rel="noopener noreferrer"&gt;full version of this guide&lt;/a&gt; stays up to date there.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>fintech</category>
      <category>owasp</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A Practical Guide to Real-Time Market Data with WebSockets</title>
      <dc:creator>TJ Alam</dc:creator>
      <pubDate>Sun, 06 Dec 2026 04:30:54 +0000</pubDate>
      <link>https://dev.to/tjalam/a-practical-guide-to-real-time-market-data-with-websockets-a7g</link>
      <guid>https://dev.to/tjalam/a-practical-guide-to-real-time-market-data-with-websockets-a7g</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://tjalam.com/blog/real-time-market-data-websockets-guide" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive implementation and why it fails
&lt;/h2&gt;

&lt;p&gt;The first version of most WebSocket integrations looks the same: open a connection, subscribe to a symbol, update the UI on every message. It works perfectly in a demo and falls over within days in production - usually when the connection silently drops (no error thrown, just no more messages) and nobody notices until a user reports stale prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Heartbeats and dead-connection detection
&lt;/h2&gt;

&lt;p&gt;Most exchange WebSocket APIs support (or require) a ping/pong heartbeat. If you don't implement one, you need your own: track the timestamp of the last received message, and if it exceeds an expected threshold (e.g., 1.5x the expected update interval), assume the connection is dead and force a reconnect - even if the socket object itself hasn't fired a close event. TCP connections can go stale without any client-side signal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reconnection strategy
&lt;/h2&gt;

&lt;p&gt;Use exponential backoff with jitter for reconnect attempts to avoid hammering the exchange's API and getting rate-limited or IP-banned during an outage. On reconnect, always re-fetch a full snapshot via REST before resuming to trust incremental WebSocket updates - otherwise a missed message during the disconnect window leaves your local state permanently wrong.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exponential backoff: 1s, 2s, 4s, 8s... capped at a reasonable max (e.g., 30s)&lt;/li&gt;
&lt;li&gt;Add random jitter so many clients reconnecting after a shared outage don't all hit the server simultaneously&lt;/li&gt;
&lt;li&gt;Always resync via REST snapshot before trusting further deltas&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Handling multiple exchanges with different message formats
&lt;/h2&gt;

&lt;p&gt;If you're aggregating data from Binance, Kraken, Coinbase, or others, normalize every incoming message into one internal shape immediately at the connection layer. Don't let exchange-specific field names or units (satoshis vs. BTC, different timestamp formats) leak into your application logic - it becomes unmaintainable within a few integrations.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/crypto-trading-bot-development" rel="noopener noreferrer"&gt;Crypto trading bot development&lt;/a&gt;· &lt;a href="https://tjalam.com/broker-api-integration" rel="noopener noreferrer"&gt;Broker and exchange API integration&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Client-side performance at scale
&lt;/h2&gt;

&lt;p&gt;For UIs subscribing to many symbols (a full order book or a large watchlist), batch incoming updates and flush them to the render layer on a fixed interval (e.g., every 100–250ms) rather than re-rendering on every single message. This single change often has more impact on perceived performance than any component-level optimization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring is part of the architecture
&lt;/h2&gt;

&lt;p&gt;Track connection uptime, reconnect frequency, and message latency per feed as first-class metrics, not an afterthought. A feed that reconnects constantly is telling you something - usually a rate limit issue or a bug in your subscription logic - long before users start complaining about stale prices.&lt;/p&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/trading-platform-development" rel="noopener noreferrer"&gt;Custom trading platform development&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Snapshots, sequence numbers and gap detection
&lt;/h2&gt;

&lt;p&gt;Order book feeds send changes, not the full book. To build a correct local book you need a starting snapshot and every change after it, in order. Most exchanges number their updates so you can check that nothing was missed; Binance's documentation for its depth stream describes this exact procedure.&lt;/p&gt;

&lt;p&gt;The pattern is the same everywhere. Open the WebSocket first and buffer updates. Fetch a REST snapshot, which carries its own update ID. Drop buffered updates older than the snapshot, apply the rest, and from then on check that each update's number follows the last one. If a number is skipped, the book is wrong: discard it and start again from a new snapshot. Never try to patch a gap.&lt;/p&gt;

&lt;p&gt;Some exchanges, such as Kraken and OKX, also send a checksum of the top of the book. Compare it with your own after each update; a mismatch is the fastest way to catch a bug in your merge logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  A reconnecting feed client in TypeScript
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;The client below is on GitHub as &lt;a href="https://github.com/TJalam-com/ws-feed-client" rel="noopener noreferrer"&gt;ws-feed-client&lt;/a&gt; (MIT), with tests.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The sketch below puts the earlier sections together: a watchdog for silent drops, reconnects with exponential backoff and jitter, and a resync after every new connection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;FeedHandlers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;onMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;resync&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// load a REST snapshot, then apply buffered deltas&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;connectFeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FeedHandlers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;STALE_MS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// about 1.5x the feed's slowest normal gap&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;WebSocket&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;lastMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;stopped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;reconnect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1_000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// backoff with jitter&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stopped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;lastMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onopen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;lastMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nf"&gt;reconnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// A dead TCP connection can stay "open" with no close event: watch the clock.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;watchdog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;lastMessage&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;STALE_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dead&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;dead&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;dead&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nf"&gt;reconnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;stopped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;watchdog&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;onclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  One exchange connection, many users
&lt;/h2&gt;

&lt;p&gt;Do not open an exchange connection from every user's browser. Exchanges cap connections and subscriptions per IP and per key, and browsers cannot hold API keys safely. Run one connection per stream on your server, normalise the messages there, and publish to your own clients over your own WebSocket or server-sent events.&lt;/p&gt;

&lt;p&gt;This also lets you keep the latest snapshot in memory, so a user who opens the page gets a full book at once instead of waiting for the next update. And it gives you one place to measure latency and gaps, instead of thousands of browsers you cannot see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing a feed before it goes live
&lt;/h2&gt;

&lt;p&gt;Feeds fail in production in ways a quick local test never shows. Test these on purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replay recorded messages from a real session and check the final book matches a snapshot taken at the same moment&lt;/li&gt;
&lt;li&gt;Cut the network in the middle of a busy period and confirm the client resyncs instead of carrying on with a stale book&lt;/li&gt;
&lt;li&gt;Inject a skipped sequence number and a duplicate message, and check both are caught&lt;/li&gt;
&lt;li&gt;Run a soak test for at least a day with metrics on reconnects, gaps and latency&lt;/li&gt;
&lt;li&gt;Load the client UI with your largest realistic watchlist and check it still renders smoothly on a mid-range laptop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Related: &lt;a href="https://tjalam.com/broker-api-integration" rel="noopener noreferrer"&gt;Broker and exchange API integration&lt;/a&gt;· &lt;a href="https://tjalam.com/blog/how-to-build-a-trading-platform" rel="noopener noreferrer"&gt;How to build a trading platform&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I'm TJ Alam. I build custom trading platforms, bots and broker integrations at &lt;a href="https://tjalam.com" rel="noopener noreferrer"&gt;tjalam.com&lt;/a&gt;. The &lt;a href="https://tjalam.com/blog/real-time-market-data-websockets-guide" rel="noopener noreferrer"&gt;full version of this guide&lt;/a&gt; stays up to date there.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>websockets</category>
      <category>trading</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
