{"format":"opendoc-document","version":1,"url":"https://docs.storm.tg/developers/sdk_go","title":"🐹 Go SDK","description":"github.com/storm trade/sdk go covers both trading paths. The storm package drives v3 : it builds and signs intents, submits them to the sequencer, and manages…","kind":"article","locale":"en","inLanguage":"en","lastModified":"2026-10-09T14:26:32+03:00","revision":"d36475e7b456c737fae6933fa27b7e1bc2687f2c19291b05725ab2c4e8f79d7a","section":{"title":"For Developers","url":"https://docs.storm.tg/developers"},"representations":{"html":"https://docs.storm.tg/developers/sdk_go","markdown":"https://docs.storm.tg/developers/sdk_go.md","json":"https://docs.storm.tg/developers/sdk_go.json"},"translations":{"en":"https://docs.storm.tg/developers/sdk_go"},"breadcrumbs":[{"title":"⚡ About Storm Trade","url":"https://docs.storm.tg"},{"title":"For Developers","url":"https://docs.storm.tg/developers"},{"title":"🐹 Go SDK","url":"https://docs.storm.tg/developers/sdk_go"}],"headings":[{"depth":2,"id":"v3-smart-account-and-intents","title":"⚡ v3: Smart Account and Intents"},{"depth":3,"id":"set-up","title":"Set up"},{"depth":3,"id":"first-deposit","title":"First deposit"},{"depth":3,"id":"orders","title":"Orders"},{"depth":3,"id":"positions","title":"Positions"},{"depth":3,"id":"options-worth-knowing","title":"Options worth knowing"},{"depth":3,"id":"reading-state","title":"Reading state"},{"depth":2,"id":"v2-direct-wallet-transactions","title":"🔁 v2: Direct Wallet Transactions"},{"depth":2,"id":"cli","title":"🧪 CLI"}],"markdown":"# 🐹 Go SDK\n\n`github.com/storm-trade/sdk-go` covers both trading paths. The `storm` package drives **v3**: it builds and signs intents, submits them to the sequencer, and manages Smart Account deposits and withdrawals. The `stormv2` package drives **v2** with direct wallet transactions and appends the executor fee automatically.\n\n- Source: [storm-trade/sdk-go](https://github.com/storm-trade/sdk-go)\n- CLI examples: `cmd/example` for v3, `cmd/v2example` for v2\n\n```bash\ngo get github.com/storm-trade/sdk-go\n```\n\n| Package | Purpose |\n| --- | --- |\n| `config` | Networks, markets, assets, `Direction` |\n| `storm` | v3 client: Smart Account plus sequencer |\n| `stormv2` | v2 client: direct wallet transactions |\n| `sequencer` | Trading API (V3) REST client |\n| `oracle` | Signed oracle prices, used by v2 margin operations |\n| `client/vamm`, `client/vault`, `client/smartaccount`, `client/positionmanager` | On-chain reads and Smart Account operations |\n| `tlb`, `contracts` | Order types, position state, error codes, TL-B schemas |\n\n---\n\n## ⚡ v3: Smart Account and Intents\n\n### Set up\n\n```go\nctx := context.Background()\n\npool := liteclient.NewConnectionPool()\npool.AddConnectionsFromConfigUrl(ctx, \"https://ton-blockchain.github.io/testnet-global.config.json\")\napi := ton.NewAPIClient(pool, ton.ProofCheckPolicyUnsafe).WithRetry(10)\n\nw, _ := wallet.FromSeed(api, strings.Split(seedPhrase, \" \"), wallet.V4R2)\n\nfactory := smartaccount.NewFactory(api, address.MustParseAddr(config.Networks[config.Testnet].FactoryAddress))\nsaAddr, _ := factory.GetSmartAccountAddress(ctx, w.WalletAddress())\n\nclient := storm.NewClient(config.Testnet,\n    storm.WithTONApi(api),\n    storm.WithWallet(w),\n    storm.WithSmartAccount(saAddr),\n    storm.WithSigner(ed25519.PrivateKey(signingKey)),\n    storm.WithClockSkew(5*time.Second),\n)\n```\n\nThe signing key is an ED25519 key registered on the Smart Account. It is separate from the TON wallet key: the wallet pays for deposits and withdrawals, the signing key authorizes intents.\n\n### First deposit\n\nThe first deposit deploys the Smart Account and registers the signing key in one go. Amounts use the asset's own decimals.\n\n```go\namount := tlb.MustFromDecimal(\"100\", 6) // 100 USDT\nclient.Deposit(ctx, \"USDT\", &amount, storm.WithInit(), storm.WithPublicKey(pubKey))\n\n// later\nclient.Deposit(ctx, \"USDT\", &amount)\nclient.Withdraw(ctx, \"USDT\", &amount)\n```\n\nPassing a public key without `WithInit()` on an existing account fails with contract error 115. Use `client.AddPublicKey(ctx)` to register an extra key later.\n\n### Orders\n\nOrder amounts and sizes use 9 decimals, leverage is scaled by 10^9.\n\n```go\nbtc, _ := client.Market(\"BTC\", \"USDT\")\namount := tlb.MustFromDecimal(\"100\", 9)\n\n// Market order with SL/TP attached as extra intents\nsl := tlb.MustFromTON(\"60000\")\ntp := tlb.MustFromTON(\"80000\")\nres, err := client.PlaceMarketOrder(ctx, btc, config.Long, &amount, 3_000_000_000,\n    storm.WithStopLoss(&sl), storm.WithTakeProfit(&tp))\n\n// Limit and stop-limit\nlimit := tlb.MustFromTON(\"65000\")\nres, _ = client.PlaceLimitOrder(ctx, btc, config.Long, &amount, 3_000_000_000, &limit)\nstop := tlb.MustFromTON(\"64000\")\nres, _ = client.PlaceStopLimitOrder(ctx, btc, config.Long, &amount, 3_000_000_000, &limit, &stop)\n\n// Cancel by hash from the result\nclient.CancelOrder(ctx, res.OrderHash)\n```\n\nEvery order call returns `*PlaceOrderResult` with `QueryID`, `OrderHash`, the ids and hashes of attached SL/TP, and the raw sequencer response including the emulation trace. `OrderHash` is what you pass to `CancelOrder` and to `GET /intent/{hash}`.\n\n### Positions\n\n```go\nsize := tlb.MustFromDecimal(\"0.001\", 9)\nclient.ClosePosition(ctx, btc, config.Long, &size)\nclient.ClosePositionFull(ctx, btc, config.Long) // reads the size on-chain\n\ntrigger := tlb.MustFromTON(\"60000\")\nclient.PlaceStopLoss(ctx, btc, config.Long, &size, &trigger)\nclient.PlaceTakeProfit(ctx, btc, config.Long, &size, &trigger)\n\nmargin := tlb.MustFromDecimal(\"50\", 9)\nclient.AddMargin(ctx, btc, config.Long, &margin)\nclient.RemoveMargin(ctx, btc, config.Long, &margin)\n```\n\n### Options worth knowing\n\n| Option | Effect |\n| --- | --- |\n| `WithClockSkew(5*time.Second)` | Compensates local clock drift in intent expirations. Recommended |\n| `WithGasless()` | Gasless execution mode |\n| `WithExpiration(ts)` | Custom intent expiration, Unix seconds |\n| `WithQueryID(id)` | Override the query id. The client tracks it for you otherwise |\n\n### Reading state\n\n```go\nseq := sequencer.NewClient(sequencer.TestnetURL)\nstate, _ := seq.GetAccountState(ctx, saAddr)\nbalances, _ := seq.GetBalances(ctx, saAddr)\npositions, _ := seq.GetPositions(ctx, saAddr)\nintent, _ := seq.GetIntent(ctx, res.OrderHash)\nstatus, _ := seq.GetStatus(ctx)\n\nspot, _ := client.GetSpotPrice(ctx, btc)\namm, _ := client.GetAmmState(ctx, btc)\nvault, _ := client.GetVaultData(ctx, \"USDT\")\n```\n\n---\n\n## 🔁 v2: Direct Wallet Transactions\n\n```go\nclient := stormv2.NewClient(config.Testnet,\n    stormv2.WithWallet(w),\n    stormv2.WithTONApi(api),\n)\n\nbtc, _ := client.Market(\"BTC\", \"USDT\")\namount := tlb.MustFromDecimal(\"10\", 6) // collateral decimals: 6 for USDT\n\nres, _ := client.PlaceMarketOrder(ctx, btc, config.Long, &amount, 3_000_000_000,\n    stormv2.WithStopLoss(&sl), stormv2.WithTakeProfit(&tp), stormv2.WithReferralID(123))\nfmt.Println(res.Hash) // TON transaction hash\n\n// Cancel by order type and index: 0 SL, 1 TP, 2 limit, 3 market\nclient.CancelOrder(ctx, btc, config.Long, 2, 0)\n```\n\nDifferences from v3 that matter in code:\n\n| | v3 `storm` | v2 `stormv2` |\n| --- | --- | --- |\n| Result | Intent hash, sequencer response | TON transaction hash |\n| Cancel | By order hash | By order type and index |\n| Amounts | 9 decimals | Collateral decimals |\n| Oracle data | Injected by the sequencer | Fetched by the SDK for margin operations |\n| Executor fee | Not needed | Appended as a second message |\n\n---\n\n## 🧪 CLI\n\nThe repository ships a CLI that exercises every call above. It is the quickest way to check your keys and environment before writing code.\n\n```bash\nexport STORM_SEED=\"word1 word2 ... word24\"\nexport STORM_PRIVATE_KEY=<ed25519 hex>   # v3 only\nexport STORM_NETWORK=testnet             # or mainnet\n\ngo run ./cmd/example keygen\ngo run ./cmd/example deposit TON 0.5 --init\ngo run ./cmd/example order market BTC USDT long 100 3 --sl=60000 --tp=80000\ngo run ./cmd/example positions\ngo run ./cmd/example close-all BTC USDT long\n\ngo run ./cmd/v2example order limit BTC USDT long 10 3 --limit=60000\ngo run ./cmd/v2example orders BTC USDT long\n```\n","text":"🐹 Go SDK github.com/storm trade/sdk go covers both trading paths. The storm package drives v3 : it builds and signs intents, submits them to the sequencer, and manages Smart Account deposits and withdrawals. The stormv2 package drives v2 with direct wallet transactions and appends the executor fee automatically. Source: storm trade/sdk go CLI examples: cmd/example for v3, cmd/v2example for v2 Package Purpose config Networks, markets, assets, Direction storm v3 client: Smart Account plus sequencer stormv2 v2 client: direct wallet transactions sequencer Trading API (V3) REST client oracle Signed oracle prices, used by v2 margin operations client/vamm , client/vault , client/smartaccount , client/positionmanager On chain reads and Smart Account operations tlb , contracts Order types, position state, error codes, TL B schemas WithClockSkew(5 time.Second) Compensates local clock drift in intent expirations. Recommended WithGasless() Gasless execution mode WithExpiration(ts) Custom intent expiration, Unix seconds WithQueryID(id) Override the query id. The client tracks it for you otherwise Reading state 🔁 v2: Direct Wallet Transactions Differences from v3 that matter in code: v3 storm v2 stormv2 Result Intent hash, sequencer response TON transaction hash Cancel By order hash By order type and index Amounts 9 decimals Collateral decimals Oracle data Injected by the sequencer Fetched by the SDK for margin operations Executor fee Not needed Appended as a second message 🧪 CLI The repository ships a CLI that exercises every call above. It is the quickest way to check your keys and environment before writing code."}