Fix CTP exchange routing for non-SHFE contracts and duplicate trade closes.
Resolve CZCE/DCE symbols to the correct exchange for orders, dedupe stop-loss closes and trade logs, and rely on CTP sync for authoritative records. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+28
-10
@@ -140,6 +140,17 @@ def _find_product_by_letters(letters: str) -> Optional[dict]:
|
||||
return None
|
||||
|
||||
|
||||
def _product_codes(product: dict, ths_code: str, market_code: str, sina_code: str) -> dict:
|
||||
return {
|
||||
"ths_code": ths_code,
|
||||
"market_code": market_code,
|
||||
"sina_code": sina_code,
|
||||
"ex": product["ex"],
|
||||
"name": product["name"],
|
||||
"exchange": product["exchange"],
|
||||
}
|
||||
|
||||
|
||||
def ths_to_codes(ths_code: str) -> Optional[dict]:
|
||||
"""同花顺合约代码 -> ths_full + sina 回退代码。"""
|
||||
code = ths_code.strip()
|
||||
@@ -155,11 +166,13 @@ def ths_to_codes(ths_code: str) -> Optional[dict]:
|
||||
return None
|
||||
product = _find_product_by_letters(letters)
|
||||
if product:
|
||||
return {
|
||||
"ths_code": build_ths_code(product, year, month),
|
||||
"market_code": build_ths_full_code(product, year, month),
|
||||
"sina_code": build_sina_code(product, year, month),
|
||||
}
|
||||
ths = build_ths_code(product, year, month)
|
||||
return _product_codes(
|
||||
product,
|
||||
ths,
|
||||
build_ths_full_code(product, year, month),
|
||||
build_sina_code(product, year, month),
|
||||
)
|
||||
letters_up = letters.upper()
|
||||
if letters_up in ("IF", "IH", "IC", "IM", "T", "TF", "TS"):
|
||||
ths = f"{letters_up}{digits}"
|
||||
@@ -167,6 +180,9 @@ def ths_to_codes(ths_code: str) -> Optional[dict]:
|
||||
"ths_code": ths,
|
||||
"market_code": f"{ths}.CFFEX",
|
||||
"sina_code": f"CFF_RE_{letters_up}{digits}",
|
||||
"ex": "CFFEX",
|
||||
"name": letters_up,
|
||||
"exchange": "中金所",
|
||||
}
|
||||
|
||||
m3 = re.match(r"^([A-Za-z]+)(\d{3})$", code)
|
||||
@@ -183,11 +199,13 @@ def ths_to_codes(ths_code: str) -> Optional[dict]:
|
||||
candidate += 10
|
||||
product = _find_product_by_letters(letters)
|
||||
if product:
|
||||
return {
|
||||
"ths_code": build_ths_code(product, candidate, month),
|
||||
"market_code": build_ths_full_code(product, candidate, month),
|
||||
"sina_code": build_sina_code(product, candidate, month),
|
||||
}
|
||||
ths = build_ths_code(product, candidate, month)
|
||||
return _product_codes(
|
||||
product,
|
||||
ths,
|
||||
build_ths_full_code(product, candidate, month),
|
||||
build_sina_code(product, candidate, month),
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user