Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Crypto
/
Crypto-auto-trading
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
June
2021-11-12 00:06:38 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1a663f4945e747fdcdb3dfdf9b9194b0210bfd2f
1a663f49
1 parent
4085f941
Add repeat taker function
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
6 deletions
index.js
models/Coin.js
index.js
View file @
1a663f4
...
...
@@ -28,8 +28,9 @@ async function get_marketName() {
})
return
data
;
}
async
function
get_marketInfo
(
name_list
)
{
async
function
get_marketInfo
()
{
//각 암호화폐 정보 조회
var
name_list
=
await
get_marketName
();
const
url2
=
`https://api.upbit.com/v1/ticker/?markets=
${
name_list
}
`
;
var
arr
=
new
Array
();
let
response2
=
await
fetch
(
url2
,
options
)
...
...
@@ -43,7 +44,8 @@ async function get_marketInfo(name_list) {
})
return
arr
}
async
function
sort_data
(
arr
)
{
async
function
sort_data
()
{
arr
=
await
get_marketInfo
();
arr
.
sort
((
a
,
b
)
=>
{
return
b
[
1
]
-
a
[
1
];
})
...
...
@@ -75,7 +77,6 @@ async function get_candle(minute, market) {
.
then
(
json
=>
candle
=
json
)
return
candle
;
}
app
.
get
(
'/get_market'
,
async
(
req
,
res
)
=>
{
var
name_list
=
(
await
get_marketName
());
var
market_info
=
(
await
get_marketInfo
(
name_list
));
...
...
@@ -90,13 +91,73 @@ app.get('/get_candle', async (req, res) => {
get_candle
(
5
,
item
.
name
)
.
then
(
result
=>
{
Coin
.
findOneAndUpdate
({
name
:
result
[
0
].
market
},
{
five_candle
:
result
[
0
].
trade_price
},
{
new
:
true
},
(
err
,
doc
)
=>
{
console
.
log
(
doc
);
//
console.log(doc);
})
})
})
});
})
app
.
listen
(
5000
,
()
=>
{
console
.
log
(
'server'
)
async
function
refresh_db
()
{
Coin
.
find
()
.
then
(
result
=>
{
if
(
result
.
length
!==
0
)
{
Coin
.
deleteMany
({
tid
:
{
$gt
:
0
}
},
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
}
else
{
console
.
log
(
result
);
}
})
}
save_coin
(
sort_info
);
})
}
async
function
repeat_check
(
t1
)
{
await
Coin
.
find
().
then
(
result
=>
{
for
(
var
key
in
result
)
{
t1
.
push
(
result
[
key
].
name
)
}
})
setTimeout
(()
=>
{
setInterval
(
async
()
=>
{
for
(
var
i
=
0
;
i
<
t1
.
length
;
i
++
)
{
// console.log(t1.length);
// console.log(t1[i]);
var
candle
=
await
get_candle
(
5
,
t1
[
i
]);
// console.log(i+"번째 코인 가격 "+candle[0].trade_price);
await
Coin
.
findOne
({
name
:
candle
[
0
].
market
}).
then
((
result
)
=>
{
//가격이 떨어졌을때
if
(
result
.
current_price
>
candle
[
0
].
trade_price
)
{
Coin
.
updateOne
({
name
:
candle
[
0
].
market
},
{
current_price
:
candle
[
0
].
trade_price
,
$inc
:
{
count
:
1
}
},
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
}
else
{
}
})
}
//그대로 이거나 올랐을때
else
{
Coin
.
updateOne
({
name
:
candle
[
0
].
market
},
{
current_price
:
candle
[
0
].
trade_price
,
count
:
0
},
(
err
,
result
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
}
else
{
}
})
}
})
}
},
600
*
5
);
},
600
*
5
);
}
app
.
listen
(
5000
,
async
()
=>
{
console
.
log
(
'server start'
)
//coin 이름,가격,거래대금 저장
sort_info
=
(
await
sort_data
());
//DB 최신화
(
await
refresh_db
());
var
t1
=
new
Array
();
test_data
=
await
(
repeat_check
(
t1
));
//반복
})
\ No newline at end of file
...
...
models/Coin.js
View file @
1a663f4
...
...
@@ -18,6 +18,10 @@ const coinSchema=mongoose.Schema({
},
five_candle
:{
type
:
Number
},
count
:{
type
:
Number
,
default
:
0
}
})
...
...
Please
register
or
login
to post a comment