/**
 * Posts an order to exchange. Creates the signed order and places it to exchange,
 * without requiring two separate function calls.
 */

/* eslint-disable no-console */
import { Networks, FireflyClient, MARKET_SYMBOLS, ORDER_SIDE, ORDER_TYPE } from "../index";

async function main() {
  // no gas fee is required to create order signature.
  const dummyAccountKey =
    "a182091b4d5a090b65d604e36f68629a692e3bf2aa864bd3f037854034cdd676";

  const client = new FireflyClient(true, Networks.TESTNET_ARBITRUM, dummyAccountKey); //passing isTermAccepted = true for compliance and authorizarion
  await client.init()

  client.addMarket(MARKET_SYMBOLS.ETH);

  // will post a limit order of 0.5 quantity at price 11
  const response = await client.postOrder({
    symbol: MARKET_SYMBOLS.ETH,
    price: 11,
    quantity: 0.5,
    side: ORDER_SIDE.BUY,
    cancelOnRevert: true,
    orderType: ORDER_TYPE.LIMIT
  });

  console.log(response.data);
}

main().then().catch(console.warn);
