June

Modify transaction function

Showing 1 changed file with 26 additions and 4 deletions
...@@ -51,7 +51,15 @@ function get_asset(market) { ...@@ -51,7 +51,15 @@ function get_asset(market) {
51 if (err) throw new Error(err) 51 if (err) throw new Error(err)
52 var empty = new Object(); 52 var empty = new Object();
53 data = JSON.parse(body); 53 data = JSON.parse(body);
54 - resolve(data); 54 + data.filter(function (item) {
55 + if (item.currency == market.split('-')[1]) {
56 + // resolve(item);
57 + empty.market = item;
58 + } else if (item.currency == "KRW") {
59 + empty.KRW = item
60 + }
61 + resolve(empty);
62 + })
55 }) 63 })
56 }) 64 })
57 return result(market); 65 return result(market);
...@@ -69,7 +77,7 @@ async function get_marketName() { ...@@ -69,7 +77,7 @@ async function get_marketName() {
69 }) 77 })
70 return data; 78 return data;
71 } 79 }
72 -async function transaction_coin(coin_name, side, volume, price, ord_type) { 80 +async function transaction_coin(coin_name, side, volume, price, ord_type, first = false) {
73 var volume=volume; 81 var volume=volume;
74 if(side=="ask"){ 82 if(side=="ask"){
75 await User.findOne({uid:1}).then((result)=>{ 83 await User.findOne({uid:1}).then((result)=>{
...@@ -109,6 +117,16 @@ async function transaction_coin(coin_name, side, volume, price, ord_type) { ...@@ -109,6 +117,16 @@ async function transaction_coin(coin_name, side, volume, price, ord_type) {
109 },delay) 117 },delay)
110 }) 118 })
111 var my_asset=await asset(1000); 119 var my_asset=await asset(1000);
120 + if(side=="bid"){
121 + 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 });
122 + await user.save().then(() => { isuser = true })
123 + }else if(side=="ask"){
124 + User.deleteOne({uid:1},(err,res)=>{
125 + if(err){
126 + console.log(err);
127 + }
128 + });
129 + }
112 }).catch((err) => { console.log(err.error) }) 130 }).catch((err) => { console.log(err.error) })
113 } 131 }
114 async function get_marketInfo() { 132 async function get_marketInfo() {
...@@ -256,8 +274,12 @@ app.listen(5000, async () => { ...@@ -256,8 +274,12 @@ app.listen(5000, async () => {
256 console.log('server start') 274 console.log('server start')
257 //coin 이름,가격,거래대금 저장 , DB 최신화 1시간마다 반복 275 //coin 이름,가격,거래대금 저장 , DB 최신화 1시간마다 반복
258 //5분마다 현재 가격 가져와서 db랑 비교후 매수 매도 기준잡기 276 //5분마다 현재 가격 가져와서 db랑 비교후 매수 매도 기준잡기
259 - var t1 = new Array(); 277 + // var t1 = new Array();
260 - test_data = await (latest_repeat(t1)); 278 + // test_data = await (latest_repeat(t1));
261 //계좌 정보 db 최신화 279 //계좌 정보 db 최신화
262 // console.log(await get_asset()); 280 // console.log(await get_asset());
281 + //매도
282 + await transaction_coin("KRW-BTC","ask","",null,"market");
283 + //매수
284 + // await transaction_coin("KRW-BTC", "bid", null, divided_money, "price");
263 }) 285 })
...\ No newline at end of file ...\ No newline at end of file
......