switched to 45 pip distance

This commit is contained in:
artin 2023-08-03 03:29:49 -07:00
parent 09dc949a9e
commit 8754ca77fe

View File

@ -14,8 +14,10 @@ const client = new pg.Client(
client.connect();
var ASKGAP = 0.9955;
var BIDGAP = 1.0045;
//var ASKGAP = 0.9955;
//var BIDGAP = 1.0045;
var ASKGAP = 0.0045;
var BIDGAP = 0.0045;
const port = 3000;
const host = "0.0.0.0";
@ -55,15 +57,10 @@ function processTP() {
for (const pair in PRICES) {
for (const acct in STATE) {
//console.log(`acct:${acct} pair:${pair}`);
//console.log(STATE[acct][pair]);
if (typeof (STATE[acct][pair]) !== 'undefined' && STATE[acct][pair]["watch"] == "ask") {
if (PRICES[pair]["ask"] * STATE[acct][pair]["TPVal"] >= STATE[acct][pair]["trigger"]) {
STATE[acct][pair]["trigger"] = PRICES[pair]["ask"] * STATE[acct][pair]["TPVal"];
if (typeof(STATE[acct][pair]) !== 'undefined' && STATE[acct][pair]["watch"] == "ask") {
if (PRICES[pair]["ask"] - STATE[acct][pair]["TPVal"] >= STATE[acct][pair]["trigger"]) {
STATE[acct][pair]["trigger"] = PRICES[pair]["ask"] - STATE[acct][pair]["TPVal"];
STATE[acct][pair]["TP"] = true;
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["trigger"] - STATE[acct][pair]["base"];
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["TPVal"] * 0.32;
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["TPVal"] + STATE[acct][pair]["base"];
} else if (
STATE[acct][pair]["TP"] == true &&
@ -76,14 +73,11 @@ function processTP() {
);
delete STATE[acct][pair];
}
} else if (typeof (STATE[acct][pair]) !== 'undefined' && STATE[acct][pair]["watch"] == "bid") {
if (PRICES[pair]["bid"] <= STATE[acct][pair]["trigger"]) {
} else if (typeof(STATE[acct][pair]) !== 'undefined' && STATE[acct][pair]["watch"] == "bid") {
if (PRICES[pair]["bid"] + STATE[acct][pair]["TPVal"] <= STATE[acct][pair]["trigger"]) {
STATE[acct][pair]["trigger"] = PRICES[pair]["bid"];
STATE[acct][pair]["TP"] = true;
STATE[acct][pair]["trigger"] = PRICES[pair]["bid"] * STATE[acct][pair]["TPVal"];
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["base"] - STATE[acct][pair]["trigger"];
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["TPVal"] * 0.32;
//STATE[acct][pair]["TPVal"] = STATE[acct][pair]["base"] - STATE[acct][pair]["TPVal"];
STATE[acct][pair]["trigger"] = PRICES[pair]["bid"] + STATE[acct][pair]["TPVal"];
} else if (
STATE[acct][pair]["TP"] == true &&
PRICES[pair]["bid"] > STATE[acct][pair]["trigger"]
@ -386,7 +380,7 @@ async function takeProfit(acct_id, api_key, tradeID, dist) {
}
app.get("/closeAll", async (req, res) => {
res.json("disabled for now");
res.json("disabled for now");
});
app.get("/asdfadsfasdfcloseAll", async (req, res) => {
@ -487,19 +481,21 @@ app.get("/trades", async (req, res) => {
try {
r[account] = response.data;
STATE[account] = {};
STATE[account] = {};
for (const t in response.data["trades"]) {
let td = response["data"]["trades"][t];
console.log(td);
let delta = 0.0012;
let askGap = ASKGAP;
let bidGap = BIDGAP ;
let td = response["data"]["trades"][t];
console.log(td);
//let delta = 0.0012;
let delta = 0;
let askGap = ASKGAP;
let bidGap = BIDGAP;
if (td["instrument"].includes("JPY")) {
delta = 0.12;
askGap = ASKGAP * 100;
bidGap = BIDGAP * 100;
//delta = 0.12;
delta = 0;
askGap = ASKGAP * 100;
bidGap = BIDGAP * 100;
}
if (typeof (STATE[account][td["instrument"]]) === 'undefined') {
if (typeof(STATE[account][td["instrument"]]) === 'undefined') {
STATE[account][td["instrument"]] = {};
}
STATE[account][td["instrument"]]["TP"] = true;
@ -508,12 +504,12 @@ app.get("/trades", async (req, res) => {
if (td["currentUnits"] > 0) {
STATE[account][td["instrument"]]["base"] = Number(td["price"]) + delta;
STATE[account][td["instrument"]]["watch"] = "ask";
STATE[account][td["instrument"]]["trigger"] = (Number(td["price"]) + delta) * askGap;
STATE[account][td["instrument"]]["trigger"] = (Number(td["price"]) + delta) - askGap;
STATE[account][td["instrument"]]["TPVal"] = askGap;
} else {
STATE[account][td["instrument"]]["base"] = Number(td["price"]) - delta;
STATE[account][td["instrument"]]["watch"] = "bid";
STATE[account][td["instrument"]]["trigger"] = (Number(td["price"]) - delta) * bidGap;
STATE[account][td["instrument"]]["trigger"] = (Number(td["price"]) - delta) + bidGap;
STATE[account][td["instrument"]]["TPVal"] = bidGap;
}
}
@ -617,17 +613,17 @@ app.get("/order/:instrument/:quantity", async (req, res) => {
console.log(response["data"]);
if (typeof response["data"]["orderFillTransaction"] !== "undefined") {
let delta = 0.0012;
let askGap = ASKGAP;
let bidGap = BIDGAP;
let askGap = ASKGAP;
let bidGap = BIDGAP;
if (req.params.instrument.includes("JPY")) {
delta = 0.12;
askGap = ASKGAP * 100;
bidGap = BIDGAP * 100;
askGap = ASKGAP * 100;
bidGap = BIDGAP * 100;
}
if (typeof (STATE[account]) === 'undefined') {
if (typeof(STATE[account]) === 'undefined') {
STATE[account] = {};
}
if (typeof (STATE[account][req.params.instrument]) === 'undefined') {
if (typeof(STATE[account][req.params.instrument]) === 'undefined') {
STATE[account][req.params.instrument] = {};
}
STATE[account][req.params.instrument]["TP"] = true;
@ -661,11 +657,11 @@ app.listen(port, host, () => {
async function price_stream() {
const response = await fetch(
`${STREAMURL_DEMO}/accounts/101-001-8005237-001/pricing/stream?instruments=GBP_CAD%2CNZD_CAD%2CEUR_CHF%2CEUR_CAD%2CNZD_CHF%2CCHF_JPY%2CUSD_CHF%2CAUD_JPY%2CEUR_USD%2CNZD_USD%2CUSD_JPY%2CGBP_AUD%2CEUR_AUD%2CCAD_JPY%2CEUR_GBP%2CAUD_CAD%2CEUR_JPY%2CAUD_CHF%2CCAD_CHF%2CGBP_JPY%2CUSD_CAD%2CNZD_JPY%2CUSD_SGD%2CAUD_USD%2CGBP_CHF%2CAUD_NZD%2CGBP_USD`, {
method: "GET",
headers: {
Authorization: "Bearer e88218d201bd344c2dc3c469f8f8d1f3-e77504680a17f51f0baecf9dababa40b",
},
}
method: "GET",
headers: {
Authorization: "Bearer e88218d201bd344c2dc3c469f8f8d1f3-e77504680a17f51f0baecf9dababa40b",
},
}
);
try {
for await (const chunk of response.body) {