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

View this thread on steempeak.com
· @wonsama ·
$1.44
STEEM-ENGINE 마켓거래 정보 읽어들이기
![](https://cdn.steemitimages.com/DQmVr5PmAw3krYQAJN1BsyCdWy94BjUjm47x3ZuDky2619a/image.png)

> 참조 : [[steem-engine] 거래 정보 추출 - 작업 진행 내용 기록용](https://steemit.com/zzan/@wonsama/ofmmm-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에는 모든 토큰에 대한 정보를 포함하기 때문)   

# 관련 소스코드 (발췌본)

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

```javascript
/// 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());
```
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 91 others
properties (23)
post_id79,371,300
authorwonsama
permlink5x8j9p-steem-engine
categoryzzan
json_metadata{"tags":["zzan","sct","sct-freeboard","sct-kr","kr-dev"],"image":["https:\/\/cdn.steemitimages.com\/DQmVr5PmAw3krYQAJN1BsyCdWy94BjUjm47x3ZuDky2619a\/image.png"],"links":["https:\/\/steemit.com\/zzan\/@wonsama\/ofmmm-steem-engine"],"app":"steemit\/0.1","format":"markdown"}
created2019-08-23 19:43:51
last_update2019-08-23 19:43:51
depth0
children3
net_rshares5,495,389,426,502
last_payout2019-08-30 19:43:51
cashout_time1969-12-31 23:59:59
total_payout_value0.750 SBD
curator_payout_value0.694 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4,388
author_reputation962,350,626,398,086
root_title"STEEM-ENGINE 마켓거래 정보 읽어들이기"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (155)
@anpigon ·
SCOT-API 사용하는게 어렵네요. ㅎㅎ
properties (22)
post_id79,378,110
authoranpigon
permlinkpwpvgc
categoryzzan
json_metadata{"tags":["zzan"],"app":"steemzzang\/0.1"}
created2019-08-24 01:14:51
last_update2019-08-24 01:14:51
depth1
children0
net_rshares0
last_payout2019-08-31 01:14:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length23
author_reputation106,878,140,422,651
root_title"STEEM-ENGINE 마켓거래 정보 읽어들이기"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@tailcock ·
우찌 그리 잘 하는지...ㅎㅎ
properties (22)
post_id79,386,778
authortailcock
permlinkpwqhxx
categoryzzan
json_metadata{"tags":["zzan"],"app":"steemit\/0.1"}
created2019-08-24 09:20:24
last_update2019-08-24 09:20:24
depth1
children0
net_rshares0
last_payout2019-08-31 09:20:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length16
author_reputation238,658,978,685,858
root_title"STEEM-ENGINE 마켓거래 정보 읽어들이기"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@bluengel ·
스콧에서 다양한 API 제공해줘야 함에도... 
스콧에서 기본인 API 제공해줌이 별루인...

Posted using [Partiko Android](https://partiko.app/referral/bluengel)
properties (22)
post_id79,409,764
authorbluengel
permlinkbluengel-re-wonsama-5x8j9p-steem-engine-20190825t023121810z
categoryzzan
json_metadata{"app":"partiko","client":"android"}
created2019-08-25 02:31:21
last_update2019-08-25 02:31:21
depth1
children0
net_rshares0
last_payout2019-09-01 02:31:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length123
author_reputation487,279,092,618,993
root_title"STEEM-ENGINE 마켓거래 정보 읽어들이기"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000