-
Notifications
You must be signed in to change notification settings - Fork 6
Get SDA SDA Exchange Offer
Wern Ling edited this page Oct 6, 2022
·
4 revisions
Returns the UserSdaExchangeInfo
of an account.
The following parameters are required:
- Context - context
- PublicAccount - PublicAccount of an account
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
// Private key of some existing account
privateKey = "3B9670B5CB19C893694FC49B461CE489BF9588BE16DBE8DC29CF06338133DEE6"
)
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Account from private key
account, err := client.NewAccountFromPrivateKey(privateKey)
if err != nil {
fmt.Printf("NewAccountFromPrivateKey returned error: %s", err)
return
}
// Get user offers info
userSdaExchangeInfo, err := client.SdaExchange.GetAccountSdaExchangeInfo(context.Background(), account.PublicAccount)
if err != nil {
fmt.Printf("SdaExchange.GetAccountSdaExchangeInfo returned error: %s", err)
return
}
fmt.Println(userSdaExchangeInfo.String())
}
Returns the SdaOfferBalance
of an account.
The following parameters are required:
- Context - context
- AssetId - AssetId of a mosaic
- offerType - give or get
package main
import (
"context"
"fmt"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
)
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Get the balance of the SDA-SDA offers by namespaceId (assetId)
sdaOfferBalanace, err := client.SdaExchange.GetSdaExchangeOfferByAssetId(context.Background(), sdk.XpxNamespaceId, "give")
if err != nil {
fmt.Printf("SdaExchange.GetSdaExchangeOfferByAssetId returned error: %s", err)
return
}
fmt.Println(sdaOfferBalanace)
}
Creates a new SDA-SDA offer.
The following parameters are required:
- Deadline - deadline of the transaction
-
PlaceSdaOffer - array of the PlaceSdaOffer
-
SdaOffer
- MosaicGive - mosaic to be given
- MosaicGet - mosaic to be gained
- Duration - duration of the SDA-SDA offer
-
SdaOffer
Note: Offers cannot be placed for special mosaics - Storage (SO), Streaming (SM), Review, Supercontract (SC)
package main
import (
"context"
"fmt"
"time"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
// Private key of some existing account
privateKey = "3B9670B5CB19C893694FC49B461CE489BF9588BE16DBE8DC29CF06338133DEE6"
)
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Account from private key
account, err := client.NewAccountFromPrivateKey(privateKey)
if err != nil {
fmt.Printf("NewAccountFromPrivateKey returned error: %s", err)
return
}
placeSdaOfferTrx, err := client.NewPlaceSdaExchangeOfferTransaction(
sdk.NewDeadline(time.Hour),
[]*sdk.PlaceSdaOffer{
{
SdaOffer: sdk.SdaOffer{
MosaicGive: &sdk.Mosaic{AssetId: ExampleMosaicId1, Amount: 1000},
MosaicGet: &sdk.Mosaic{AssetId: ExampleMosaicId2, Amount: 2000},
},
sdk.Duration(1000),
},
{
SdaOffer: sdk.SdaOffer{
MosaicGive: &sdk.Mosaic{AssetId: ExampleMosaicId2, Amount: 200},
MosaicGet: &sdk.Mosaic{AssetId: ExampleMosaicId1, Amount: 100},
},
sdk.Duration(1000),
},
},
)
// Sign transaction
signedTransaction, err := account.Sign(placeSdaOfferTrx)
if err != nil {
fmt.Printf("Sign returned error: %s", err)
return
}
// Announce transaction
_, err = client.Transaction.Announce(context.Background(), signedTransaction)
if err != nil {
fmt.Printf("Transaction.Announce returned error: %s", err)
return
}
}
Removes an existing SDA-SDA offer.
The following parameters are required:
- Deadline - deadline of the transaction
-
RemoveSdaOffer - array of the RemoveSdaOffer
-
RemoveSdaOffer
- AssetIdGive - mosaic that was to be given
- AssetIdGet - mosaic that was to be gained
-
RemoveSdaOffer
package main
import (
"context"
"fmt"
"time"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
)
const (
// Sirius api rest server
baseUrl = "http://localhost:3000"
// Private key of some existing account
privateKey = "3B9670B5CB19C893694FC49B461CE489BF9588BE16DBE8DC29CF06338133DEE6"
)
func main() {
conf, err := sdk.NewConfig(context.Background(), []string{baseUrl})
if err != nil {
fmt.Printf("NewConfig returned error: %s", err)
return
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Account from private key
account, err := client.NewAccountFromPrivateKey(privateKey)
if err != nil {
fmt.Printf("NewAccountFromPrivateKey returned error: %s", err)
return
}
removeSdaOfferTrx, err := client.NewRemoveSdaExchangeOfferTransaction(
sdk.NewDeadline(time.Hour),
[]*sdk.RemoveSdaOffer{
{
AssetIdGive: ExampleNamespaceId1,
AssetIdGet: ExampleNamespaceId2,
},
{
AssetIdGive: ExampleNamespaceId2,
AssetIdGet: ExampleNamespaceId1,
},
},
)
// Sign transaction
signedTransaction, err := account.Sign(removeSdaOfferTrx)
if err != nil {
fmt.Printf("Sign returned error: %s", err)
return
}
// Announce transaction
_, err = client.Transaction.Announce(context.Background(), signedTransaction)
if err != nil {
fmt.Printf("Transaction.Announce returned error: %s", err)
return
}
}
- Home
- Installation
-
Examples
- Basic functions
- Get Accounts info
- Get Transactions info
- Get Mosaic info
- Get Mosaic Levy info
- Get Namespace info
- Get BlockChain info
- Get Network info
- Get Metadata info
- Get Nem Metadata info
- Get Account Properties info
- Get Exchange info
- Get SDA-SDA Exchange info
- Get Secret lock info
- Get Storage info
- Announces a transaction
- Websocket