Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix: Closing order does not work with an order object #213

Open
atrefonas opened this issue Jul 12, 2022 · 4 comments
Open

🐛 Fix: Closing order does not work with an order object #213

atrefonas opened this issue Jul 12, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@atrefonas
Copy link
Contributor

atrefonas commented Jul 12, 2022

ℹ Overview

const api = new AlgodexAPI({config: {
  'algod': {
    'uri': environment === 'mainnet' ? 'https://node.algoexplorerapi.io' :
      'https://node.testnet.algoexplorerapi.io',
    'token': '',
  },
  'indexer': {
    'uri': 'https://algoindexer.testnet.algoexplorerapi.io',
    'token': '',
  },
  'explorer': {
    'uri': environment === 'mainnet' ? 'https://indexer.testnet.algoexplorerapi.io' :
    'https://indexer.algoexplorerapi.io',
  },
  'dexd': {
    'uri': environment === 'mainnet' ? 'https://app.algodex.com/algodex-backend' :
      'https://testnet.algodex.com/algodex-backend',
    'token': '',
  },
}});


    await api.setWallet({
      'type': 'sdk',
      'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
      'connector': require('../lib/wallet/connectors/AlgoSDK'),
      // eslint-disable-next-line max-len
      'mnemonic': '...',
    });

...

await api.closeOrder({
      'asset': order.asset,
      'address': order.address,
      'price': order.price,
      'amount': order.amount,
      'execution': 'close',
      'type': order.type,
    }); 

Uncaught TypeError TypeError: Must have valid algod client!!!
at structure (/Users/a3voices/algodex-sdk/lib/order/structure/structure.js:49:58)
at (/Users/a3voices/algodex-sdk/lib/AlgodexApi.js:506:16)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

📝 Related Issues

💻 System Configuration

  • Operating System:
    • Edition:
    • Version:
    • Build:
  • Browser:
    • Type:
    • Version:
@atrefonas atrefonas added the bug Something isn't working label Jul 12, 2022
@atrefonas
Copy link
Contributor Author

I tried order.client = api.algod;

Now saying TypeError: Must have valid Application Index

@atrefonas
Copy link
Contributor Author

I see it's being used in the PR-400 in algodex-react, however I don't see this documented anywhere:

    const cancelOrderPromise = closeOrder({
      address: ownerAddress,
      version,
      price: Number(formattedPrice),
      amount: Number(formattedASAAmount),
      total: Number(formattedPrice) * Number(formattedASAAmount),
      asset: { id: assetId, decimals },
      assetId,
      type: cellData.type.toLowerCase(),
      appId,
      contract: {
        creator: ownerAddress
      },
      wallet
    })

@atrefonas
Copy link
Contributor Author

Finally got it to work after adding all of this:

const cancelOrderObj = {
   address: dbOrder.address,
   version: dbOrder.version,
   price: dbOrder.price,
   amount: dbOrder.amount,
   total: dbOrder.price * dbOrder.amount,
   asset: {id: assetId, decimals: 6},
   assetId: dbOrder.assetId,
   type: dbOrder.type,
   appId: appId,
   contract: {
     creator: dbOrder.contract.creator,
     lsig: new LogicSigAccount(dbOrder.contract.lsig.lsig.logic.data),
   },
   wallet: api.wallet,
   client: api.algod,
 };

@atrefonas
Copy link
Contributor Author

This is how difficult it currently is to close orders using the Algodex orderbook alone:

https://github.com/algodex/algodex-sdk-examples/blob/main/cancel-all-orders/cancel-all-orders.js

Should get massively simplified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant