jerryliu369-tqsdk-trading
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md382 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
<!-- Imported from: https://github.com/shinnytech/tqsdk-python Source Path: doc/ai_editor/skills/tqsdk-trading-and-data/SKILL.md Curated for awesome-quant-skills -->
name: tqsdk-trading-and-data description: "Explain, implement, or debug TqSdk Python workflows for wait_update or is_changing update loops, market data retrieval, historical download, account type selection, funds or positions or orders or trades, field meanings, order placement or cancellation, target-position tools, TqScenario margin trials, real-account margin-rate lookup, margin or risk-ratio what-if analysis, simulation, backtest, multi-strategy, and common TqSdk errors. Use when a request mentions TqSdk, TqApi, TqAuth, TqAccount, TqKq, TqKqStock, TqSim, TqSimStock, TqMultiAccount, TqTradingUnit, TqBacktest, TqScenario, TargetPosTask, TargetPosScheduler, Twap, DataDownloader, margin rate, margin calculation, risk ratio, scenario trial, market data, K-line, tick, historical data, positions, trades, orders, account data, order placement, cancellation, position adjustment, field meanings, wait_update, debugging, \u884c\u60c5, K\u7ebf, \u5386\u53f2\u6570\u636e, \u4fdd\u8bc1\u91d1\u7387, \u4fdd\u8bc1\u91d1, \u98ce\u9669\u5ea6, \u573a\u666f\u8bd5\u7b97, \u6301\u4ed3, \u6210\u4ea4, \u59d4\u6258, \u8d26\u6237, \u4e0b\u5355, \u64a4\u5355, \u8c03\u4ed3, \u591a\u7b56\u7565, \u5b57\u6bb5\u542b\u4e49, or \u62a5\u9519."
TqSdk Trading and Data
Use this skill to answer TqSdk questions with the repository's real APIs, docs, and examples. Prefer minimal runnable snippets, keep futures and stock behavior separate, and explain the update loop explicitly whenever the user's issue depends on wait_update().
Route The Request First
Read only the references needed for the user's question.
- Read references/wait-update-and-update-loop.md for
wait_update,is_changing,deadline, async update notifications, Jupyter caveats, or backtest progression questions. - Read references/market-data.md for
get_quote,get_kline_serial,get_tick_serial, contract discovery, symbol metadata, andDataDownloader. - Read references/account-type-matrix.md for
TqAccount,TqKq,TqKqStock,TqSim,TqSimStock,TqTradingUnit, OTG account classes, andTqMultiAccount. - Read references/accounts-and-trading.md for account, position, order, and trade getters plus multi-account getter patterns.
- Read references/scenario-and-margin.md for
TqScenario, real-account margin-rate lookup, margin occupancy calculation, risk-ratio what-if analysis, and limited built-in margin discount rules. - Read references/order-functions-and-position-tools.md for
insert_order,cancel_order,TargetPosTask,support_open_min_volume,TargetPosScheduler,Twap, and advanced execution helpers. - Read references/object-fields.md when the user asks what fields mean on
Quote, K-line or tick rows,Account,Position,Order,Trade, or their stock variants. - Read references/simulation-and-backtest.md for local sim, Quick sim, stock sim, backtest, and cross-account backtest limits.
- Read references/error-faq.md when the user asks about common TqSdk failures, confusing behavior, or exception messages.
- Read references/example-map.md when you want a repository-backed example or doc page to imitate.
Before Writing Code
- Identify the task mode first: market data only, local sim, Quick sim, real account, stock trading, futures trading, backtest, or margin trial.
- If an example needs a current futures or option contract, verify it with
query_quotes(..., expired=False),query_options(..., expired=False), or a main-contract symbol before using it. - Prefer main-contract symbols such as
KQ.m@SHFE.rbfor market-data and historical-download examples when the user does not need a tradable delivery month. - Use a concrete non-expired delivery-month contract for order, position,
TargetPosTask, and margin examples. - Do not expose real account names, passwords, tokens, or customer credentials. Use placeholders or environment variables.
- When writing or changing code, run the smallest practical verification, such as import checks, syntax checks, a short quote subscription, or a narrow backtest.
Core Rules
- Treat
get_*results as live references, not snapshots. Explain that they refresh duringwait_update(). - Explain
wait_update()whenever the user is confused by missing data, stale fields, orders not leaving the client, orTargetPosTasknot acting. - Distinguish futures and stock workflows:
- Futures accounts and objects use
Account,Position,Order,Trade. - Stock accounts and objects use
SecurityAccount,SecurityPosition,SecurityOrder,SecurityTrade. - Stock trading does not use
offset, andTargetPosTaskis not for stock trading.
- Futures accounts and objects use
- Choose account type before writing code. Do not default to
TqKqorTqAccountunless the user really needs that account mode. - In multi-account mode, pass
account=for getters and trading calls, or use the account object's ownget_account,get_position,get_order, andget_trade. - For current market examples, avoid expired contracts. Prefer contract discovery APIs or main-contract symbols.
- When the user asks for field meanings, explain the smallest relevant field set first and say whether the object is futures or stock.
- When the user asks for long historical ranges, prefer
DataDownloaderover pretendingget_kline_serialis an unlimited history API. - When the user asks for advanced execution, prefer public helpers first:
TargetPosTaskfor target net position.TargetPosTask(..., support_open_min_volume=True)only for contracts with exchange minimum opening size rules when approximate completion is acceptable.TargetPosSchedulerplustwap_tableorvwap_tablefromtqsdk.algorithmfor scheduled execution.TargetPosScheduler(..., support_open_min_volume=True)when the scheduled execution targets a contract with exchange minimum opening size rules.- Direct
tqsdk.algorithm.Twap(..., support_open_min_volume=True)only when the user asks for the older/direct TWAP helper; note that it is not for backtest. - Mention
InsertOrderTaskandInsertOrderUntilAllTradedTaskas internal or advanced helpers, not the default answer.
- Use
TqScenariofor synchronous what-if margin and risk trials, not for live order placement. It is futures-only, single-account, and updates the trial snapshot immediately after each call. - Explain the margin-rate source in every
TqScenarioanswer:
account=NoneorTqSim()usesQuotemargin data.TqAccount(...)orTqKq()queries account-specific rates synchronously and may fall back toQuotemargin if lookup fails.
- Treat margin discounts conservatively. Reuse one
TqScenarioobject for step-by-step trial actions, and do not promise broker-specific preferential rules beyond the limited built-in rules modeled by TqSdk. - Preserve exchange-specific close semantics in
TqScenario. For SHFE or INE futures, keepCLOSEversusCLOSETODAYconsistent with the imported position snapshot.
Answering Style
- Prefer imports from
tqsdk.__init__for top-level APIs. When an API is documented under a submodule, use that official submodule path such astqsdk.toolsortqsdk.algorithm. - Prefer short, correct code blocks over broad pseudo-code.
- Name the exact API the user should call next.
- If behavior differs in live trading, Quick sim, local sim, stock sim, or backtest, say so explicitly.
- If the answer depends on a common pitfall, state the pitfall directly instead of burying it in examples.
- If the answer uses
TqScenario, say what snapshot goes intopositions, what balance goes intoinit_balance, and whether the result comes from quote margin or account-specific margin rates.
04 同仓库更多 Skills
troves
Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.
trade
Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".
staking
Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.
send
Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".
portfolio
View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".
multi-swap
Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.