Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
ts-api-demo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wmvm
ts-api-demo
Commits
848d1110
Commit
848d1110
authored
Aug 22, 2024
by
1486327116
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
cbf218eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
12 deletions
+141
-12
coinAndPairSetting.ts
cron/coinAndPairSetting.ts
+90
-0
index.ts
cron/index.ts
+3
-1
package-lock.json
package-lock.json
+11
-11
coreSystemUtils.ts
src/utils/coreSystemUtils.ts
+37
-0
No files found.
cron/coinAndPairSetting.ts
0 → 100644
View file @
848d1110
'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();
cron/index.ts
View file @
848d1110
// 计划任务
\ No newline at end of file
// 计划任务
require
(
"./coinAndPairSetting.sync"
);
\ No newline at end of file
package-lock.json
View file @
848d1110
...
...
@@ -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.1
5
"
,
"resolved"
:
"https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/@madex/ex-ts-dao/-/@madex/ex-ts-dao-0.0.1
5
.tgz"
,
"integrity"
:
"sha512-
O2Y/jNMOsTU7dYvgswVLgDzL3hVocD57z2KV293JlI2xJBBnclh+lYC1j1pt6FPbaSP/wo/IcITpfQhiFO6NZg
=="
,
"version"
:
"0.0.1
7
"
,
"resolved"
:
"https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/@madex/ex-ts-dao/-/@madex/ex-ts-dao-0.0.1
7
.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.1
2
"
,
"resolved"
:
"https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/electron-to-chromium/-/electron-to-chromium-1.5.1
2
.tgz"
,
"integrity"
:
"sha512-
tIhPkdlEoCL1Y+PToq3zRNehUaKp3wBX/sr7aclAWdIWjvqAe/Im/H0SiCM4c1Q8BLPHCdoJTol+ZblflydehA
=="
,
"version"
:
"1.5.1
3
"
,
"resolved"
:
"https://packages.aliyun.com/646341b481b284e28f47a25b/npm/npm-registry/electron-to-chromium/-/electron-to-chromium-1.5.1
3
.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"
:
{
...
...
src/utils/coreSystemUtils.ts
0 → 100644
View file @
848d1110
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment