STEEM-ENGINE 마켓거래 정보 읽어들이기

in #zzan5 years ago

참조 : [steem-engine] 거래 정보 추출 - 작업 진행 내용 기록용 내용이 잘못된 부분이 많이 존재하기 때문에 본 내용을 참조 바랍니다.

조회 방법

  • 거래 정보 : 토큰명 + 계정명으로 조회
  • 상세 정보 : txid 기준으로 조회

데이터 구성

STEEMP 에서 정보를 조회하는 것은 정보량이 많기 떄문에 개별 토큰에서 조회한다. (상세정보 조회 시 시간이 너무 많이 걸림)

  • 구매등록, 구매등록취소, 구매완료, 판매완료 ( STEEMP )
  • 판매등록, 판매등록취소, 구매완료, 판매완료 ( 각토큰 )
  • 기타정보 : 유저간 토큰 발송, 토큰발행(issue)

구분

  • action : buy, flag : buy - 내가 사는 것, idx가 1이상만 존재
  • action : buy, flag : sell - N/A
  • action : sell, flag : buy - 남이 파는 것을 산 경우, idx가 1이상만 존재
  • action : sell, flag : sell - 내가 파는 것, idx가 0만 존재하며 내가 실제 판매에 성공한 정보(`하위 인덱스 모두를 탐색해야 됨``)를 로딩해야 됨에 유의

from_type, to_type

  • from_type, to_type - user:user, contract:user, user:contract
  • from_type, to_type - contract 인 경우 from 또는 to 값이 tokens 또는 market
  • tokens : 토큰 발행 issue 등의 정보가 담겨짐
  • market : 스팀엔진 마켓 거래 정보가 담겨짐 -> 해당 정보를 필터링 하여 정리

유의사항

  • 조회 시간이 많이 걸리므로 timeout 시간을 충분하게 늘려준다.
  • 위 사항이 힘든 경우 limit 값을 줄여 상세 정보 조회 시간을 줄여준다.
  • 버그인지 가끔 데이터 누락본이 있는데 이는 STEEMP에서 크로스 체크를 하면 되나 그러면 시간이 너무 많이 걸리므로 비추천함.(STEEMP에는 모든 토큰에 대한 정보를 포함하기 때문)

관련 소스코드 (발췌본)

대상 마켓 이력정보를 조회하기 위한 관련 소스코드를 발췌하여 게시 합니다.

/// market 이력 정보를 조회한다
async function init(author, symbol){

    // 전역 설정 값
    let datas;

    wlog.info(`STEP 0 (0/5) : start program ::: ${author}'s ${symbol} steem-engine market history.`);

    // 전체 목록정보 조회 
    wse
        .token_history(author, symbol)   // 토큰 거래 정보 조회
        .then(res=>{

            wlog.info(`STEP 1 (1/5) : token_history is loaded. (${res.length})`);

            // 매수, 매도 처리 정보의 txid 만 발췌하여 로딩
            let buy = res
                .filter(x=>x.from=='market'&&x.txid.indexOf('-')>0)
                .map(_market_data_update);  // buy 는 idx 가 다양하게 존재하는듯, 0은 없는 듯 ?!

            let sell = res
                .filter(x=>x.to=='market'&&x.txid.indexOf('-')>0)
                .map(_market_data_update);  // sell 은 idx 가 0 만 존재하는듯

            // 전송 데이터 
            datas = buy.concat(sell);

            // 유니크한 거래 TXID 정보 
            let txids = quique_strs(datas.map(x=>x.txid));

            wlog.info(`STEP 2 (2/5) : filtered search txids. (${txids.length})`);

            // 거래 정보 기준으로 전송
            let sends = [];
            for(let txid of txids){
                sends.push(wse.getTransactionInfo(txid));
            }

            return Promise.all(sends);
        })
        .then(res=>{

            wlog.info(`STEP 3 (3/5) : get detail transaction informations. (${res.length})`);

            let trans = [];
            for(let r of res){

                if(r.action == 'buy' && r.sender==author){          // flag : buy - 내가 사는 것
                    
                    _set_trans_data(trans, r, datas, author, symbol);

                }else if(r.action == 'buy' && r.sender!=author){    // flag : sell - N/A
                    
                    // 존재 불가의 데이터
                    wlog.error('sell - N/A', r);

                }else if(r.action == 'sell' && r.sender==author){   // flag : sell - 내가 파는 것
                    
                    _set_trans_data(trans, r, datas, author, 'STEEMP');

                }else if(r.action == 'sell' && r.sender!=author){   // flag : buy - 남이 파는것을 산 경우
                    
                    _set_trans_data(trans, r, datas, author, symbol);

                }else {
                    
                    // 존재 불가의 데이터 2
                    wlog.error('unknown data', r);
                }

            }// for(let r of res)

            wlog.info(`STEP 4 (4/5) : filtered detail transaction informations. (${trans.length})`);

            // 최신 순서로 정렬
            trans.sort((a,b)=>b.time-a.time);
            return Promise.resolve(trans);
        })
        .then(res=>{
            wlog.info(`STEP 5 (5/5) : prints results (${res.length})`);

            // 결과 출력 
            for(let r of res){
                let color = r.flag=='buy'?'red':'blue';

                // 로그 작성
                wlog[color](`[${r.flag.padEnd(4,' ')}][${r.timestamp}] ${r.who.padEnd(16,' ')} ${r.quantity.toString().padStart(10,' ')} ${symbol} x ${r.price.toString().padEnd(8,' ')} = ${r.sum.toString().padStart(12,' ')} STEEMP ( ${r.txid} )`);
            }
        });
}
init('wonsama', 'sct'.toUpperCase());
Sort:  

SCOT-API 사용하는게 어렵네요. ㅎㅎ

우찌 그리 잘 하는지...ㅎㅎ

스콧에서 다양한 API 제공해줘야 함에도...
스콧에서 기본인 API 제공해줌이 별루인...

Posted using Partiko Android

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.034
BTC 63578.68
ETH 3314.57
USDT 1.00
SBD 3.94