1.0.23 • Published 2 years ago
terramarkets.js v1.0.23
TerraMarkets SDK
Usage
Initialize api, receive information about available symbols and subscribe to real-time market events
import { TerraMarketsApi } from 'terramarkets.js';
// Initialize api
const api = new TerraMarketsApi("mainnet"); // or "testnet"
// Get available symbols and contract addresses
const symbolsInfo = await api.getSymbols();
// Initialize hub connection: neccessary for receive real-time market updates
const hubConnection = await api.startHubConnection();
// Set market updates callback
hubConnection.on("onMarketUpdate", (marketUpdate: MarketUpdate) => {
// Handle market update - do something ...
});
// Handle connection lost and reconnect
hubConnection.onreconnected(async () => {
// Resubscribe to symbol
await api.subscribe(symbolsInfo[0].symbol);
});
// Subscribe to symbol
await api.subscribe(symbolsInfo[0].symbol);
// Get current market state
const marketState = await api.getMarketState(symbolsInfo[0].symbol);
// Close connection on app end
await api.closeHubConnection();
Interacting with TerraMarkets smart contract
import { LCDClient, MnemonicKey, Wallet } from '@terra-money/terra.js';
import { TerraMarketsContract } from 'terramarkets.js';
// Create LCD client and wallet
const lcdClient = new LCDClient({
URL: 'https://bombay-lcd.terra.dev',
chainID: 'bombay-12',
});
const wallet = new Wallet(lcdClient, new MnemonicKey({
mnemonic: process.env.MNEMONIC,
}));
// Initialize TerraMarketsContract
const contract = new TerraMarketsContract(contractAddress); // Contract addresses are returned by api.getSymbols();
// Query market
const market = await contract.queryMarket(wallet);
// Pleace bet (for 15 UST up)
if (market.status === MarketStatus.Open) {
await contract.executeBet(wallet, market.open_round_id, "15000000", BetDirection.Up);
}
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.22
2 years ago
1.0.11
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.23
2 years ago
1.0.12
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago