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
2019102152 김다빈
2021-11-06 17:56:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
13c5d17e33dfd705fa453ba47559b38ee2f0b7dc
13c5d17e
1 parent
123de305
Sort coin info & save to database
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
5 deletions
README.md
config/key.js
config/prod.js
index.js
models/Coin.js
README.md
View file @
13c5d17
#Trading Service
./config/dev.js 생성 필요
module.exports = {
mongoURI:{mongoURI}
}
...
...
config/key.js
0 → 100644
View file @
13c5d17
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
module
.
exports
=
require
(
'./prod'
);
}
else
{
module
.
exports
=
require
(
'./dev'
);
}
\ No newline at end of file
config/prod.js
0 → 100644
View file @
13c5d17
module
.
exports
=
{
mongoURI
:
process
.
env
.
MONGO_URI
}
\ No newline at end of file
index.js
View file @
13c5d17
const
fetch
=
(...
args
)
=>
import
(
'node-fetch'
).
then
(({
default
:
fetch
})
=>
fetch
(...
args
));
const
url
=
'https://api.upbit.com/v1/market/all'
;
const
url
1
=
'https://api.upbit.com/v1/market/all'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}
};
const
express
=
require
(
'express'
);
const
app
=
express
();
const
{
Coin
}
=
require
(
"./models/Coin"
);
const
mongoose
=
require
(
'mongoose'
);
const
config
=
require
(
'./config/key'
);
const
connect
=
mongoose
.
connect
(
config
.
mongoURI
,{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
})
.
then
(()
=>
console
.
log
(
'디비연결 성공'
))
.
catch
((
err
)
=>
console
.
log
(
err
));
async
function
get_marketName
()
{
var
data
=
new
Array
();
//전체 암호화폐 리스트 불러오기
let
response
=
await
fetch
(
url
,
options
)
let
response
=
await
fetch
(
url
1
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
for
(
i
in
json
){
...
...
@@ -19,9 +30,9 @@ async function get_marketName() {
}
async
function
get_marketInfo
(
name_list
){
//각 암호화폐 정보 조회
const
url
=
`https://api.upbit.com/v1/ticker/?markets=
${
name_list
}
`
;
const
url
2
=
`https://api.upbit.com/v1/ticker/?markets=
${
name_list
}
`
;
var
arr
=
new
Array
();
let
response2
=
await
fetch
(
url
,
options
)
let
response2
=
await
fetch
(
url
2
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
{
for
(
i
in
json
){
...
...
@@ -30,12 +41,39 @@ async function get_marketInfo(name_list){
}
}
})
return
arr
}
async
function
sort_data
(
arr
){
arr
.
sort
((
a
,
b
)
=>
{
return
b
[
1
]
-
a
[
1
];
})
return
arr
;
}
async
function
save_coin
(
arr
){
for
(
var
i
=
0
;
i
<
10
;
i
++
){
if
(
arr
[
i
]){
const
coin
=
new
Coin
({
tid
:
i
+
1
,
name
:
arr
[
i
][
0
],
acc_trade_price_24h
:
arr
[
i
][
1
],
current_price
:
arr
[
i
][
2
]
});
await
coin
.
save
((
err
)
=>
{
if
(
err
){
console
.
log
(
err
)
}
})
}
}
return
true
;
}
app
.
get
(
'/get_market'
,
async
(
req
,
res
)
=>
{
var
name_list
=
(
await
get_marketName
());
var
market_info
=
(
await
get_marketInfo
(
name_list
));
res
.
json
(
market_info
);
var
sort_info
=
(
await
sort_data
(
market_info
));
console
.
log
(
sort_info
);
res
.
json
(
await
save_coin
(
sort_info
));
})
app
.
listen
(
5000
,()
=>
{
console
.
log
(
'server'
)
...
...
models/Coin.js
0 → 100644
View file @
13c5d17
const
mongoose
=
require
(
'mongoose'
);
const
coinSchema
=
mongoose
.
Schema
({
tid
:{
type
:
Number
,
},
name
:{
type
:
String
,
required
:
true
},
acc_trade_price_24h
:{
type
:
Number
,
required
:
true
},
current_price
:{
type
:
Number
,
required
:
true
}
})
const
Coin
=
mongoose
.
model
(
"Coin"
,
coinSchema
);
module
.
exports
=
{
Coin
};
\ No newline at end of file
Please
register
or
login
to post a comment