Initial commit
Made-with: Cursor
This commit is contained in:
65
srde/miniprogram/pages/create/create.ts
Normal file
65
srde/miniprogram/pages/create/create.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
Page({
|
||||
data: {
|
||||
step: 1,
|
||||
logic: '',
|
||||
symbol: '',
|
||||
direction: 'long' as 'long' | 'short',
|
||||
entry_price: '',
|
||||
stop_loss: '',
|
||||
take_profit: '',
|
||||
upPct: 0,
|
||||
downPct: 0,
|
||||
odds: '',
|
||||
position_size: '',
|
||||
},
|
||||
onLogicInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ logic: (e.detail.value as string).trim() });
|
||||
},
|
||||
onSymbolInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ symbol: (e.detail.value as string).trim() });
|
||||
},
|
||||
setDir(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ direction: e.currentTarget.dataset.dir as 'long' | 'short' });
|
||||
},
|
||||
onEntryInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ entry_price: e.detail.value as string }, () => this.calc());
|
||||
},
|
||||
onStopInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ stop_loss: e.detail.value as string }, () => this.calc());
|
||||
},
|
||||
onTpInput(e: WechatMiniprogram.CustomEvent) {
|
||||
this.setData({ take_profit: e.detail.value as string }, () => this.calc());
|
||||
},
|
||||
calc() {
|
||||
const { entry_price, stop_loss, take_profit, direction } = this.data;
|
||||
const e = parseFloat(entry_price);
|
||||
const s = parseFloat(stop_loss);
|
||||
const t = parseFloat(take_profit);
|
||||
if (!e || !s || !t) return;
|
||||
const upPct = direction === 'long' ? ((t - e) / e * 100) : ((e - t) / e * 100);
|
||||
const downPct = direction === 'long' ? ((e - s) / e * 100) : ((s - e) / e * 100);
|
||||
const risk = direction === 'long' ? e - s : s - e;
|
||||
const reward = direction === 'long' ? t - e : e - t;
|
||||
const odds = risk > 0 && reward > 0 ? (reward / risk).toFixed(2) : '';
|
||||
this.setData({ upPct: upPct.toFixed(1), downPct: downPct.toFixed(1), odds });
|
||||
},
|
||||
nextStep() {
|
||||
const { step, logic } = this.data;
|
||||
if (step === 1 && logic.length < 30) return;
|
||||
if (step === 2) {
|
||||
this.setData({ position_size: '0.5', odds: this.data.odds || '-' });
|
||||
}
|
||||
this.setData({ step: step + 1 });
|
||||
},
|
||||
prevStep() {
|
||||
this.setData({ step: this.data.step - 1 });
|
||||
},
|
||||
onConfirm() {
|
||||
wx.showLoading({ title: '提交中' });
|
||||
setTimeout(() => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '已创建' });
|
||||
wx.navigateBack();
|
||||
}, 800);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user