𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁𝗶𝗮𝘁𝗶𝗻𝗴 𝗧𝗿𝗮𝗱𝗲𝘀 𝗶𝗻 𝗛𝗼𝗻𝗴 𝗞𝗼𝗻𝗴 𝗪𝗲𝗯𝗦𝗼𝗰𝗸𝗲𝘁 𝗙𝗲𝗲𝗱𝘀

Real-time market data moves fast. When you stream Hong Kong equity trades, you see different types of prints. Not all trades represent the same thing. Some are investor orders. Others are system auto-matches or odd-lot transactions.

You need to classify these trades quickly.

The Problem

Standard data fields often fail to help. The trade type field is often unreliable. To fix this, use these three rules:

  • Volume check: Most Hong Kong stocks trade in lots of 100 shares. Any trade under 100 shares is an odd lot.
  • Time clustering: Auto-matched trades happen in fast bursts. You see many fills within milliseconds. Odd lots do not follow this pattern.
  • Counterparty check: Look at the buyer and seller. If both are system accounts like SYS, it is an auto-match.

Implementation

You can code this logic into your data stream.

from websocket import create_connection
import json

API_TOKEN = 'your_api_token'
ws_url = f"wss://ws.alltick.co/stock?token={API_TOKEN}"
ws = create_connection(ws_url)

subscribe_msg = {
    "action": "subscribe",
    "symbol": "00700.HK",
    "type": "transaction"
}
ws.send(json.dumps(subscribe_msg))

def check_auto_match(tick):
    return tick.get('buyer') == 'SYS' and tick.get('seller') == 'SYS'

while True:
    data = ws.recv()
    tick = json.loads(data)
    volume = tick.get('volume', 0)

    if volume < 100:
        tick['tag'] = 'odd_lot'
    elif check_auto_match(tick):
        tick['tag'] = 'auto_match'
    else:
        tick['tag'] = 'normal'

    print(tick['time'], tick['price'], tick['volume'], tick['tag'])

Sorting these trades helps you see the true market movement.

Source: https://dev.to/emily19980210/differentiating-auto-matched-and-odd-lot-trades-in-hong-kong-stock-websocket-feeds-3bgg

Optional learning community: https://t.me/GyaanSetuAi