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-27 20:32:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e369aa7d68217cfd279d5a24921f842aac0202a5
e369aa7d
1 parent
9cc40ad4
Modify transaction_fuction and User Schema & Add nodemon dependencies
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
45 deletions
index.js
models/User.js
package-lock.json
package.json
index.js
View file @
e369aa7
...
...
@@ -13,13 +13,14 @@ const request = require('request-promise-native');
// const request = require('request')
const
{
v4
}
=
require
(
"uuid"
)
const
sign
=
require
(
'jsonwebtoken'
).
sign
var
krw_balance
=
60000
;
var
divided_money
=
krw_balance
/
10
;
var
krw_balance
=
60000
;
var
divided_money
=
krw_balance
/
10
;
var
sort_info
=
new
Array
();
const
mongoose
=
require
(
'mongoose'
);
const
config
=
require
(
'./config/key'
);
const
{
json
}
=
require
(
'express'
);
const
e
=
require
(
'express'
);
const
connect
=
mongoose
.
connect
(
config
.
mongoURI
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
...
...
@@ -34,7 +35,7 @@ const access_key = process.env.access_key;
const
secret_key
=
process
.
env
.
secret_key
;
const
server_url
=
"https://api.upbit.com"
function
get_asset
()
{
function
get_asset
(
market
)
{
const
payload
=
{
access_key
:
access_key
,
nonce
:
v4
(),
...
...
@@ -45,21 +46,16 @@ function get_asset() {
url
:
server_url
+
"/v1/accounts"
,
headers
:
{
Authorization
:
`Bearer
${
token
}
`
},
}
return
new
Promise
(
resolve
=>
{
const
result
=
(
market
)
=>
new
Promise
((
resolve
)
=>
{
request
(
options
,
function
(
err
,
res
,
body
)
{
if
(
err
)
throw
new
Error
(
err
)
// test=res.json
();
var
empty
=
new
Object
();
data
=
JSON
.
parse
(
body
);
// console.log(data[0].currency)
data
.
filter
(
function
(
item
)
{
if
(
item
.
currency
==
"PLA"
)
{
resolve
(
item
);
}
})
resolve
(
data
);
})
})
return
result
(
market
);
}
async
function
get_marketName
()
{
var
data
=
new
Array
();
//전체 암호화폐 리스트 불러오기
...
...
@@ -74,6 +70,13 @@ async function get_marketName() {
return
data
;
}
async
function
transaction_coin
(
coin_name
,
side
,
volume
,
price
,
ord_type
)
{
var
volume
=
volume
;
if
(
side
==
"ask"
){
await
User
.
findOne
({
uid
:
1
}).
then
((
result
)
=>
{
console
.
log
(
result
.
volume
);
volume
=
String
(
result
.
volume
);
}).
catch
(
err
=>
{
console
.
log
(
err
.
error
)});
}
const
body
=
{
market
:
coin_name
,
side
:
side
,
...
...
@@ -84,31 +87,29 @@ async function transaction_coin(coin_name, side, volume, price, ord_type) {
//시장가 매수인 경우 price를 얼마치 살건지 입력
//시장가 매도인경우 volume에 몇개를 팔건지 입력
const
query
=
queryEncode
(
body
)
const
hash
=
crypto
.
createHash
(
'sha512'
)
const
queryHash
=
hash
.
update
(
query
,
'utf-8'
).
digest
(
'hex'
)
const
payload
=
{
access_key
:
access_key
,
nonce
:
v4
(),
query_hash
:
queryHash
,
query_hash_alg
:
'SHA512'
,
}
const
token
=
sign
(
payload
,
secret_key
)
const
options
=
{
method
:
"POST"
,
url
:
server_url
+
"/v1/orders"
,
headers
:
{
Authorization
:
`Bearer
${
token
}
`
},
json
:
body
}
await
request
(
options
).
then
(
async
(
result
)
=>
{
console
.
log
(
result
.
body
);
const
user
=
new
User
({
krw_balance
:
100
,
market
:
"KRW-BTC"
,
count
:
1
,
avg_price
:
100
});
await
user
.
save
().
then
(()
=>
{
isuser
=
true
})
},).
catch
((
err
)
=>
{
console
.
log
(
err
.
error
)})
await
request
(
options
).
then
(
async
(
result
)
=>
{
const
asset
=
(
delay
)
=>
new
Promise
((
resolve
)
=>
{
setTimeout
(
async
()
=>
{
resolve
(
await
get_asset
(
result
.
market
));
},
delay
)
})
var
my_asset
=
await
asset
(
1000
);
}).
catch
((
err
)
=>
{
console
.
log
(
err
.
error
)
})
}
async
function
get_marketInfo
()
{
//각 암호화폐 정보 조회
...
...
@@ -191,7 +192,7 @@ async function check_coin(t1) {
}
else
{
console
.
log
(
"***"
+
result
.
korean_name
+
"은(는)"
+
result
.
count
*
5
+
"분 동안 하락중"
);
if
(
result
.
count
>=
3
)
{
// transaction_coin(result.name,"bid",null,divided_money,
"price");
transaction_coin
(
result
.
name
,
"bid"
,
null
,
divided_money
,
"price"
);
}
}
})
...
...
@@ -201,17 +202,16 @@ async function check_coin(t1) {
//특정 조건...
const
user
=
new
User
({
krw_balance
:
100
,
market
:
"KRW-BTC"
,
count
:
1
,
avg_price
:
100
});
await
user
.
save
().
then
(()
=>
{
isuser
=
true
})
// transaction_coin(result.name,"ask","몇개를 팔건지",null,"market");
console
.
log
(
result
.
korean_name
+
"은(는)"
+
result
.
count
*
5
+
"분 동안 상승 혹은 정체중"
);
})
}
})
}
else
{
}
else
{
console
.
log
(
"메롱"
);
}
}
}
else
{
console
.
log
(
result
);
console
.
log
(
user_data
);
}
}).
catch
((
err
)
=>
{
console
.
log
(
err
);
...
...
@@ -256,9 +256,8 @@ app.listen(5000, async () => {
console
.
log
(
'server start'
)
//coin 이름,가격,거래대금 저장 , DB 최신화 1시간마다 반복
//5분마다 현재 가격 가져와서 db랑 비교후 매수 매도 기준잡기
//
var t1 = new Array();
//
test_data = await (latest_repeat(t1));
var
t1
=
new
Array
();
test_data
=
await
(
latest_repeat
(
t1
));
//계좌 정보 db 최신화
// console.log(await get_asset());
await
transaction_coin
(
"KRW-BTC"
,
"bid"
,
null
,
divided_money
,
"price"
);
})
\ No newline at end of file
...
...
models/User.js
View file @
e369aa7
const
mongoose
=
require
(
'mongoose'
);
const
userSchema
=
mongoose
.
Schema
({
uid
:{
type
:
Number
},
krw_balance
:{
type
:
Number
,
},
...
...
@@ -12,6 +15,9 @@ const userSchema=mongoose.Schema({
},
avg_buy_price
:{
type
:
Number
},
volume
:{
type
:
Number
}
})
...
...
package-lock.json
View file @
e369aa7
...
...
@@ -23,7 +23,7 @@
"uuid"
:
"^8.3.2"
},
"devDependencies"
:
{
"nodemon"
:
"^2.0.1
4
"
"nodemon"
:
"^2.0.1
5
"
}
},
"node_modules/@sindresorhus/is"
:
{
...
...
@@ -1726,21 +1726,21 @@
"integrity"
:
"sha512-0bA08/2RKWxw6pMkOVd3KP+0F5+ifQLMMTDxrCgxlgkoU1N8DhCbCSAYEqpgaVYM2smvbVVewiXjW+8AyoLfxQ=="
},
"node_modules/nodemon"
:
{
"version"
:
"2.0.1
4
"
,
"resolved"
:
"https://registry.npmjs.org/nodemon/-/nodemon-2.0.1
4
.tgz"
,
"integrity"
:
"sha512-
frcpDx+PviKEQRSYzwhckuO2zoHcBYLHI754RE9z5h1RGtrngerc04mLpQQCPWBkH/2ObrX7We9YiwVSYZpFJQ
=="
,
"version"
:
"2.0.1
5
"
,
"resolved"
:
"https://registry.npmjs.org/nodemon/-/nodemon-2.0.1
5
.tgz"
,
"integrity"
:
"sha512-
gdHMNx47Gw7b3kWxJV64NI+Q5nfl0y5DgDbiVtShiwa7Z0IZ07Ll4RLFo6AjrhzMtoEZn5PDE3/c2AbVsiCkpA
=="
,
"dev"
:
true
,
"hasInstallScript"
:
true
,
"dependencies"
:
{
"chokidar"
:
"^3.
2
.2"
,
"debug"
:
"^3.2.
6
"
,
"chokidar"
:
"^3.
5
.2"
,
"debug"
:
"^3.2.
7
"
,
"ignore-by-default"
:
"^1.0.1"
,
"minimatch"
:
"^3.0.4"
,
"pstree.remy"
:
"^1.1.
7
"
,
"pstree.remy"
:
"^1.1.
8
"
,
"semver"
:
"^5.7.1"
,
"supports-color"
:
"^5.5.0"
,
"touch"
:
"^3.1.0"
,
"undefsafe"
:
"^2.0.
3
"
,
"undefsafe"
:
"^2.0.
5
"
,
"update-notifier"
:
"^5.1.0"
},
"bin"
:
{
...
...
@@ -4041,20 +4041,20 @@
"integrity"
:
"sha512-0bA08/2RKWxw6pMkOVd3KP+0F5+ifQLMMTDxrCgxlgkoU1N8DhCbCSAYEqpgaVYM2smvbVVewiXjW+8AyoLfxQ=="
},
"nodemon"
:
{
"version"
:
"2.0.1
4
"
,
"resolved"
:
"https://registry.npmjs.org/nodemon/-/nodemon-2.0.1
4
.tgz"
,
"integrity"
:
"sha512-
frcpDx+PviKEQRSYzwhckuO2zoHcBYLHI754RE9z5h1RGtrngerc04mLpQQCPWBkH/2ObrX7We9YiwVSYZpFJQ
=="
,
"version"
:
"2.0.1
5
"
,
"resolved"
:
"https://registry.npmjs.org/nodemon/-/nodemon-2.0.1
5
.tgz"
,
"integrity"
:
"sha512-
gdHMNx47Gw7b3kWxJV64NI+Q5nfl0y5DgDbiVtShiwa7Z0IZ07Ll4RLFo6AjrhzMtoEZn5PDE3/c2AbVsiCkpA
=="
,
"dev"
:
true
,
"requires"
:
{
"chokidar"
:
"^3.
2
.2"
,
"debug"
:
"^3.2.
6
"
,
"chokidar"
:
"^3.
5
.2"
,
"debug"
:
"^3.2.
7
"
,
"ignore-by-default"
:
"^1.0.1"
,
"minimatch"
:
"^3.0.4"
,
"pstree.remy"
:
"^1.1.
7
"
,
"pstree.remy"
:
"^1.1.
8
"
,
"semver"
:
"^5.7.1"
,
"supports-color"
:
"^5.5.0"
,
"touch"
:
"^3.1.0"
,
"undefsafe"
:
"^2.0.
3
"
,
"undefsafe"
:
"^2.0.
5
"
,
"update-notifier"
:
"^5.1.0"
},
"dependencies"
:
{
...
...
package.json
View file @
e369aa7
...
...
@@ -28,6 +28,6 @@
"uuid"
:
"^8.3.2"
},
"devDependencies"
:
{
"nodemon"
:
"^2.0.1
4
"
"nodemon"
:
"^2.0.1
5
"
}
}
...
...
Please
register
or
login
to post a comment