June

Modify transaction function

Showing 1 changed file with 26 additions and 4 deletions
......@@ -51,7 +51,15 @@ function get_asset(market) {
if (err) throw new Error(err)
var empty = new Object();
data = JSON.parse(body);
resolve(data);
data.filter(function (item) {
if (item.currency == market.split('-')[1]) {
// resolve(item);
empty.market = item;
} else if (item.currency == "KRW") {
empty.KRW = item
}
resolve(empty);
})
})
})
return result(market);
......@@ -69,7 +77,7 @@ async function get_marketName() {
})
return data;
}
async function transaction_coin(coin_name, side, volume, price, ord_type) {
async function transaction_coin(coin_name, side, volume, price, ord_type, first = false) {
var volume=volume;
if(side=="ask"){
await User.findOne({uid:1}).then((result)=>{
......@@ -109,6 +117,16 @@ async function transaction_coin(coin_name, side, volume, price, ord_type) {
},delay)
})
var my_asset=await asset(1000);
if(side=="bid"){
const user = new User({ uid:1,krw_balance: my_asset.KRW.balance, market: coin_name, count: 1, avg_price: my_asset.market.avg_buy_price,volume:my_asset.market.balance });
await user.save().then(() => { isuser = true })
}else if(side=="ask"){
User.deleteOne({uid:1},(err,res)=>{
if(err){
console.log(err);
}
});
}
}).catch((err) => { console.log(err.error) })
}
async function get_marketInfo() {
......@@ -256,8 +274,12 @@ 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","ask","",null,"market");
//매수
// await transaction_coin("KRW-BTC", "bid", null, divided_money, "price");
})
\ No newline at end of file
......