Skip to content

Commit

Permalink
💱 Optimize, clarify global declarations
Browse files Browse the repository at this point in the history
It could be prudent to globalize the accounts so that we can walk through the other limit order examples
  • Loading branch information
JFWooten4 committed Nov 26, 2024
1 parent f1a50e2 commit a4bdaeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
4 changes: 3 additions & 1 deletion docs/learn/encyclopedia/sdex/README.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
---
title: Trading Liquidity
title: Payment Liquidity
sidebar_position: 90
---

import DocCardList from "@theme/DocCardList";

{_/ Opt. do as "Conversion" liquidirty _/}

Native network markets, liquidity, and conversions for all assets.

<DocCardList />
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import org.stellar.sdk.*;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.SubmitTransactionResponse;


public class Liquidity {
static final Server server = new Server("https://horizon-testnet.stellar.org");

Expand All @@ -111,20 +112,6 @@ public class Liquidity {
```

```go
package main

import (
"fmt"
"github.com/stellar/go/build"
"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/txnbuild"
)

var server = horizonclient.DefaultTestNetClient

func main() {
// Account setup
privateKey := "SAXBT6KO6NJ6SJXHBO6EBC7I5ZB7DZFYNPQOLXZJOKQ2LSGY5FU7ZJZB"
Expand Down Expand Up @@ -159,6 +146,7 @@ func newTxBuilder(pubKey string) (*txnbuild.Transaction, error) {
<CodeExample>

```python
# rpl with the txBuilderHerlperEnv
transaction = TransactionBuilder(
source_account = account,
network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE,
Expand All @@ -170,8 +158,8 @@ transaction = TransactionBuilder(
price = "20.0" # 20 Pesos per Dollar
).set_timeout(360).build()

keypair = Keypair.from_secret(privateKey) transaction.sign(keypair)

keypair = Keypair.from_secret(privateKey)
transaction.sign(keypair)
response = server.submit_transaction(transaction)

print(f"Transaction successful: {response['successful']}")
Expand Down Expand Up @@ -214,6 +202,8 @@ print(f"Offer ID: {response['result_xdr']}")

```java


main{{
AccountResponse account = server.accounts().account(publicKey);

Transaction transaction = new TransactionBuilder(account, Network.TESTNET)
Expand All @@ -238,6 +228,8 @@ print(f"Offer ID: {response['result_xdr']}")
```

```go

main {{?
request := horizonclient.AccountRequest{AccountID: publicKey}
account, err := server.AccountDetail(request)
check(err)
Expand Down Expand Up @@ -1142,7 +1134,7 @@ public static SubmitTransactionResponse addLiquidity(
KeyPair source,
String poolId,
String maxReserveA,
String maxReserveB
String maxReserveB,
) throws Exception {
double exactPrice = Double.parseDouble(maxReserveA) / Double.parseDouble(maxReserveB);
double minPrice = exactPrice - exactPrice * 0.1;
Expand Down Expand Up @@ -1546,12 +1538,12 @@ public static void main(String[] args) throws Exception {
balance ->
"liquidity_pool_shares".equals(balance.getAssetType()) &&
poolId.equals(balance.getLiquidityPoolId())
)Ã¥
)
.mapToDouble(balance -> Double.parseDouble(balance.getBalance()))
.findFirst();
if (!balance.isPresent()) {
throw new Exception("No liquidity pool shares found for kp1");

}
removeLiquidity(kp1, poolId, balance);
getSpotPrice();
}
Expand Down

0 comments on commit a4bdaeb

Please sign in to comment.