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 16:26:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b5033aa83b2208ec3cd0106f59c4bb7b066c517e
b5033aa8
1 parent
5b57b649
postman에 코인리스트 10개를 업로드 할 수 있다
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
25 deletions
app.js
test.js
test2.js
app.js
View file @
b5033aa
...
...
@@ -7,33 +7,42 @@ app.use(bodyParser.urlencoded({ extended: false }));
app
.
use
(
bodyParser
.
json
());
app
.
get
(
'/price'
,
function
(
req
,
res
)
{
var
arr
;
var
responseList
=
new
Array
();
fs
.
readFile
(
'coin_name.txt'
,
'utf8'
,
function
(
err
,
data
){
arr
=
data
.
split
(
","
);
console
.
log
(
arr
);
for
(
var
i
=
0
;
i
<
1
;
i
++
){
// 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
(
req
=>
req
.
json
())
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
coinJson
.
coin
=
arr
[
i
];
coinJson
.
price
=
json
[
0
][
"trade_price"
]
;
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
);
}
}).
then
(
function
(){
jsonData
=
JSON
.
stringify
(
responseList
);
res
.
send
(
jsonData
);
});
return
promise
;
}
print_coin
().
then
(
function
(
resList
){
res
.
send
(
resList
);
});
})
})
var
server
=
app
.
listen
(
8082
);
console
.
log
(
"Server Created.."
);
...
...
test.js
View file @
b5033aa
const
fetch
=
require
(
'node-fetch'
);
var
fs
=
require
(
'fs'
);
var
responseList
=
new
Array
();
fs
.
readFile
(
'coin_name.txt'
,
'utf8'
,
function
(
err
,
data
){
arr
=
data
.
split
(
","
);
// console.log(arr);
for
(
var
i
=
0
;
i
<
10
;
i
++
){
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
;
})
.
then
(
function
(){
responseList
.
push
(
coinJson
);
console
.
log
(
responseList
);
//console.log(responseList)
if
(
i
>
8
){
resolve
(
responseList
);
}
})
.
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
},
1
0
);
},
i
*
18
0
);
})(
i
);
}
});
return
promise
;
}
print_coin
().
then
(
function
(
resList
){
console
.
log
(
resList
);
});
})
...
...
test2.js
0 → 100644
View file @
b5033aa
// for(var i =0; i<10;i++){
// (function(i){
// setTimeout(function(){
// console.log(i);
// },10);
// })(i);
// }
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
);
});
\ No newline at end of file
Please
register
or
login
to post a comment