pub struct TransactionSigner { /* private fields */ }Expand description
Ed25519 signer for Bulk exchange transactions.
§Example
let signer = TransactionSigner::from_private_key("base58_key")?;
let mut tx = Transaction { .. };
tx.sign(&signer)?;Implementations§
Source§impl TransactionSigner
impl TransactionSigner
Sourcepub fn from_private_key(key_b58: &str) -> Result<Self>
pub fn from_private_key(key_b58: &str) -> Result<Self>
Create a signer from a base58-encoded private key (32-byte seed).
§Arguments
private_key: 32 or 64 byte private key
Examples found in repository?
examples/execute_cond.rs (line 41)
30async fn main() -> eyre::Result<()> {
31 tracing_subscriber::fmt()
32 .with_env_filter(
33 EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())
34 )
35 .init();
36
37 let args = Args::parse();
38
39 info!("Connecting to {} for execution", args.url);
40 let key = env::var("BULK_PRIVATE_KEY")?;
41 let signer = TransactionSigner::from_private_key(key.as_str())?;
42 let client = BulkHttpClient::new(&HttpConfig {
43 base_url: args.url,
44 signer: Some(signer.clone()),
45 ..Default::default()
46 }).unwrap();
47
48 let account = if false {
49 Pubkey::from_str("8oqBACkDvyJjBoiWNbZPXrnjZvFjzUjMThbi9oahAVvH")?
50 } else {
51 signer.public_key()
52 };
53 let nonce = 1776682154418;
54
55 let orders = vec![
56 Action::TakeProfit(StopOrTP {
57 symbol: Arc::from("BTC-USD"),
58 is_above: false,
59 size: 0.480894,
60 threshold: 40000.0,
61 limit: None,
62 meta: ActionMeta {
63 account,
64 nonce,
65 seqno: 0,
66 hash: None,
67 }
68 }),
69 ];
70
71 let results = client.place_tx(orders, Some(account), Some(nonce)).await?;
72 eprintln!("results: {:?}\n", results);
73
74 process::exit(0);
75}More examples
examples/execute_limit.rs (line 41)
30async fn main() -> eyre::Result<()> {
31 tracing_subscriber::fmt()
32 .with_env_filter(
33 EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())
34 )
35 .init();
36
37 let args = Args::parse();
38
39 info!("Connecting to {} for execution", args.url);
40 let key = env::var("BULK_PRIVATE_KEY")?;
41 let signer = TransactionSigner::from_private_key(key.as_str())?;
42 let client = BulkHttpClient::new(&HttpConfig {
43 base_url: args.url,
44 signer: Some(signer.clone()),
45 ..Default::default()
46 }).unwrap();
47
48 let account = signer.public_key();
49 let nonce = make_nonce();
50
51 let mut orders = vec![
52 Action::LimitOrder(LimitOrder {
53 symbol: Arc::from("BTC-USD"),
54 is_buy: true,
55 price: 1000.0,
56 size: 0.0001,
57 tif: TimeInForce::IOC,
58 reduce_only: false,
59 iso: false,
60 meta: ActionMeta {
61 account,
62 nonce,
63 seqno: 0,
64 hash: None,
65 }
66 }),
67 Action::LimitOrder(LimitOrder {
68 symbol: Arc::from("ETH-USD"),
69 is_buy: true,
70 price: 1000.0,
71 size: 0.0001,
72 tif: TimeInForce::IOC,
73 reduce_only: false,
74 iso: false,
75 meta: ActionMeta {
76 account,
77 nonce,
78 seqno: 1,
79 hash: None,
80 }
81 }),
82 ];
83
84 let oids = orders.iter_mut()
85 .map(|o| o.hash().to_string())
86 .collect::<Vec<_>>();
87
88 eprintln!("order IDs: {:?}", oids);
89
90 let results = client.place_tx(orders, Some(account), Some(nonce)).await?;
91 eprintln!("results: {:?}\n", results);
92
93 process::exit(0);
94}Sourcepub fn sign_bytes(&self, message: &[u8]) -> Result<Signature>
pub fn sign_bytes(&self, message: &[u8]) -> Result<Signature>
Sign an arbitrary byte slice and return the raw 64-byte signature.
Used by [BulkHttpClient] for generic (non-Signable) payloads
such as leverage updates, agent wallet management, and faucet requests,
where the exchange expects a signature over the canonical JSON string.
pub fn sign_transaction_bytes(&self, message: &[u8]) -> Result<Signature>
pub fn sign_transaction_clear(&self, clear_text: &str) -> Result<Signature>
pub fn tx_signature_mode(&self) -> TxSignatureMode
pub fn tx_signature_mode_hint_header_value(&self) -> Option<&'static str>
Sourcepub fn public_key(&self) -> Pubkey
pub fn public_key(&self) -> Pubkey
Get pubkey
Examples found in repository?
examples/execute_cond.rs (line 51)
30async fn main() -> eyre::Result<()> {
31 tracing_subscriber::fmt()
32 .with_env_filter(
33 EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())
34 )
35 .init();
36
37 let args = Args::parse();
38
39 info!("Connecting to {} for execution", args.url);
40 let key = env::var("BULK_PRIVATE_KEY")?;
41 let signer = TransactionSigner::from_private_key(key.as_str())?;
42 let client = BulkHttpClient::new(&HttpConfig {
43 base_url: args.url,
44 signer: Some(signer.clone()),
45 ..Default::default()
46 }).unwrap();
47
48 let account = if false {
49 Pubkey::from_str("8oqBACkDvyJjBoiWNbZPXrnjZvFjzUjMThbi9oahAVvH")?
50 } else {
51 signer.public_key()
52 };
53 let nonce = 1776682154418;
54
55 let orders = vec![
56 Action::TakeProfit(StopOrTP {
57 symbol: Arc::from("BTC-USD"),
58 is_above: false,
59 size: 0.480894,
60 threshold: 40000.0,
61 limit: None,
62 meta: ActionMeta {
63 account,
64 nonce,
65 seqno: 0,
66 hash: None,
67 }
68 }),
69 ];
70
71 let results = client.place_tx(orders, Some(account), Some(nonce)).await?;
72 eprintln!("results: {:?}\n", results);
73
74 process::exit(0);
75}More examples
examples/execute_limit.rs (line 48)
30async fn main() -> eyre::Result<()> {
31 tracing_subscriber::fmt()
32 .with_env_filter(
33 EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())
34 )
35 .init();
36
37 let args = Args::parse();
38
39 info!("Connecting to {} for execution", args.url);
40 let key = env::var("BULK_PRIVATE_KEY")?;
41 let signer = TransactionSigner::from_private_key(key.as_str())?;
42 let client = BulkHttpClient::new(&HttpConfig {
43 base_url: args.url,
44 signer: Some(signer.clone()),
45 ..Default::default()
46 }).unwrap();
47
48 let account = signer.public_key();
49 let nonce = make_nonce();
50
51 let mut orders = vec![
52 Action::LimitOrder(LimitOrder {
53 symbol: Arc::from("BTC-USD"),
54 is_buy: true,
55 price: 1000.0,
56 size: 0.0001,
57 tif: TimeInForce::IOC,
58 reduce_only: false,
59 iso: false,
60 meta: ActionMeta {
61 account,
62 nonce,
63 seqno: 0,
64 hash: None,
65 }
66 }),
67 Action::LimitOrder(LimitOrder {
68 symbol: Arc::from("ETH-USD"),
69 is_buy: true,
70 price: 1000.0,
71 size: 0.0001,
72 tif: TimeInForce::IOC,
73 reduce_only: false,
74 iso: false,
75 meta: ActionMeta {
76 account,
77 nonce,
78 seqno: 1,
79 hash: None,
80 }
81 }),
82 ];
83
84 let oids = orders.iter_mut()
85 .map(|o| o.hash().to_string())
86 .collect::<Vec<_>>();
87
88 eprintln!("order IDs: {:?}", oids);
89
90 let results = client.place_tx(orders, Some(account), Some(nonce)).await?;
91 eprintln!("results: {:?}\n", results);
92
93 process::exit(0);
94}Sourcepub fn public_key_b58(&self) -> String
pub fn public_key_b58(&self) -> String
Get pubkey as b58 encoding
Trait Implementations§
Source§impl Clone for TransactionSigner
impl Clone for TransactionSigner
Auto Trait Implementations§
impl Freeze for TransactionSigner
impl RefUnwindSafe for TransactionSigner
impl Send for TransactionSigner
impl Sync for TransactionSigner
impl Unpin for TransactionSigner
impl UnsafeUnpin for TransactionSigner
impl UnwindSafe for TransactionSigner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more