@vibek/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -0
- package/README.md +210 -0
- package/config.example.toml +58 -0
- package/dist/core/export-html/template.css +1066 -0
- package/dist/core/export-html/template.html +55 -0
- package/index.js +2633 -0
- package/package.json +27 -0
- package/strategy-sdk.js +2 -0
- package/vibek-package.json +5 -0
- package/webui/client.js +41 -0
- package/webui/index.html +16 -0
- package/webui/styles.css +651 -0
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibek/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vibek CTP quantitative trading CLI and WebUI",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"vibek": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org/"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"bun": ">=1.4.0"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"strategy-sdk.js",
|
|
20
|
+
"webui",
|
|
21
|
+
"dist",
|
|
22
|
+
"config.example.toml",
|
|
23
|
+
".env.example",
|
|
24
|
+
"vibek-package.json",
|
|
25
|
+
"README.md"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/strategy-sdk.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function u(t){return t.status==="submitting"||t.status==="notTraded"||t.status==="partTraded"}var m=Symbol.for("vibek.strategy.cta-template-runtime.v1");class s{static author="";static parameters=[];static variables=[];static stateVersion=1;#a="";#o="";#l="paper";#i=!1;#e=!1;#u=0;#s=null;#m=!1;#d=Object.freeze({bindContext:(t)=>this.#h(t),restoreVariables:(t)=>this.#p(t),setRuntimeState:(t)=>{if(t.inited!==void 0)this.#i=t.inited;if(t.trading!==void 0)this.#e=t.trading;if(t.pos!==void 0)this.#u=t.pos},getStateVariables:()=>this.#g()});get strategyName(){return this.#a}get vtSymbol(){return this.#o}get mode(){return this.#l}get inited(){return this.#i}get trading(){return this.#e}get pos(){return this.#u}onStart(){}onStop(){}onTick(t){}onBar(t){}onTrade(t){}onOrder(t){}migrateState(t,e){throw Error(`\u7B56\u7565\u72B6\u6001\u7248\u672C ${t} \u65E0\u6CD5\u8FC1\u79FB\u5230 ${this.#n().stateVersion??1}`)}buy(t,e){return this.#r("long","open",t,e)}sell(t,e){return this.#r("short","close",t,e)}short(t,e){return this.#r("short","open",t,e)}cover(t,e){return this.#r("long","close",t,e)}cancelOrder(t){if(this.#e)this.#t().cancelOrder(this,t)}cancelAll(){if(this.#e)this.#t().cancelAll(this)}loadBar(t,e=(r)=>this.onBar(r)){this.#t().loadBar(this,t,e)}writeLog(t){this.#t().writeLog(this,t)}sendNotification(t){if(this.#i)this.#t().sendNotification(this,t)}getPriceTick(){return this.#t().getPriceTick(this)}getSize(){return this.#t().getSize(this)}[m](){return this.#d}#r(t,e,r,a){if(!this.#e)return[];return this.#t().sendOrder(this,t,e,r,a)}#g(){let t={};for(let e of this.#n().variables??[])t[e]=this.#b(e);return t}#h(t){if(this.#m)throw Error("\u7B56\u7565\u5B9E\u4F8B\u5DF2\u7ECF\u7ED1\u5B9A\u8FD0\u884C\u4E0A\u4E0B\u6587");this.#m=!0,this.#s=t.ctaEngine,this.#a=t.strategyName,this.#o=t.vtSymbol,this.#l=t.mode,this.#f(t.setting)}#p(t){let e=new Set(this.#n().variables??[]);for(let[r,a]of Object.entries(t))if(e.has(r))this.#c(r,a)}#f(t){let e=new Set(this.#n().parameters??[]);for(let r of Object.keys(t))if(!e.has(r))throw Error(`\u7B56\u7565 ${this.#a} \u4E0D\u652F\u6301\u53C2\u6570 "${r}"`);for(let r of e)if(Object.hasOwn(t,r))this.#c(r,t[r])}#t(){if(!this.#s)throw Error("\u7B56\u7565\u5C1A\u672A\u7ED1\u5B9A CtaEngine");return this.#s}#n(){return this.constructor}#b(t){return this[t]}#c(t,e){this[t]=e}}function c(t){return t}function i(t){let e=/^(\d+)(min|h|d)$/.exec(t);if(!e)throw Error(`\u4E0D\u652F\u6301\u7684 K \u7EBF\u5468\u671F: ${t}`);let r=Number(e[1]);if(!Number.isInteger(r)||r<=0)throw Error(`\u4E0D\u652F\u6301\u7684 K \u7EBF\u5468\u671F: ${t}`);if(e[2]==="min")return r*60;if(e[2]==="h")return r*3600;return r*86400}function o(t,e){return Math.floor(t/e)*e}var d=new Set(["1min","5min","15min"]);class l{timeframe;seconds;current=null;constructor(t){this.timeframe=t;if(!d.has(t))throw Error(`\u5468\u671F "${t}" \u4E0D\u53D7\u652F\u6301\uFF1B\u4EC5\u652F\u6301 1min\u30015min\u300115min`);this.seconds=i(t)}pushBar(t){let e=this.pushBars(t);if(e.length>1)throw Error("\u5355\u6839 1min bar \u540C\u65F6\u95ED\u5408\u4E86\u591A\u4E2A\u7A97\u53E3\uFF1B\u8BF7\u4F7F\u7528 pushBars() \u4FDD\u7559\u5168\u90E8\u4FE1\u53F7");return e[0]??null}pushBars(t){if(t.timeframe!=="1min")throw Error(`BarGenerator \u53EA\u63A5\u53D7\u95ED\u5408 1min bar\uFF0C\u6536\u5230 ${t.timeframe}`);if(this.seconds===60)return[t];let e=[],r=o(t.barTime,this.seconds);if(this.current&&this.current.barTime!==r){let n=this.finish();if(n)e.push(n)}if(!this.current)this.start(t,r);else this.merge(t);if(t.barTime+60>=r+this.seconds||t.boundaryReason){let n=this.finish(t.boundaryReason);if(n)e.push(n)}return e}flush(t){return this.finish(t)}start(t,e){this.current={code:t.code,timeframe:this.timeframe,barTime:e,open:t.open,high:t.high,low:t.low,close:t.close,volume:t.volume}}merge(t){let e=this.current;e.high=Math.max(e.high,t.high),e.low=Math.min(e.low,t.low),e.close=t.close,e.volume+=t.volume}finish(t){let e=this.current;if(!e)return null;return this.current=null,{...e,...t?{boundaryReason:t}:{}}}}export{l as BarGenerator,s as CtaTemplate,c as defineStrategy,u as isActiveOrder,i as parseTimeframe};
|