Commit 848d1110 authored by 1486327116's avatar 1486327116

format

parent cbf218eb
'use strict';
const schedule = require('node-schedule');
let { logger, datetimeUtils } = require('@madex/ex-js-public');
import { spotPairs, ormDB, coinType } from "@madex/ex-ts-dao";
import { getPairFromCore, getCoinFromCore } from '../src/utils/coreSystemUtils'
let running = false;
/**
* 每五分钟检查一次
*/
let job = schedule.scheduleJob('*/15 * * * * ?', async function () {
logger.info('setting sync start');
if (!running) {
try {
await syncPair();
await syncCoin();
running = true;
logger.info("coinAndPair sync job finish");
} catch (e) {
logger.info(e)
}
running = false;
}
});
const syncPair = async () => {
let now = new Date();
let res = await spotPairs.prototype.findAll({
where: {
status:1,
updatedAt:{[ormDB.Op.lt]:new Date(now.getTime()-10*1000)} // 10秒之前的
},
raw: true
})
for (const pair of res) {
const { symbol, id } = pair;
let cfg = await getPairFromCore(symbol);
if (cfg) {
await spotPairs.prototype.update({
status: 2,
product_id: cfg.id,
price_scale: cfg["price-scale"],
price_increment: cfg["price-increment"],
quantity_scale: cfg["quantity-scale"],
quantity_increment: cfg["quantity-increment"],
}, {
where: { id, status: 1 }
});
logger.info(symbol, "sync config success")
}
}
}
const syncCoin = async () => {
let now = new Date();
let res = await coinType.prototype.findAll({
where: {
is_main:1,
main_status:1,
updatedAt:{[ormDB.Op.lt]:new Date(now.getTime()-10*1000)} // 10秒之前的
},
raw: true
})
for (const coin of res) {
const { general_name:symbol, id } = coin;
let cfg = await getCoinFromCore(symbol);
if (cfg) {
await coinType.prototype.update({
main_status: 2,
asset_id: cfg["id"],
}, {
where: { id, main_status: 1 }
});
logger.info(symbol, "sync config success")
}
}
}
// job.invoke();
// 计划任务
\ No newline at end of file
// 计划任务
require("./coinAndPairSetting.sync");
\ No newline at end of file
......@@ -874,7 +874,7 @@
},
"node_modules/@madex/ex-js-common": {
"version": "1.0.0",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-common.git#8454d948b63c279242837dddf00a1089b6f76223",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-common.git#6aa1d7d9264b2a13e13fe6c79d33223205b9cc40",
"license": "ISC",
"dependencies": {
"@madex/ex-js-dao": "git+ssh://git@bitbucket.org/biiigle/ex-js-dao.git#master",
......@@ -940,7 +940,7 @@
},
"node_modules/@madex/ex-js-dao": {
"version": "1.0.0",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-dao.git#1cd641acf21ab34be602e6240ef542bda31195a2",
"resolved": "git+ssh://git@bitbucket.org/biiigle/ex-js-dao.git#37d36528608cbd7affb29aa88ba022cc073495c5",
"license": "ISC",
"dependencies": {
"@madex/ex-js-public": "git+ssh://git@bitbucket.org/biiigle/ex-js-public.git#master",
......@@ -1068,9 +1068,9 @@
}
},
"node_modules/@madex/ex-ts-dao": {
"version": "0.0.15",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/@madex/ex-ts-dao/-/@madex/ex-ts-dao-0.0.15.tgz",
"integrity": "sha512-O2Y/jNMOsTU7dYvgswVLgDzL3hVocD57z2KV293JlI2xJBBnclh+lYC1j1pt6FPbaSP/wo/IcITpfQhiFO6NZg==",
"version": "0.0.17",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/@madex/ex-ts-dao/-/@madex/ex-ts-dao-0.0.17.tgz",
"integrity": "sha512-TDR4FNGVSAv4FLqJQJZ+D8ZeJmBacQIF7AYVECutsL4PWE5LBRP3xylvuL1EB6DRdbDRt/L42k7bdChWn1TN0A==",
"license": "ISC",
"dependencies": {
"@madex/ex-js-public": "git+ssh://git@bitbucket.org/biiigle/ex-js-public.git#master",
......@@ -4455,9 +4455,9 @@
}
},
"node_modules/electron-to-chromium": {
"version": "1.5.12",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/electron-to-chromium/-/electron-to-chromium-1.5.12.tgz",
"integrity": "sha512-tIhPkdlEoCL1Y+PToq3zRNehUaKp3wBX/sr7aclAWdIWjvqAe/Im/H0SiCM4c1Q8BLPHCdoJTol+ZblflydehA==",
"version": "1.5.13",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/electron-to-chromium/-/electron-to-chromium-1.5.13.tgz",
"integrity": "sha512-lbBcvtIJ4J6sS4tb5TLp1b4LyfCdMkwStzXPyAgVgTRAsep4bvrAGaBOP7ZJtQMNJpSQ9SqG4brWOroNaQtm7Q==",
"dev": true,
"license": "ISC"
},
......@@ -7279,9 +7279,9 @@
"license": "MIT"
},
"node_modules/is-core-module": {
"version": "2.15.0",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/is-core-module/-/is-core-module-2.15.0.tgz",
"integrity": "sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA==",
"version": "2.15.1",
"resolved": "https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/is-core-module/-/is-core-module-2.15.1.tgz",
"integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==",
"dev": true,
"license": "MIT",
"dependencies": {
......
const axios = require("axios");
import configSetting from "./../../config"
const webadmin_endpoint = configSetting.webadmin_endpoint
let { logger } = require('@madex/ex-js-public');
// { id: 1, symbol: 'BTC' }
export const getCoinFromCore = async(symbol)=> {
const url = `${webadmin_endpoint}/asset/by_symbol?symbol=${symbol}`
let { data } = await axios.get(url);
if (data.error) {
logger.error("getCoinFromCore",data);
return null
}
return data[0];
}
// {
// "id": 1,
// "symbol": 'BTC_USDT',
// 'price-scale': 4,
// 'price-increment': 1,
// 'quantity-scale': 2,
// 'quantity-increment': '0'
// }
export const getPairFromCore = async(symbol,market="spot")=> {
const url = `${webadmin_endpoint}/pair/by_symbol?symbol=${symbol}&market=${market}`
let { data } = await axios.get(url);
if (data.error) {
logger.error("getPairFromCore",data);
return null
}
return data[0]
}
// getPairFromCore("BTC_USDT").then(console.log)
\ No newline at end of file
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