Skip to content

Commit 9206c40

Browse files
authored
Merge pull request #4 from quiknode-labs/add-slippage-parameter-for-users
slippage changes
2 parents de5799a + 7e8b974 commit 9206c40

6 files changed

Lines changed: 21 additions & 3 deletions

File tree

python/close_position.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
print(f"Closing {COIN} position for {address}\n")
99

10+
# Optional: custom slippage (default 3%, range 0.1%-10%)
11+
# res = exchange({"action": {...}, "slippage": 0.05}) # 5% slippage
12+
1013
res = exchange({
1114
"action": {
1215
"type": "closePosition",

python/market_order.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
print(f"Market BUY {SIZE} {COIN}\n")
1010

11+
# Optional: custom slippage (default 3%, range 0.1%-10%)
12+
# res = exchange({"action": {...}, "slippage": 0.05}) # 5% slippage
13+
1114
res = exchange({
1215
"action": {
1316
"type": "order",
@@ -21,7 +24,7 @@
2124
})
2225

2326
computed_price = res["action"]["orders"][0]["p"]
24-
print(f"Computed price (mid + 3% slippage): {computed_price}")
27+
print(f"Computed price (mid + slippage, default 3%): {computed_price}")
2528
print(f"Builder fee: {res['builderFee']}")
2629

2730
sig = sign_hash(res["hash"])

rust/examples/close_position.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ async fn main() {
99

1010
println!("Closing {COIN} position for {}\n", client.address);
1111

12+
// Optional: custom slippage (default 3%, range 0.1%-10%)
13+
// .exchange(&json!({"action": {...}, "slippage": 0.05})) // 5% slippage
14+
1215
let res = client
1316
.exchange(&json!({
1417
"action": {

rust/examples/market_order.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ async fn main() {
1010

1111
println!("Market BUY {SIZE} {COIN}\n");
1212

13+
// Optional: custom slippage (default 3%, range 0.1%-10%)
14+
// .exchange(&json!({"action": {...}, "slippage": 0.05})) // 5% slippage
15+
1316
let res = client
1417
.exchange(&json!({
1518
"action": {
@@ -20,7 +23,7 @@ async fn main() {
2023
.await;
2124

2225
let computed_price = res["action"]["orders"][0]["p"].as_str().unwrap_or("?");
23-
println!("Computed price (mid + 3% slippage): {computed_price}");
26+
println!("Computed price (mid + slippage, default 3%): {computed_price}");
2427
println!("Builder fee: {}", res["builderFee"]);
2528

2629
let hash = res["hash"].as_str().unwrap();

typescript/src/closePosition.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const COIN = "HYPE";
55
async function main() {
66
console.log(`Closing ${COIN} position for ${address}\n`);
77

8+
// Optional: custom slippage (default 3%, range 0.1%-10%)
9+
// const res = await exchange({ action: {...}, slippage: 0.05 }); // 5% slippage
10+
811
const res = await exchange({
912
action: {
1013
type: "closePosition",

typescript/src/marketOrder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const SIZE = "0.00011";
66
async function main() {
77
console.log(`Market BUY ${SIZE} ${COIN}\n`);
88

9+
// Optional: custom slippage (default 3%, range 0.1%-10%)
10+
// const res = await exchange({ action: {...}, slippage: 0.05 }); // 5% slippage
11+
912
const res = await exchange({
1013
action: {
1114
type: "order",
@@ -14,7 +17,7 @@ async function main() {
1417
});
1518

1619
const computedPrice = res.action.orders[0].p;
17-
console.log(`Computed price (mid + 3% slippage): ${computedPrice}`);
20+
console.log(`Computed price (mid + slippage, default 3%): ${computedPrice}`);
1821
console.log(`Builder fee: ${res.builderFee}`);
1922

2023
const sig = await signHash(res.hash);

0 commit comments

Comments
 (0)