Rust Bot SDK
Bot traders interact with the CrypDefi backend via API calls. To simplify authentication and transaction signing, the Bot SDK can be used instead of manually managing individual API requests.
This rust library is also used for making bindings in the Go and Python languages.
Create keys for the Bot login.
Generate Bot's private key.
Generate Bot's Public key
Examples
// --------------------------- CONFIG ---------------------------
// Replace with one of your bot's wallet_id.
const user_id = "us-0000000000-691dc9136b45c44f621f";
// Replace with the wallet_id of the wallet you want to trade with.
const wallet_id = "wa-0000000000-93cbea463ddfa0afc3a3";
// This is the bot's private key used to authenticate with CrypDefi (not the wallet's private key).
const private_key_pem: &str = "-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgT/x59Xqj/UnxmiO0
VfdMlG3IA6EhXb0a3TePDvWw6RqhRANCAAQfPDagIdi3luh8HaOBihcKqgaCsYsU
6hpCDdXZruL5+EnOhscqQQqRhJ0zIeCeIBR6oTHOFhVVkzE6Dw9JeArx
-----END PRIVATE KEY-----";
// NOTE: If you want to change the backend endpoint you will need to set the env variable: CRYPDEFI_BASE_URL
// --------------------------- INIT BOT ---------------------------
println!;
let bot = new.unwrap;
// --------------------------- LOGIN WITH BOT ---------------------------
println!;
// if you turn off auto_refresh the bot will not automaticately authentificate when the token is about to expire
bot.login.unwrap;
// --------------------------- Check for expiration time of AUTH ---------------------------
let expiration = bot.auth_expiration_unix_time;
println!;
// --------------------------- FETCH ASSOCIATED WALLETS ---------------------------
println!;
let wallets = bot.get_wallets.unwrap;
println!;
// --------------------------- CREATE & SIGN TRANSACTION ---------------------------
println!;
// Include steps to create transaction here. Replace example_evm_hex below with the actual hex string of the transaction to sign.
let example_evm_hex = "02f8af01018390f560850461933067828cb394a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4880b844095ea7b300000000000000000000000097802f38a37e1d789eba194513e3eb7e918d34df000000000000000000000000000000000000000000000000000000001dcd6500c001a0ad0b4a87309ef94b96d38f145d676d971ca1f1e4702c9cace99fdec8df4a8814a008651a171f31629bcf3a686ca26b9d3cece44c6dfec39fb2c1848e3b290ba121";
println!;
// Sign the transaction using the wallet that was configured. Make sure the bot has access to this wallet in the Management UI.
let signature = bot.sign_transaction.unwrap;
println!;
// --------------------------- REFRESH SESSION ---------------------------
println!;
let result = bot.refresh.unwrap;
println!;
// --------------------------- LOGOUT ---------------------------
let result = bot.logout.unwrap;
println!;
DEVELOPMENT
This are commands and tools for developers of the SDK.
build python
Run:
build GO and C
Run:
run example bot
This runs a very simple main function with the basic functionality of the SDK