Trade Programmatically
Auto rebalance at low spread and increase your profits.
1
2
import { createPublicClient, createWalletClient, http, Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { TurbineClient, OrderIntent, getRandomSalt, spreads } from "turbine-sdk";
const account = privateKeyToAccount(PRIVATE_KEY);
const walletClient = createWalletClient({
account: account,
chain: mainnet,
transport: http(RPC_URL),
});
const publicClient = createPublicClient({
chain: mainnet,
transport: http(RPC_URL),
});
const turbineClient = await TurbineClient.create(
walletClient,
publicClient,
TURBINE_API_URL
);3
4
const now = BigInt(Math.floor(Date.now() / 1000));
const orderIntent: OrderIntent = {
owner: account.address,
sellToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
buyToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
sellAmount: 30n * 10n ** 6n, // 30 USDC in atomic units
minBuyAmount: 7n * 10n ** 15n, // 0.007 WETH in atomic units
spreadCurve: spreads.constant(100), // 1%
startTime: now,
endTime: now + 300n, // 300 seconds = 5 minutes
partialFill: true, // only partially fillable orders are supported
callData: "0x",
callDataTarget: "0x0000000000000000000000000000000000000000",
salt: getRandomSalt(),
};5
const orderHash = await turbineClient.addOrder(orderIntent);6
const orderState = (await turbineClient.getOrderStates([orderHash]))[0];
console.log(orderState.status);Last updated
Was this helpful?