Skip to content

Commit

Permalink
added examples on how to read some data about tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam committed Feb 21, 2024
1 parent 1fdfb9b commit c0db2dc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/docs/how-to/token/trade-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ import TabItem from '@theme/TabItem';
```
</TabItem>
</Tabs>

Get executed trades:

```tsx file=../../../../packages/sdk/examples/token/https/trade.ts#L49-L69
```
34 changes: 33 additions & 1 deletion packages/sdk/examples/token/https/trade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dataset, Network } from '@build-5/interfaces';
import { Dataset, Network, TokenTradeOrderStatus, TokenTradeOrderType } from '@build-5/interfaces';
import { Build5, SoonaverseApiKey, https } from '@build-5/sdk';
import { address } from '../../utils/secret';
import { walletSign } from '../../utils/utils';
Expand Down Expand Up @@ -42,3 +42,35 @@ async function main() {
}

main().then(() => process.exit());
mainRead().then(() => process.exit());

// Other examples
async function mainRead() {
// Get all active BUYs through live stream. Use getMemberBidsLive to get member's one.
const tokenId = 'tokenId';
await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.TOKEN_MARKET)
.getBidsLive(tokenId, TokenTradeOrderType.BUY, TokenTradeOrderStatus.ACTIVE)
.subscribe((bids) => {
console.log(bids);
});

// Get all active SELLs through live stream. Use getMemberBidsLive to get member's one.
await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.TOKEN_MARKET)
.getBidsLive(tokenId, TokenTradeOrderType.SELL, TokenTradeOrderStatus.ACTIVE)
.subscribe((bids) => {
console.log(bids);
});

// Get live stream of token purchases
await https(origin)
.project(SoonaverseApiKey[origin])
.dataset(Dataset.TOKEN_PURCHASE)
.getPuchasesLive(tokenId)
.subscribe((bids) => {
console.log(bids);
});
}

0 comments on commit c0db2dc

Please sign in to comment.