From a68c4a4b05e089d90aebff633eed9073ac641397 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 7 May 2024 15:02:54 -0400 Subject: [PATCH] diagonals working except for start/end times --- src/blockchain/wallet.js | 4 ++-- src/charts/shape.js | 11 ++++----- src/components/chart/DiagonalBuilder.vue | 29 ++++++++++-------------- src/components/chart/RungBuilder.vue | 20 +++++++++------- src/orderbuild.js | 22 +++++++++--------- 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 37f4be7..199d24e 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -378,8 +378,8 @@ function pendOrderAsTransaction(pend) { return null } } - console.log('placing order', pend.id) - const tx = await contract.placeDexorder(pend.order) // todo update status + console.log('placing order', pend.id, pend.order) + const tx = await contract.placeDexorder(pend.order) pend.tx = tx pend.state = PendingOrderState.Sent console.log(`order ${pend.id} sent transaction`, tx) diff --git a/src/charts/shape.js b/src/charts/shape.js index 85084db..6cd0d7f 100644 --- a/src/charts/shape.js +++ b/src/charts/shape.js @@ -30,8 +30,8 @@ export const ShapeType = { text anchored_text note anchored_note signpost double_curve arc icon emoji sticker arrow_up arrow_down arrow_left arrow_right price_label price_note arrow_marker flag vertical_line horizontal_line cross_line horizontal_ray trend_line info_line trend_angle arrow ray extended parallel_channel disjoint_angle flat_bottom anchored_vwap pitchfork schiff_pitchfork_modified schiff_pitchfork balloon comment inside_pitchfork pitchfan gannbox gannbox_square gannbox_fixed gannbox_fan fib_retracement fib_trend_ext fib_speed_resist_fan fib_timezone fib_trend_time fib_circles fib_spiral fib_speed_resist_arcs fib_channel xabcd_pattern cypher_pattern abcd_pattern callout triangle_pattern 3divers_pattern head_and_shoulders fib_wedge elliott_impulse_wave elliott_triangle_wave elliott_triple_combo elliott_correction elliott_double_combo cyclic_lines time_cycles sine_line long_position short_position forecast date_range price_range date_and_price_range bars_pattern ghost_feed projection rectangle rotated_rectangle circle ellipse triangle polyline path curve cursor dot arrow_cursor eraser measure zoom brush highlighter regression_trend fixed_range_volume_profile */ Segment: {name: 'Trend Line', code: 'trend_line'}, - Ray: {name: 'Ray', code: 'ray'}, - Line: {name: 'Extended Line', code: 'extended', drawingProp: 'linetoolextended'}, + Ray: {name: 'Ray', code: 'ray', drawingProp: 'linetoolray'}, + Line: {name: 'Extended Line', code: 'extended', drawingProp: 'linetoolray'}, HRay: {name: 'Horizontal Ray', code: 'horizontal_ray'}, HLine: {name: 'Horizontal Line', code: 'horizontal_line', drawingProp: 'linetoolhorzline'}, VLine: {name: 'Vertical Line', code: 'vertical_line', drawingProp: 'linetoolvertline'}, @@ -539,20 +539,20 @@ export class VLine extends Line { export class DLine extends Line { constructor(model, onModel=null, onDelete=null, props=null) { - super(ShapeType.Line, onModel, onDelete, props) + super(ShapeType.Ray, onModel, onDelete, props) // Model this.model.pointA = null // {time:..., price:...} this.model.pointB = null this.setModel(model) // call setModel at the end - console.log('initial shape model', {...model}) } drawingOverrides() { const result = super.drawingOverrides(); - result.linetoolextended = {extendLeft: false, extendRight: false} + result.extendLeft = false + result.extendRight = false return result } @@ -585,7 +585,6 @@ export class DLine extends Line { dirty = true } if (dirty) { - console.log('DLine points were dirty', this.tvPoints, points) super.onPoints(points); this.updateModel({pointA: points[0], pointB: points[1]}) } diff --git a/src/components/chart/DiagonalBuilder.vue b/src/components/chart/DiagonalBuilder.vue index 1ad4e7c..c5e99ce 100644 --- a/src/components/chart/DiagonalBuilder.vue +++ b/src/components/chart/DiagonalBuilder.vue @@ -19,7 +19,7 @@ label="Price" /> - {{ allocationTexts[weights.length-1] }} + {{ allocationTexts[weights.length-1] }} @@ -36,7 +36,7 @@   - Diagonal + — Interior Line — {{ allocationTexts[i] }} @@ -52,7 +52,7 @@ label="Price" /> - {{ allocationTexts[0] }} + {{ allocationTexts[0] }} @@ -109,18 +109,17 @@ builderDefaults(props.builder, { function buildTranches() { - throw Error('unimplemented') // todo const order = props.order const builder = props.builder const tranches = [] - console.log('buildTranches', builder, order, tranches) - const la = buildLine(_endpoints[0]) - const lb = buildLine(_endpoints[1]) + console.log('buildTranches', builder, order, _endpoints.value) + const la = _endpoints.value[0] // use the flatline format which is a vector of length 4, useful for vectorInterpolate() + const lb = _endpoints.value[1] const ws = weights.value for (let i = 0; i < ws.length; i++) { const w = ws[i] - const line = vectorInterpolate(la, lb, i/(ws.length-1)) + const line = ws.length === 1 ? la : vectorInterpolate(la, lb, i/(ws.length-1)) const t = newTranche({fraction: w * MAX_FRACTION}) const symbol = co.selectedSymbol console.log('symbol', symbol) @@ -137,7 +136,7 @@ function flattenLine(l) { function buildLine(f) { - console.log('buildLine', f) + // console.log('buildLine', f) return f === null ? null : [{time: f[0], price: f[1]}, {time: f[2], price: f[3]}] } @@ -243,17 +242,13 @@ const price2B = computed({ }) function update(a, b) { // a and b are lines of two points - console.log('update', a, b) if (!vectorEquals(props.builder.lineA, a) || !vectorEquals(props.builder.lineB, b)) { - console.log('update was dirty') _endpoints.value = [flattenLine(a), flattenLine(b)] const newBuilder = {...props.builder} newBuilder.lineA = a newBuilder.lineB = b emit('update:builder', newBuilder) } - else - console.log('update was not dirty') } @@ -290,14 +285,14 @@ function getModelValue(model) { if (!model.pointA || !model.pointB) return null const result = flattenLine([model.pointA, model.pointB]); - console.log('getModelValue', {...model}, result) + // console.log('getModelValue', {...model}, result) return result // this is the vector the RungBuilder will interpolate } function setModelValue(model, value) { const oldModel = {...model}; - console.log('setModelValue', oldModel, value) + // console.log('setModelValue', oldModel, value) const oldLine = !model.pointA || !model.pointB ? null : [model.pointA, model.pointB] const line = buildLine(value) if (dirtyLine(oldLine, line)) { @@ -310,7 +305,7 @@ function setModelValue(model, value) { model.pointB = line[1] } } - console.log('setModelValue end', oldModel, value, model) + // console.log('setModelValue end', oldModel, value, model) } @@ -318,7 +313,7 @@ function dirtyLine(a, b) { const result = a === b ? false : a === null && b !== null || a !== null && b === null || a[0].time !== b[0].time || a[0].price !== b[0].price || a[1].time !== b[1].time || a[1].price !== b[1].price - console.log('dirtyLine', result, a, b) + // console.log('dirtyLine', result, a, b) return result } diff --git a/src/components/chart/RungBuilder.vue b/src/components/chart/RungBuilder.vue index c94c9f1..536d1ec 100644 --- a/src/components/chart/RungBuilder.vue +++ b/src/components/chart/RungBuilder.vue @@ -87,7 +87,7 @@ watchEffect(()=>{ function setEndpoints(a, b) { - console.log('rb setting endpoints', devectorize(a), devectorize(b)) + // console.log('rb setting endpoints', devectorize(a), devectorize(b)) endpoints.value = [devectorize(a), devectorize(b)] } @@ -107,13 +107,13 @@ const rungs = computed({ r = Number(r) const prevR = Number(props.builder.rungs) props.builder.rungs = r - console.log('set rungs', prevR, r, a, b) + // console.log('set rungs', prevR, r, a, b) if ( r > 0 && vectorIsNull(b) ) { // convert single shape to a range if (props.mode===0) { const width = vectorize(props.stdWidth) const mid = vectorize(a) - console.log('stdWidth', width) + // console.log('stdWidth', width) const halfWidth = vectorDiv(width,2); a = vectorAdd(mid, vectorNeg(halfWidth) ) b = vectorAdd(mid, halfWidth) @@ -149,7 +149,6 @@ const values = computed(()=>{ let [a, b] = endpoints.value a = vectorize(a) b = vectorize(b) - console.log('computing values', a, b) const r = props.builder.rungs let result if ( !r || vectorIsNull(a) ) @@ -170,14 +169,20 @@ const values = computed(()=>{ } } props.setValues(result) - console.log('values', result) + // console.log('values', result) return result; }) const weights = computed(() => { // const skew = props.flip ? -props.builder.skew : props.builder.skew - const ws = linearWeights(props.builder.rungs, -props.builder.skew) + const most = 0.998 + let skew = -props.builder.skew + if (skew <= -1) + skew = -most + else if (skew >= 1) + skew = most + const ws = linearWeights(props.builder.rungs, skew) if (props.setWeights) props.setWeights(ws) return ws @@ -239,7 +244,7 @@ function translateOnModel(shape) { const prev = getModelValue(oldModel) const cur = vectorize(getModelValue(this.model)) const delta = vectorSub(cur, prev) - console.log('delta', shape.id, prev, cur, delta) + // console.log('delta', shape.id, prev, cur, delta) let [a, b] = endpoints.value a = vectorize(a) if (!vectorIsZero(delta)) { @@ -252,7 +257,6 @@ function translateOnModel(shape) { } function setModelColor(model) { - console.log('setmc', color.value, model.color) if (model.color !== undefined && model.color !== color.value) color.value = model.color } diff --git a/src/orderbuild.js b/src/orderbuild.js index 440f02f..49ae082 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -208,24 +208,24 @@ export function builderDefaults(builder, defaults) { builder[k] = defaults[k] instanceof Function ? defaults[k]() : defaults[k] } -export function linearWeights(n, s) { - if (n === 1) return [1] +export function linearWeights(num, skew) { + if (num === 1) return [1] const result = [] - if (s === 0) { + if (skew === 0) { // equal weighted - for (let i = 0; i < n; i++) - result.push(1 / n) - } else if (s === 1) { + for (let i = 0; i < num; i++) + result.push(1 / num) + } else if (skew === 1) { result.push(1) - for (let i = 1; i < n; i++) + for (let i = 1; i < num; i++) result.push(0) - } else if (s === -1) { - for (let i = 1; i < n; i++) + } else if (skew === -1) { + for (let i = 1; i < num; i++) result.push(0) result.push(1) } else { - for (let i = 0; i < n; i++) - result.push((1 - s * (2 * i / (n - 1) - 1)) / n) + for (let i = 0; i < num; i++) + result.push((1 - skew * (2 * i / (num - 1) - 1)) / num) } // console.log('weights', result) return result