Commit 8bc75bc0 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 7a99f950
let moment = require('moment-timezone')
let plus = 'plus'
let zarib = 'zarib'
let plus='plus' function run(data, config) {
let zarib='zarib'
function run(data,config) {
let commision = config.commision let commision = config.commision
let money = config.base let money = config.base
let total = 0 let total = 0
...@@ -18,22 +15,21 @@ let zarib='zarib' ...@@ -18,22 +15,21 @@ let zarib='zarib'
// console.log(data) // console.log(data)
let step = 0 let step = 0
let reserv=0 let reserv = 0
let profit=0 let profit = 0
let lastCom=0 let lastCom = 0
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
if (step === 0) if (step === 0)
money = config.base money = config.base
else else {
{ if (config.type === zarib)
if (config.type ===zarib)
money = config.base * config.param * step money = config.base * config.param * step
else if (config.type ===plus) else if (config.type === plus)
money = config.base +(config.param * step) money = config.base + (config.param * step)
} }
let d = inlineCheck(money, commision, data[i],profit,lastCom) let d = inlineCheck(money, commision, data[i], profit, lastCom)
if (Math.abs(d.reserve) > Math.abs(maxReserve)) if (Math.abs(d.reserve) > Math.abs(maxReserve))
...@@ -41,54 +37,70 @@ let zarib='zarib' ...@@ -41,54 +37,70 @@ let zarib='zarib'
if (money > maxAllocatedMoney) if (money > maxAllocatedMoney)
maxAllocatedMoney = money maxAllocatedMoney = money
// console.log(data[i]) // console.log(data[i])
// console.log( 'step->'+step) // console.log( 'step->'+step)
// console.log(d) // console.log(d)
if (step>maxLevel) if (step > maxLevel)
maxLevel=step maxLevel = step
if (d.done === true) { if (d.done === true) {
step = 0 step = 0
reserv=0 reserv = 0
profit=0 profit = 0
lastCom=0 lastCom = 0
total++ total++
} else { } else {
step++ step++
profit=profit+d.profit profit = profit + d.profit
lastCom=lastCom+d.com lastCom = lastCom + d.com
} }
} }
let percentage=maxReserve+total
percentage=maxAllocatedMoney/percentage
let minus=0
if (percentage<0) { let dur = getMinDiff(data[0].openDate, data[data.length - 1].closeDate)
minus=percentage let newT=total/dur
let percentage = maxReserve + total
percentage = maxAllocatedMoney / percentage
let minus = 0
if (percentage < 0) {
minus = percentage
percentage = null percentage = null
} }
// let percentage2 = maxReserve + newT
// percentage2 = maxAllocatedMoney / percentage2
// let minus2 = 0
// if (percentage2 < 0) {
// minus2 = percentage2
// percentage2 = null
// }
let opt = { let opt = {
platform: data[0].signal, platform: data[0].signal,
type:config.type +' param:'+config.param+' base:'+config.base, type: config.type + ' param:' + config.param + ' base:' + config.base,
total: total, total: total,
avgLevel: maxLevel/total, avgLevel: maxLevel / total,
maxLevel: maxLevel, maxLevel: maxLevel,
dur:dur,
maxAllocatedMoney: maxAllocatedMoney, maxAllocatedMoney: maxAllocatedMoney,
avgAllocatedMoney: maxAllocatedMoney/total, avgAllocatedMoney: maxAllocatedMoney / total,
maxReseve: maxReserve, maxReseve: maxReserve,
avgReserve: maxReserve/total, avgReserve: maxReserve / total,
percentage:percentage, percentage: percentage,
minus:minus avgProfitPerDay:newT,
minus: minus,
}
}
return opt return opt
...@@ -98,27 +110,27 @@ let zarib='zarib' ...@@ -98,27 +110,27 @@ let zarib='zarib'
} }
function inlineCheck(money, com, data,profit,lastCom) { function inlineCheck(money, com, data, profit, lastCom) {
// console.log(profit) // console.log(profit)
com = com * money com = com * money
let target = money +Math.abs(profit)+ com+lastCom + 1 let target = money + Math.abs(profit) + com + lastCom + 1
let reserve = percentage(money, data.drawDown) let reserve = percentage(money, data.drawDown)
let profitMoney = percentageMinus(money, data.profit) let profitMoney = percentageMinus(money, data.profit)
let diff=reserve - money let diff = reserve - money
diff=diff-com-lastCom+profit diff = diff - com - lastCom + profit
// console.log('reserve->'+reserve + ' money->'+money +' com->'+com +' lastCom->'+lastCom + 'profit->'+profit +' diff->'+diff) // console.log('reserve->'+reserve + ' money->'+money +' com->'+com +' lastCom->'+lastCom + 'profit->'+profit +' diff->'+diff)
if (percentage(money,data.runUp) > target) if (percentage(money, data.runUp) > target)
return {done: true, reserve: diff} return {done: true, reserve: diff}
else else
return {done: false, reserve: diff,profit:profitMoney,com:com} return {done: false, reserve: diff, profit: profitMoney, com: com}
} }
...@@ -146,12 +158,21 @@ function percentageMinus(base, per) { ...@@ -146,12 +158,21 @@ function percentageMinus(base, per) {
return temp return temp
} }
function getMinDiff(start, closed) {
//2019-05-25T05:34:27+04:30
var now = moment(moment(closed).tz('Asia/Tehran').format());
var end = moment.duration(now.diff(moment(start).tz('Asia/Tehran')));
// console.log(parseInt(end.asDays()))
return parseInt(end.asDays())
}
module.exports = module.exports =
{ {
run:run, run: run,
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ let _ = require('lodash') ...@@ -5,7 +5,7 @@ let _ = require('lodash')
test() test()
async function test() { async function test() {
let configs = await fs.readFileSync('./config.json', 'utf8') let configs = await fs.readFileSync('./configs.json', 'utf8')
configs = JSON.parse(configs) configs = JSON.parse(configs)
let arr = [] let arr = []
let files = await fs.readdirSync('./work') let files = await fs.readdirSync('./work')
...@@ -44,7 +44,7 @@ function createfile(data) { ...@@ -44,7 +44,7 @@ function createfile(data) {
async function test2() { async function test2() {
let configs = await fs.readFileSync('./config.json', 'utf8') let configs = await fs.readFileSync('./configTemp.json', 'utf8')
configs = JSON.parse(configs) configs = JSON.parse(configs)
console.log(configs) console.log(configs)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment