Fixed re-subscribe bug

This commit is contained in:
Aleksandr Kraiz
2022-06-06 11:17:04 +04:00
parent bc2951fb66
commit 11de694b6f
3 changed files with 15 additions and 8 deletions

View File

@@ -286,6 +286,8 @@ const exchangeContract = Exchange__factory.connect(
const orderIsOk = await exchangeContract.validateOrder(signedOrder);
if (!orderIsOk) throw new Error("Order invalid");
const { orderId } = await simpleFetch(orionUnit.orionAggregator.placeOrder)(
signedOrder,
false // True if you want place order to "internal" orderbook. If you do not want your order to be executed on CEXes or DEXes, but could be filled with the another "internal" order(s).

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.12.0",
"version": "0.12.1",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -139,6 +139,8 @@ const exclusiveSubscriptions = [
] as const;
type WsMessage = string | ArrayBufferLike | Blob | ArrayBufferView;
const isSubType = (subType: string): subType is keyof Subscription => Object.values(SubscriptionType).some((t) => t === subType);
class OrionAggregatorWS {
private ws: WebSocket | undefined;
@@ -264,14 +266,17 @@ class OrionAggregatorWS {
this.ws.onopen = () => {
// Re-subscribe to all subscriptions
if (isReconnect) {
Object.entries(this.subscriptions).forEach(([type, subscription]) => {
this.send({
T: type,
...('payload' in subscription) && {
S: subscription.payload,
},
Object.keys(this.subscriptions)
.filter(isSubType)
.forEach((subType) => {
const subscriptions = this.subscriptions[subType];
if (subscriptions) {
Object.keys(subscriptions).forEach((subKey) => {
const sub = subscriptions[subKey];
if (sub) this.subscribe(subType, sub);
});
}
});
});
}
};
this.ws.onmessage = (e) => {