@firefly-exchange/firefly-client
Version:
The Firefly Client Library allows traders to sign, create, retrieve and listen to orders on Firefly Exchange.
51 lines • 2.48 kB
JavaScript
/**
* Create an order signature on chain and returns it. The signature is used to verify
* during on-chain trade settlement whether the orders being settled against each other
* were actually signed on by the maker/taker of the order or not.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-console */
const index_1 = require("../index");
function main() {
return __awaiter(this, void 0, void 0, function* () {
// no gas fee is required to create order signature.
const dummyAccountKey = "a182091b4d5a090b65d604e36f68629a692e3bf2aa864bd3f037854034cdd676";
const client = new index_1.FireflyClient(true, index_1.Networks.TESTNET_ARBITRUM, dummyAccountKey); // passing isTermAccepted = true for compliance and authorization
yield client.init();
client.addMarket(index_1.MARKET_SYMBOLS.DOT);
// this will throw because BTC Market does not exist in client.
try {
client.createSignedOrder({
symbol: index_1.MARKET_SYMBOLS.BTC,
price: 0,
quantity: 0.1,
side: index_1.ORDER_SIDE.SELL,
orderType: index_1.ORDER_TYPE.MARKET,
});
}
catch (e) {
console.log("Error:", e);
}
// will create a signed order to sell 0.1 DOT at MARKET price
const signedOrder = yield client.createSignedOrder({
symbol: index_1.MARKET_SYMBOLS.DOT,
price: 0,
quantity: 0.1,
side: index_1.ORDER_SIDE.SELL,
orderType: index_1.ORDER_TYPE.MARKET,
});
console.log("Signed Order Created:", signedOrder);
});
}
main().then().catch(console.warn);
//# sourceMappingURL=9.create-signed-order.js.map
;