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-06-07 07:11:03 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7c5252af3130c62492ede6db0cd265b415336d0b
7c5252af
1 parent
78561e95
Add Comparing price function
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
6 deletions
app.js
app.js
View file @
7c5252a
var
express
=
require
(
'express'
);
const
line
Token
=
require
(
'./apiKey.json'
);
const
Token
=
require
(
'./apiKey.json'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
lineToken
.
line_token
;
const
TOKEN
=
Token
.
line_token
;
const
binanceKey
=
Token
.
binance_key
;
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
fetch
=
require
(
'node-fetch'
);
const
rp
=
require
(
'request-promise'
);
const
domain
=
"2018102235.oss2021.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
...
...
@@ -31,8 +33,6 @@ app.post('/hook', function (req, res) {
}
}
res
.
sendStatus
(
200
);
});
...
...
@@ -54,6 +54,47 @@ function kimp(replyToken,message){
return
promise
;
}
korean_price
().
then
(
function
(
upbitPrice
){
compare_price
(
replyToken
,
message
,
upbitPrice
);
});
}
function
compare_price
(
replyToken
,
message
,
upbitPrice
){
var
binancePrice
=
0
;
function
binance_price
(){
var
promise
=
new
Promise
(
function
(
resolve
,
reject
){
const
url
=
'https://api.binance.com/api/v3/ticker/price?symbol='
+
message
+
'USDT'
;
const
options
=
{
method
:
'GET'
,
headers
:
{
Accept
:
'application/json'
}};
const
requestOptions
=
{
method
:
'GET'
,
uri
:
'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
,
qs
:
{
'start'
:
'1'
,
'limit'
:
'10'
,
'convert'
:
'KRW'
},
headers
:
{
'X-CMC_PRO_API_KEY'
:
binanceKey
},
json
:
true
,
gzip
:
true
};
fetch
(
url
,
options
)
.
then
(
res
=>
res
.
json
())
.
then
(
json
=>
rp
(
requestOptions
).
then
(
response
=>
{
var
i
=
0
;
while
(
response
.
data
[
i
].
id
!==
825
){
i
=
i
+
1
;
}
binancePrice
=
json
.
price
*
response
.
data
[
i
].
quote
.
KRW
.
price
;
resolve
(
binancePrice
);
})
).
catch
(
err
=>
console
.
error
(
'error:'
+
err
));
});
return
promise
;
}
binance_price
().
then
(
function
(
binancePrice
){
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -65,8 +106,12 @@ function kimp(replyToken,message){
"messages"
:[
{
"type"
:
"text"
,
"text"
:
String
(
upbitPrice
)
"text"
:
"binance : "
+
String
(
binancePrice
.
toFixed
())
+
"원"
},
{
"type"
:
"text"
,
"text"
:
"Upbit : "
+
String
(
upbitPrice
)
+
"원"
}
]
}
},(
error
,
response
,
body
)
=>
{
...
...
@@ -76,7 +121,6 @@ function kimp(replyToken,message){
});
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
...
...
Please
register
or
login
to post a comment