Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정홍주
/
Coin-trade-assistant
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
정홍주
2021-05-23 17:40:35 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
73950ad535a6a72df0957eb71676ed3189512aa3
73950ad5
1 parent
87bb6c34
코인리스트 모두 받아와서 업데이트
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
76 deletions
app.js
test.js
test2.js
app.js
View file @
73950ad
...
...
@@ -13,34 +13,36 @@ app.get('/price', function(req, res) {
var
responseList
=
new
Array
();
function
print_coin
(){
var
promise
=
new
Promise
(
function
(
resolve
,
reject
){
for
(
i
=
0
;
i
<
10
;
i
++
){
(
function
(
i
){
setTimeout
(
function
(){
const
url
=
'https://api.upbit.com/v1/candles/minutes/1?market='
+
arr
[
i
]
+
'&count=1'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}};
var
coinJson
=
new
Object
();
fetch
(
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
coinJson
.
coin
=
arr
[
i
];
coinJson
.
price
=
json
[
0
].
trade_price
;
responseList
.
push
(
coinJson
);
//console.log(responseList)
if
(
i
>
8
){
resolve
(
responseList
);
}
})
.
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
},
i
*
180
);
})(
i
);
for
(
j
=
0
;
j
<
arr
.
length
/
10
;
j
++
){
for
(
i
=
j
*
10
;
i
<
(
j
+
1
)
*
10
;
i
++
){
(
function
(
i
){
setTimeout
(
function
(){
const
url
=
'https://api.upbit.com/v1/candles/minutes/1?market='
+
arr
[
i
]
+
'&count=1'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}};
var
coinJson
=
new
Object
();
fetch
(
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
coinJson
.
coin
=
arr
[
i
];
coinJson
.
price
=
json
[
0
].
trade_price
;
responseList
.
push
(
coinJson
);
console
.
log
(
i
)
if
(
i
>
115
){
resolve
(
responseList
);
}
})
.
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
},
i
*
180
);
})(
i
);
}
}
});
return
promise
;
}
print_coin
().
then
(
function
(
resList
){
res
.
send
(
resList
);
});
});
})
})
var
server
=
app
.
listen
(
8082
);
...
...
test.js
View file @
73950ad
...
...
@@ -7,34 +7,27 @@ fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr
=
data
.
split
(
","
);
// console.log(arr);
var
responseList
=
new
Array
();
function
print_coin
(){
var
promise
=
new
Promise
(
function
(
resolve
,
reject
){
for
(
i
=
0
;
i
<
10
;
i
++
){
(
function
(
i
){
setTimeout
(
function
(){
const
url
=
'https://api.upbit.com/v1/candles/minutes/1?market='
+
arr
[
i
]
+
'&count=1'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}};
var
coinJson
=
new
Object
();
fetch
(
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
coinJson
.
coin
=
arr
[
i
];
coinJson
.
price
=
json
[
0
].
trade_price
;
responseList
.
push
(
coinJson
);
//console.log(responseList)
if
(
i
>
8
){
resolve
(
responseList
);
}
})
.
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
},
i
*
180
);
})(
i
);
}
});
return
promise
;
}
print_coin
().
then
(
function
(
resList
){
console
.
log
(
resList
);
});
for
(
j
=
0
;
j
<
2
;
j
++
){
for
(
i
=
j
*
10
;
i
<
(
j
+
1
)
*
10
;
i
++
){
(
function
(
i
){
setTimeout
(
function
(){
const
url
=
'https://api.upbit.com/v1/candles/minutes/1?market='
+
arr
[
i
]
+
'&count=1'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}};
var
coinJson
=
new
Object
();
fetch
(
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
coinJson
.
coin
=
arr
[
i
];
coinJson
.
price
=
json
[
0
].
trade_price
;
responseList
.
push
(
coinJson
);
// console.log(responseList)
console
.
log
(
i
)
})
.
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
},
i
*
180
);
})(
i
);
}
}
})
...
...
test2.js
View file @
73950ad
// for(var i =0; i<10;i++){
// (function(i){
// setTimeout(function(){
// console.log(i);
// },10);
// })(i);
// }
const
delay
=
()
=>
{
const
randomDelay
=
Math
.
floor
(
Math
.
random
()
*
4
)
*
100
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
randomDelay
))
}
const
loop
=
async
(
list
)
=>
{
console
.
log
(
"시작"
)
const
promises
=
list
.
map
(
async
data
=>
{
return
await
delay
()
.
then
(()
=>
data
)
})
function
f
()
{
var
promise
=
new
Promise
(
function
(
resolve
,
reject
)
{
for
(
var
i
=
0
;
i
<
10
;
i
++
){
(
function
(
i
){
setTimeout
(
function
(){
if
(
i
>
8
){
resolve
(
i
);
}
},
10
);
})(
i
);
}
});
return
promise
;
}
f
().
then
(
function
(
a
)
{
console
.
log
(
a
);
});
const
results
=
await
Promise
.
all
(
promises
)
results
.
forEach
(
data
=>
console
.
log
(
data
))
console
.
log
(
"끝"
)
}
\ No newline at end of file
const
list
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
]
loop
(
list
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment