Skip to content

Commit

Permalink
update comments, remove unused params
Browse files Browse the repository at this point in the history
  • Loading branch information
samanthatuhseng authored and alanwu4321 committed Aug 16, 2023
1 parent 8f57470 commit becbd39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 125 deletions.
64 changes: 2 additions & 62 deletions src/exchanges/OrderlyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,14 @@ import { Market } from "../Market";
import { NotImplementedFn } from "../NotImplementedFn";
import { Ticker } from "../Ticker";
import { Trade } from "../Trade";
import * as zlib from "../ZlibUtils";

const pongBuffer = Buffer.from("pong");

export type OrderlyClientOptions = ClientOptions & {
sendThrottleMs?: number;
};

/**
* Implements OKEx V3 WebSocket API as defined in
* https://www.okex.com/docs/en/#spot_ws-general
*
* Limits:
* 1 connection / second
* 240 subscriptions / hour
*
* Connection will disconnect after 30 seconds of silence
* it is recommended to send a ping message that contains the
* message "ping".
*
* Order book depth includes maintenance of a checksum for the
* first 25 values in the orderbook. Each update includes a crc32
* checksum that can be run to validate that your order book
* matches the server. If the order book does not match you should
* issue a reconnect.
*
* Refer to: https://www.okex.com/docs/en/#spot_ws-checksum
* Implements Orderly Network WebSocket API as defined in
* https://docs-api.orderly.network/#websocket-api
*/

type KlineType =
Expand Down Expand Up @@ -289,25 +270,6 @@ export class OrderlyClient extends BasicClient {
} catch (ex) {
this.emit("error", ex);
}
// zlib.inflateRaw(compressed, (err, raw) => {
// if (err) {
// this.emit("error", err);
// return;
// }

// // ignore pongs
// if (raw.equals(pongBuffer)) {
// return;
// }

// // process JSON message
// try {
// const msg = JSON.parse(raw.toString());
// this._processsMessage(msg);
// } catch (ex) {
// this.emit("error", ex);
// }
// });
}

protected _processsMessage(msg: any) {
Expand Down Expand Up @@ -338,18 +300,6 @@ export class OrderlyClient extends BasicClient {
}
return;
}

// // l2 snapshots
// if (msg.table.match(/depth5/)) {
// this._processLevel2Snapshot(msg);
// return;
// }

// // l2 updates
// if (msg.table.match(/depth/)) {
// this._processLevel2Update(msg);
// return;
// }
}

/**
Expand Down Expand Up @@ -429,16 +379,6 @@ export class OrderlyClient extends BasicClient {
data: { symbol },
} = msg;
this.emit("candle", data, symbol);
// for (const datum of msg.data) {
// // ensure market
// const remoteId = datum.instrument_id;
// const market = this._candleSubs.get(remoteId);
// if (!market) continue;

// // construct and emit candle
// const candle = this._constructCandle(datum);
// this.emit("candle", candle, market);
// }
}

/**
Expand Down
72 changes: 9 additions & 63 deletions src/exchanges/OrderlyPrivateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-implied-eval */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { BasicPrivateClient, PrivateChannelSubscription } from "../BasicPrivateClient";
import { BasicPrivateClient } from "../BasicPrivateClient";
import { CandlePeriod } from "../CandlePeriod";
import { CancelableFn } from "../flowcontrol/Fn";
import { throttle } from "../flowcontrol/Throttle";
import { Market } from "../Market";
import { PrivateClientOptions } from "../PrivateClientOptions";
import { base64Encode, hmacSign } from "../Jwt";
import { OrderStatus } from "../OrderStatus";
import { Order } from "../Order";
import { OrderEvent } from "../OrderEvent";
import { InvestmentType, ExchangeId } from "../types";
import { eddsa } from "ccxt/js/src/base/functions";
import * as nacl from "tweetnacl";
import * as elliptic from "elliptic";
import * as crypto from "crypto";
import * as ethUtil from "ethereumjs-util";
import { ExchangeId } from "../types";
import { ec as EC } from "elliptic";
import keccak256 from "keccak256";
import { KeyPair } from "near-api-js";
Expand Down Expand Up @@ -116,25 +109,9 @@ export type OrderlyClientOptions = PrivateClientOptions & {
};

/**
* Implements OKEx V3 WebSocket API as defined in
* https://www.okex.com/docs/en/#spot_ws-general
* https://www.okx.com/docs-v5/en/#websocket-api-private-channel-order-channel
*
* Limits:
* 1 connection / second
* 240 subscriptions / hour
*
* Connection will disconnect after 30 seconds of silence
* it is recommended to send a ping message that contains the
* message "ping".
*
* Order book depth includes maintenance of a checksum for the
* first 25 values in the orderbook. Each update includes a crc32
* checksum that can be run to validate that your order book
* matches the server. If the order book does not match you should
* issue a reconnect.
*
* Refer to: https://www.okex.com/docs/en/#spot_ws-checksum
* Implements Orderly Network WebSocket API as defined in
* https://docs-api.orderly.network/#introduction
* https://docs-api.orderly.network/#websocket-api
*/

export class OrderlyPrivateClient extends BasicPrivateClient {
Expand All @@ -161,12 +138,9 @@ export class OrderlyPrivateClient extends BasicPrivateClient {
}

/**
*
* @param subscriptionId
* @param channel
* @see https://www.okx.com/docs-v5/en/#websocket-api-private-channel-order-channel
* @see https://docs-api.orderly.network/#websocket-api-private-execution-report
*/
protected _sendSubPrivateOrders(subscriptionId: string, channel: PrivateChannelSubscription) {
protected _sendSubPrivateOrders() {
this._wss.send(
JSON.stringify({
id: "clientID3",
Expand All @@ -175,7 +149,7 @@ export class OrderlyPrivateClient extends BasicPrivateClient {
}),
);
}
protected _sendUnsubPrivateOrders(subscriptionId: string, channel: PrivateChannelSubscription) {
protected _sendUnsubPrivateOrders() {
throw new Error("Method not implemented.");
}

Expand Down Expand Up @@ -289,35 +263,7 @@ export class OrderlyPrivateClient extends BasicPrivateClient {
// order update
if (msg?.topic?.includes("executionreport")) {
if (msg.data) {
// https://docs-api.orderly.network/#restful-api-private-get-order
// _processsMessage {
// topic: 'executionreport',
// ts: 1691126463207,
// data: {
// symbol: 'SPOT_NEAR_USDC',
// clientOrderId: '',
// orderId: 382138349,
// type: 'LIMIT',
// side: 'SELL',
// quantity: 16.21,
// price: 2,
// tradeId: 0,
// executedPrice: 0,
// executedQuantity: 0,
// fee: 0,
// feeAsset: 'USDC',
// totalExecutedQuantity: 0,
// avgPrice: 0,
// status: 'NEW', // "status": "FILLED", // NEW / FILLED / PARTIAL_FILLED / CANCELLED
// reason: '',
// totalFee: 0,
// visible: 16.21,
// timestamp: 1691126463207,
// brokerId: 'woofi_dex',
// brokerName: 'WOOFi DEX',
// maker: false
// }
// }
// https://docs-api.orderly.network/#restful-api-private-get-order
const d = msg.data;
let status = d.status;
// map to our status
Expand Down

0 comments on commit becbd39

Please sign in to comment.