Creating a Market
Creating a market is permissionless, so that anyone can create a new market using the Rust CLI or the JS library.
Make sure to crank the markets you create otherwise they may fail to function ⚠️
In order to create a market you will need:
  • The Pyth oracle symbol of the market
  • The initial amount of virtual quote currency you want for the market

Using the JS library

Example for BTC/USD
1
const connection = new Connection(ENDPOINT, "confirmed");
2
const secretKey = fs.readFileSync("...").toString();
3
const admin = Keypair.fromSecretKey(Buffer.from(JSON.parse(secretKey)));
4
// Mint of the
5
const mint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); // USDC Mint
6
const initial_v_pc_amount = 976040125199; // This is an example, use something different
7
8
let [signers, instructions] = await createMarket(
9
connection,
10
admin.publicKey,
11
admin.publicKey,
12
"BTC/USD",
13
mint,
14
6,
15
new Numberu64(initial_v_pc_amount)
16
);
17
let marketAddress = signers[0].publicKey;
18
19
console.log(
20
await signAndSendTransactionInstructions(
21
connection,
22
signers,
23
admin,
24
instructions
25
)
26
);
27
console.log("Created market at ", marketAddress.toBase58());
28
29
// Wait for propagation
30
await sleep(5_000);
31
32
[signers, instructions] = await addInstance(
33
connection,
34
marketAddress,
35
admin.publicKey,
36
admin.publicKey,
37
3,
38
50
39
);
40
41
signers.push(admin);
42
43
console.log(
44
await signAndSendTransactionInstructions(
45
connection,
46
signers,
47
admin,
48
instructions
49
)
50
);
51
52
// Wait for propagation
53
await sleep(5_000);
54
55
[signers, instructions] = await addInstance(
56
connection,
57
marketAddress,
58
admin.publicKey,
59
admin.publicKey,
60
3,
61
50
62
);
63
64
signers.push(admin);
65
66
console.log(
67
await signAndSendTransactionInstructions(
68
connection,
69
signers,
70
admin,
71
instructions
72
)
73
);
Copied!

Using the Rust CLI

Last modified 3mo ago