create account

sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록 by morning

View this thread on: hive.blogpeakd.comecency.com
· @morning · (edited)
$8.89
sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록
저번에 쓴 글 [SCT 리치리스트 등 스팀엔진 데이터 가져다 쓰기 개발 방법론 및 샘플코드](https://www.steemcoinpan.com/sct/@morning/6r2inf-sct) 에서 너무 주먹구구식으로 암중모색 하듯 짰는데

https://github.com/harpagon210/sscjs
공식 툴이 있어서 이번에 잘 이용해서 coin-on 업데이트를 했습니다.

근데 너무 README.md 설명이 부족해 보여서 샘플코드 위주로 보충해봅니다.


## API Endpoint URL

기트허브 readme에 보면 아래처럼 나와있던데
### In node.js

~~~
const SSC = require('sscjs');

const ssc = new SSC('https://testapi.steem-engine.com');
ssc.stream((err, res) => {
	console.log(err, res);
});
~~~

저렇게만 써놓으면 안되죠.
테스트용 Endpoint URL 만 써놓으면 프로덕션용 Endpoint 는 본능적인 감으로 찍어서 맞춰보란 소리인가?

~~~
const ssc = new SSC('https://api.steem-engine.com/rpc/');
~~~
이게 프로덕션 엔드포인트 입니다.
그 외에도 부실한 설명에 불만이 많았지만, 이정도로 자제하고 원래 쓰려던 내용에만 충실하게 써봅니다.

## 토큰 보유자 현황
~~~~
ssc.find(
	'tokens',  //contract name
	'balances', //table name
	{'symbol':'SCT'}, //query to perform on the table
	1000, //limit the number of records to retrieve
	0,  //offset applied to the records set
	[],  //array of index definitions { index: string, descending: boolean }
	(err, results) => { //callback
		console.log(err, results);
});

결과:
[ { account: 'sct',
    symbol: 'SCT',
    balance: '133.440',
    stake: '13662.827',
    delegatedStake: '0',
    receivedStake: '0',
    pendingUnstake: '0',
    '$loki': 34165 },
  ... 566 more items ]
~~~~
이렇게만 해도 결과는 성공적으로 나옵니다.
tokens 컨트랙(=namespace 개념인듯) 의 balances 테이블에서 
symbol 이 'SCT' 인 것들을 다 찾는 쿼리.

### stake 가 50000 이상인 것으로 걸러봅니다.
~~~~
ssc.find(
	'tokens',  //contract name
	'balances', //table name
	{'symbol':'SCT', 'stake': {$gte: 50000}}, //query to perform on the table
	1000, //limit the number of records to retrieve
	0,  //offset applied to the records set
	[],  //array of index definitions { index: string, descending: boolean }
	(err, results) => { //callback
		console.log(err, results);
});

결과:
[ { account: 'jack8831',
    symbol: 'SCT',
    balance: '114.959',
    stake: '87832.618',
    delegatedStake: '0',
    receivedStake: '0',
    pendingUnstake: '0',
    '$loki': 34205 },
  { account: 'ramires',
    symbol: 'SCT',
    balance: '0.000',
    stake: '104801.708',
    delegatedStake: '0',
    receivedStake: '0',
    pendingUnstake: '0',
    '$loki': 34497 },
  { account: 'kopasi',
    symbol: 'SCT',
    balance: '0.000',
    stake: '116838.158',
    delegatedStake: '0',
    receivedStake: '0',
    pendingUnstake: '0.000',
    '$loki': 34534 },
  { account: 'jjm13',
    symbol: 'SCT',
    balance: '335.935',
    stake: '58500.400',
    delegatedStake: '0',
    receivedStake: '0',
    pendingUnstake: '0',
    '$loki': 34607 } ]
~~~~

$gte 는 Greater Than or Equal to, 이상
$gt 는 Greater Than, 초과


### or 검색
stake 가 1 이상이거나
balance 가 1 이상이거나
pendingStake 가 1 이상인 결과물 찾기

~~~~
ssc.find(
	'tokens',  //contract name
	'balances', //table name
	{
		'symbol':'SCT', 
		'$or': [
			{'stake': {$gte: 1}}, 
			{'balance': {$gte: 1}},
			{'pendingUnstake': {$gte: 1}}
		]
	},
	1000, //limit the number of records to retrieve
	0,  //offset applied to the records set
	[],  //array of index definitions { index: string, descending: boolean }
	(err, results) => { //callback
		console.log(err, results);
});

~~~~

## 마켓 오더북
~~~~
ssc.find(
	'market',
	 'buyBook', 
	{'symbol': 'SCT'}, 
	200, 
	0, 
	[{'index': 'price', 'descending': true}],
	 (e, buyBook) => {
	for (var i = 0; i < buyBook.length;i++){
		var buy = buyBook[i];
		console.log(buy);
	}
});
ssc.find(
	'market', 
	'sellBook', 
	{'symbol': 'SCT'}, 
	200,
	0,
	[{'index': 'price', 'descending': false}], 
	(e, sellBook) => {
	for (var i = 0; i < sellBook.length;i++){
		var sell = sellBook[i];
		console.log(sell);
	}
});
~~~~

[{'index': 'price', 'descending': true}]
이런식으로 해서 price 순으로 정렬해줍니다.

## 거래 기록
~~~~
ssc.find(
	'market', 
	'tradesHistory', 
	{'symbol': 'SCT'}, 
	200, 
	0, 
	[{"index":"timestamp","descending":false}], 
	(err, results) => {
});
~~~~
timestamp 순으로 정렬해야 스팀엔진 마켓과 비슷한 결과가 나옵니다.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 36 others
properties (23)
authormorning
permlinksscjs-steem-engine-api
categorysct
json_metadata{"tags":["sct","kr-dev"],"links":["https://www.steemcoinpan.com/sct/@morning/6r2inf-sct","https://github.com/harpagon210/sscjs"],"app":"steemcoinpan/0.1","format":"markdown"}
created2019-06-15 15:14:21
last_update2019-06-15 15:19:36
depth0
children6
last_payout2019-06-22 15:14:21
cashout_time1969-12-31 23:59:59
total_payout_value6.926 HBD
curator_payout_value1.965 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,859
author_reputation120,327,679,023,535
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,681,486
net_rshares15,861,673,835,194
author_curate_reward""
vote details (100)
@bewarecenterbase ·
$0.08
개알못 이라 어렵지만,
(코딩 알못 하려했더니, 코인 알못과 헷깔려서,
개알못 개발 알못으로..
코인도 모르긴 하지만요..)

일단 뭔가 있는 것을 접수..
👍  
properties (23)
authorbewarecenterbase
permlinkre-morning-sscjs-steem-engine-api-20190616t035058910z
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan/0.1"}
created2019-06-16 03:51:00
last_update2019-06-16 03:51:00
depth1
children0
last_payout2019-06-23 03:51:00
cashout_time1969-12-31 23:59:59
total_payout_value0.058 HBD
curator_payout_value0.019 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length87
author_reputation-93,249,918,891,757
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,704,897
net_rshares132,465,539,859
author_curate_reward""
vote details (1)
@bluengel ·
수고 많으셨습니당~💙
감사합니다~💙

행복한 💙 오늘 보내셔용~*^^*

Posted using [Partiko Android](https://partiko.app/referral/bluengel)
properties (22)
authorbluengel
permlinkbluengel-re-morning-sscjs-steem-engine-api-20190617t010844514z
categorysct
json_metadata{"app":"partiko","client":"android"}
created2019-06-17 01:08:45
last_update2019-06-17 01:08:45
depth1
children0
last_payout2019-06-24 01:08:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length110
author_reputation129,269,571,273,945
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,748,927
net_rshares0
@honeybeerbear ·
포스팅 잘 보았습니다~! 많은 도움이 될것 같아요~~!!
또 궁금한게 sellBook, tradesHistory같이 테이블명이 따로 공개 된게 있나요?
properties (22)
authorhoneybeerbear
permlinkre-morning-sscjs-steem-engine-api-20190616t003203331z
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan/0.1"}
created2019-06-16 00:32:03
last_update2019-06-16 00:32:03
depth1
children2
last_payout2019-06-23 00:32:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length84
author_reputation43,415,437,983,715
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,700,970
net_rshares0
@morning · (edited)
$0.02
market 컨트랙에 metrics 테이블
tokens 컨트랙에 contractsBalances, pendingUnstakes 테이블 
있네요
👍  
properties (23)
authormorning
permlinkre-honeybeerbear-re-morning-sscjs-steem-engine-api-20190616t153829202z
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan/0.1"}
created2019-06-16 15:38:30
last_update2019-06-16 15:38:48
depth2
children1
last_payout2019-06-23 15:38:30
cashout_time1969-12-31 23:59:59
total_payout_value0.015 HBD
curator_payout_value0.005 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length79
author_reputation120,327,679,023,535
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,729,386
net_rshares36,837,293,057
author_curate_reward""
vote details (1)
@honeybeerbear ·
답변 감사드립니다~~
properties (22)
authorhoneybeerbear
permlinkre-morning-re-honeybeerbear-re-morning-sscjs-steem-engine-api-20190617t084949882z
categorysct
json_metadata{"tags":["sct"],"app":"steempeak/1.11.1"}
created2019-06-17 08:49:48
last_update2019-06-17 08:49:48
depth3
children0
last_payout2019-06-24 08:49:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length11
author_reputation43,415,437,983,715
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,769,253
net_rshares0
@lovelyyeon.sct ·
코딩을 봐도 어떻게 해야하는지 모르겠지만 T.T 결과물들 감사히 잘쓰고 있습니다. 편안한 휴일되세요~
properties (22)
authorlovelyyeon.sct
permlinkre-morning-sscjs-steem-engine-api-20190615t192015881z
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan/0.1"}
created2019-06-15 19:20:30
last_update2019-06-15 19:20:30
depth1
children0
last_payout2019-06-22 19:20:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length56
author_reputation371,686,959,467,496
root_title"sscjs 를 이용한 steem-engine API 샘플코드 - 토큰 보유자 현황(리치리스트), 마켓 오더북, 거래기록"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,691,243
net_rshares0