"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("../src");
const composite_client_1 = require("../src/clients/composite-client");
const constants_1 = require("../src/clients/constants");
const local_wallet_1 = __importDefault(require("../src/clients/modules/local-wallet"));
const subaccount_1 = require("../src/clients/subaccount");
const utils_1 = require("../src/lib/utils");
const constants_2 = require("./constants");
async function sleep(ms) {
    return new Promise((resolve) => setTimeout(resolve, ms));
}
async function test() {
    const wallet = await local_wallet_1.default.fromMnemonic(constants_2.TEST_MNEMONIC, src_1.BECH32_PREFIX);
    console.log(wallet);
    const network = constants_1.Network.testnet();
    const client = await composite_client_1.CompositeClient.connect(network);
    console.log('**Client**');
    console.log(client);
    const subaccount = subaccount_1.SubaccountInfo.forLocalWallet(wallet, 0);
    /*
    Note this example places a stateful order.
    Programmatic traders should generally not use stateful orders for following reasons:
    - Stateful orders received out of order by validators will fail sequence number validation
      and be dropped.
    - Stateful orders have worse time priority since they are only matched after they are included
      on the block.
    - Stateful order rate limits are more restrictive than Short-Term orders, specifically max 2 per
      block / 20 per 100 blocks.
    - Stateful orders can only be canceled after they’ve been included in a block.
    */
    const longTermOrderClientId = (0, utils_1.randomInt)(constants_2.MAX_CLIENT_ID);
    try {
        // place a long term order
        const tx = await client.placeOrder(subaccount, 'ETH-USD', constants_1.OrderType.LIMIT, constants_1.OrderSide.SELL, 40000, 0.01, longTermOrderClientId, constants_1.OrderTimeInForce.GTT, 60, constants_1.OrderExecution.DEFAULT, false, false);
        console.log('**Long Term Order Tx**');
        console.log(tx.hash);
    }
    catch (error) {
        console.log('**Long Term Order Failed**');
        console.log(error.message);
    }
    await sleep(5000); // wait for placeOrder to complete
    try {
        // cancel the long term order
        const tx = await client.cancelOrder(subaccount, longTermOrderClientId, src_1.OrderFlags.LONG_TERM, 'ETH-USD', 0, 120);
        console.log('**Cancel Long Term Order Tx**');
        console.log(tx);
    }
    catch (error) {
        console.log('**Cancel Long Term Order Failed**');
        console.log(error.message);
    }
}
test()
    .then(() => { })
    .catch((error) => {
    console.log(error.message);
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9uZ190ZXJtX29yZGVyX2NhbmNlbF9leGFtcGxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vZXhhbXBsZXMvbG9uZ190ZXJtX29yZGVyX2NhbmNlbF9leGFtcGxlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsZ0NBQW1EO0FBQ25ELHNFQUFrRTtBQUNsRSx3REFNa0M7QUFDbEMsdUZBQThEO0FBQzlELDBEQUEyRDtBQUMzRCw0Q0FBNkM7QUFDN0MsMkNBQTJEO0FBRTNELEtBQUssVUFBVSxLQUFLLENBQUMsRUFBVTtJQUM3QixPQUFPLElBQUksT0FBTyxDQUFDLENBQUMsT0FBTyxFQUFFLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUM7QUFDM0QsQ0FBQztBQUVELEtBQUssVUFBVSxJQUFJO0lBQ2pCLE1BQU0sTUFBTSxHQUFHLE1BQU0sc0JBQVcsQ0FBQyxZQUFZLENBQUMseUJBQWEsRUFBRSxtQkFBYSxDQUFDLENBQUM7SUFDNUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUNwQixNQUFNLE9BQU8sR0FBRyxtQkFBTyxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ2xDLE1BQU0sTUFBTSxHQUFHLE1BQU0sa0NBQWUsQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEQsT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUMxQixPQUFPLENBQUMsR0FBRyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0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