Serum
Serum adalah protokol untuk pertukaran terdesentralisasi yang dibangun di atas Solana. Anda dapat menggunakan Serum untuk menciptakan pasar baru (new market), mendapatkan buku pesanan (orderbooks), berdagang (trades), dan banyak lagi.
Cara Mendapatkan Serum Market
Market di Serum berisi semua pesanan dan kemampuan untuk membuat pesanan pada Serum. Untuk semua yang Anda lakukan di Serum, Anda perlu mengetahui market yang Anda sedang kerjakan.
import { Connection, PublicKey } from "@solana/web3.js";
import { Market } from "@project-serum/serum";
(async () => {
const marketAddress = new PublicKey(
"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT"
);
const programAddress = new PublicKey(
"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
);
const connection = new Connection(
"https://ssc-dao.genesysgo.net",
"confirmed"
);
const market = await Market.load(
connection,
marketAddress,
{},
programAddress
);
})();
const market = await Market.load(connection, marketAddress, {}, programAddress);
Mendapatkan Serum Order Books
Serum markets terdiri dari orderbooks yang memiliki bids dan asks. Anda bisa menanyakan informasi ini sehingga Anda dapat melihat apa yang terjadi di pasar dan bertindak sesuai yang Anda butuhkan
import { Connection, PublicKey } from "@solana/web3.js";
import { Market } from "@project-serum/serum";
(async () => {
let marketAddress = new PublicKey(
"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT"
);
let programAddress = new PublicKey(
"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
);
let connection = new Connection("https://ssc-dao.genesysgo.net", "confirmed");
let market = await Market.load(connection, marketAddress, {}, programAddress);
let bids = await market.loadBids(connection);
for (let [price, size] of bids.getL2(20)) {
console.log(price, size);
}
let asks = await market.loadAsks(connection);
for (let [price, size] of asks.getL2(20)) {
console.log(price, size);
}
})();
let bids = await market.loadBids(connection);
for (let [price, size] of bids.getL2(20)) {
console.log(price, size);
}
let asks = await market.loadAsks(connection);
for (let [price, size] of asks.getL2(20)) {
console.log(price, size);
}
Cara Mendapatkan Open Orders
Sebagai seorang trader, Anda pasti ingin tahu Open Orders aktif apa yang Anda miliki saat ini di sebuah market. Anda dapat menanyakan Open Orders Anda atau orang lain di market dengan Serum.
import { Connection, PublicKey } from "@solana/web3.js";
import { Market } from "@project-serum/serum";
(async () => {
let trader = new PublicKey("CuieVDEDtLo7FypA9SbLM9saXFdb1dsshEkyErMqkRQq");
let marketAddress = new PublicKey(
"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT"
);
let programAddress = new PublicKey(
"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
);
let connection = new Connection("https://ssc-dao.genesysgo.net", "confirmed");
let market = await Market.load(connection, marketAddress, {}, programAddress);
const orders = await market.loadOrdersForOwner(connection, trader);
for (let order of orders) {
console.log(order);
}
})();
const orders = await market.loadOrdersForOwner(connection, traderPublicKey);