changes
This commit is contained in:
parent
8654b046b9
commit
514a4dcf18
65
index.mjs
65
index.mjs
@ -14,6 +14,9 @@ const client = new pg.Client(
|
||||
|
||||
client.connect();
|
||||
|
||||
var ASKGAP = 0.9955;
|
||||
var BIDGAP = 1.0045;
|
||||
|
||||
const port = 3000;
|
||||
const host = "0.0.0.0";
|
||||
|
||||
@ -55,16 +58,16 @@ function processTP() {
|
||||
//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]["trigger"]) {
|
||||
STATE[acct][pair]["trigger"] = PRICES[pair]["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"];
|
||||
//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 &&
|
||||
PRICES[pair]["ask"] < STATE[acct][pair]["TPVal"]
|
||||
PRICES[pair]["ask"] < STATE[acct][pair]["trigger"]
|
||||
) {
|
||||
closeOrder(
|
||||
accounts[acct]["ACCT"],
|
||||
@ -77,12 +80,13 @@ function processTP() {
|
||||
if (PRICES[pair]["bid"] <= STATE[acct][pair]["trigger"]) {
|
||||
STATE[acct][pair]["trigger"] = PRICES[pair]["bid"];
|
||||
STATE[acct][pair]["TP"] = true;
|
||||
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"];
|
||||
//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"];
|
||||
} else if (
|
||||
STATE[acct][pair]["TP"] == true &&
|
||||
PRICES[pair]["bid"] > STATE[acct][pair]["TPVal"]
|
||||
PRICES[pair]["bid"] > STATE[acct][pair]["trigger"]
|
||||
) {
|
||||
closeOrder(
|
||||
accounts[acct]["ACCT"],
|
||||
@ -382,6 +386,11 @@ async function takeProfit(acct_id, api_key, tradeID, dist) {
|
||||
}
|
||||
|
||||
app.get("/closeAll", async (req, res) => {
|
||||
res.json("disabled for now");
|
||||
|
||||
});
|
||||
app.get("/asdfadsfasdfcloseAll", async (req, res) => {
|
||||
|
||||
for (const acct in STATE) {
|
||||
for (const pair in STATE[acct]) {
|
||||
closeOrder(
|
||||
@ -478,29 +487,34 @@ app.get("/trades", async (req, res) => {
|
||||
try {
|
||||
r[account] = response.data;
|
||||
|
||||
for (const t in response.data) {
|
||||
let td = response["data"][t];
|
||||
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 ;
|
||||
if (td["instrument"].includes("JPY")) {
|
||||
delta = 0.12;
|
||||
}
|
||||
if (typeof (STATE[account]) === 'undefined') {
|
||||
STATE[account] = {};
|
||||
askGap = ASKGAP * 100;
|
||||
bidGap = BIDGAP * 100;
|
||||
}
|
||||
if (typeof (STATE[account][td["instrument"]]) === 'undefined') {
|
||||
STATE[account][td["instrument"]] = {};
|
||||
}
|
||||
STATE[account][td["instrument"]]["TP"] = false;
|
||||
STATE[account][td["instrument"]]["TP"] = true;
|
||||
STATE[account][td["instrument"]]["qty"] = td["quantity"];
|
||||
STATE[account][td["instrument"]]["trade_id"] = td["id"];
|
||||
if (req.params.quantity > 0) {
|
||||
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) * 1.5;
|
||||
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) * 0.5;
|
||||
STATE[account][td["instrument"]]["trigger"] = (Number(td["price"]) - delta) * bidGap;
|
||||
STATE[account][td["instrument"]]["TPVal"] = bidGap;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@ -584,6 +598,7 @@ app.get("/state", async (req, res) => {
|
||||
});
|
||||
|
||||
app.get("/order/:instrument/:quantity", async (req, res) => {
|
||||
client.query(`insert into order_log(order_date,order_body) values (now(), $1)`, [`${req.params.instrument} ${req.params.quantity}`]);
|
||||
let r = {};
|
||||
for (const account of Object.keys(accounts)) {
|
||||
let td = await getTradesByInstrument(
|
||||
@ -602,8 +617,12 @@ 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;
|
||||
if (req.params.instrument.includes("JPY")) {
|
||||
delta = 0.12;
|
||||
askGap = ASKGAP * 100;
|
||||
bidGap = BIDGAP * 100;
|
||||
}
|
||||
if (typeof (STATE[account]) === 'undefined') {
|
||||
STATE[account] = {};
|
||||
@ -611,18 +630,20 @@ app.get("/order/:instrument/:quantity", async (req, res) => {
|
||||
if (typeof (STATE[account][req.params.instrument]) === 'undefined') {
|
||||
STATE[account][req.params.instrument] = {};
|
||||
}
|
||||
STATE[account][req.params.instrument]["TP"] = false;
|
||||
STATE[account][req.params.instrument]["TP"] = true;
|
||||
STATE[account][req.params.instrument]["qty"] = req.params.quantity;
|
||||
STATE[account][req.params.instrument]["trade_id"] =
|
||||
response["data"]["orderFillTransaction"]["tradeOpened"]["tradeID"];
|
||||
if (req.params.quantity > 0) {
|
||||
STATE[account][req.params.instrument]["TPVal"] = askGap;
|
||||
STATE[account][req.params.instrument]["base"] = Number(response["data"]["orderFillTransaction"]["price"]) + delta;
|
||||
STATE[account][req.params.instrument]["watch"] = "ask";
|
||||
STATE[account][req.params.instrument]["trigger"] = (Number(response["data"]["orderFillTransaction"]["price"]) + delta) * 1.5;
|
||||
STATE[account][req.params.instrument]["trigger"] = (Number(response["data"]["orderFillTransaction"]["price"]) + delta) * askGap;
|
||||
} else {
|
||||
STATE[account][req.params.instrument]["TPVal"] = bidGap;
|
||||
STATE[account][req.params.instrument]["base"] = Number(response["data"]["orderFillTransaction"]["price"]) - delta;
|
||||
STATE[account][req.params.instrument]["watch"] = "bid";
|
||||
STATE[account][req.params.instrument]["trigger"] = (Number(response["data"]["orderFillTransaction"]["price"]) + delta) * 0.5;
|
||||
STATE[account][req.params.instrument]["trigger"] = (Number(response["data"]["orderFillTransaction"]["price"]) + delta) * bidGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,13 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@opentelemetry/auto-instrumentations-node": "^0.38.0",
|
||||
"@opentelemetry/exporter-trace-otlp-http": "^0.41.1",
|
||||
"@opentelemetry/instrumentation-express": "^0.33.0",
|
||||
"@opentelemetry/instrumentation-http": "^0.41.1",
|
||||
"@opentelemetry/instrumentation-mysql": "^0.34.0",
|
||||
"@opentelemetry/instrumentation-pg": "^0.36.0",
|
||||
"@opentelemetry/sdk-node": "^0.41.1",
|
||||
"axios": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user