Skip to content

Commit c51d72e

Browse files
committed
fix(mobile): normalize HK stock strategy identities
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
1 parent f769c6e commit c51d72e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/utils/strategyInstrument.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export function parseStrategyInstrumentIdentity(value, defaults = {}) {
7272
instrument: parsed.symbol ? `Crypto:${parsed.symbol}@${qualifier}` : ''
7373
}
7474
}
75-
const symbol = String(body || '').split('@', 1)[0].trim().toUpperCase()
75+
let symbol = String(body || '').split('@', 1)[0].trim().toUpperCase()
76+
if (market === 'HKStock') {
77+
const match = symbol.match(/^(?:HK\.?)?(\d{1,5})(?:\.HK|\.XHKG)?$/)
78+
if (match) symbol = `${match[1].padStart(5, '0')}.HK`
79+
}
7680
return { market, symbol, exchangeId: '', marketType: 'spot', instrument: symbol ? `${market}:${symbol}` : '' }
7781
}
7882

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import test from 'node:test'
2+
import assert from 'node:assert/strict'
3+
import { parseStrategyInstrumentIdentity, formatStrategyInstrumentIdentity } from '../../src/utils/strategyInstrument.js'
4+
5+
test('HK stock aliases use one strategy identity with an explicit market', () => {
6+
for (const symbol of ['700', '00700', '700.HK', 'HK00700', 'HK.00700', '00700.XHKG', '00700.HK']) {
7+
const parsed = parseStrategyInstrumentIdentity(symbol, { market: 'HKStock' })
8+
assert.equal(parsed.instrument, 'HKStock:00700.HK')
9+
assert.equal(parsed.symbol, '00700.HK')
10+
assert.equal(formatStrategyInstrumentIdentity({ market: 'HKStock', symbol }), 'HKStock:00700.HK')
11+
assert.equal(parseStrategyInstrumentIdentity('HKStock:' + symbol).instrument, 'HKStock:00700.HK')
12+
}
13+
})
14+
15+
test('HK normalization preserves US share classes, futures and exchange products', () => {
16+
for (const instrument of ['USStock:BRK.B', 'USStock:BRK-B', 'USStock:HK07709', 'USStock:700',
17+
'Futures:HSIZ26', 'CNStock:600519.SH', 'Crypto:00700/HKD@gate:spot',
18+
'Crypto:HK0700/USDT@binance:swap']) {
19+
assert.equal(parseStrategyInstrumentIdentity(instrument).instrument, instrument)
20+
}
21+
})

0 commit comments

Comments
 (0)