Skip to content

Commit

Permalink
feat: Place order fixes, WsJsonClient as interface (#65)
Browse files Browse the repository at this point in the history
* feat: Place order fixes, wWsJsonClient as interface

* fix package exports

* remove unneeded disclaimer

* prettier

* minor nits
  • Loading branch information
felipecsl authored Sep 8, 2023
1 parent 836e783 commit 2a0bdbe
Show file tree
Hide file tree
Showing 9 changed files with 654 additions and 363 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"types": "dist/web.d.ts",
"exports": {
"./wsJsonClient": "./dist/client/wsJsonClient.js",
"./realWsJsonClient": "./dist/client/realWsJsonClient.js",
"./mockWsJsonClient": "./dist/client/mockWsJsonClient.js",
"./alertTypes": "./dist/client/types/alertTypes.js",
"./tdaWsJsonTypes": "./dist/client/tdaWsJsonTypes.js",
"./wsJsonClientAuth": "./dist/client/wsJsonClientAuth.js",
Expand Down
182 changes: 182 additions & 0 deletions src/client/mockWsJsonClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { WsJsonClient } from "./wsJsonClient";
import { PositionsResponse } from "./services/positionsMessageHandler";
import { RawLoginResponseBody } from "./services/loginMessageHandler";
import { AlertsResponse } from "./types/alertTypes";
import { CancelOrderResponse } from "./services/cancelOrderMessageHandler";
import {
ChartRequestParams,
ChartResponse,
} from "./services/chartMessageHandler";
import { CreateAlertRequestParams } from "./services/createAlertMessageHandler";
import { OptionChainResponse } from "./services/optionSeriesMessageHandler";
import {
OptionChainDetailsRequest,
OptionChainDetailsResponse,
} from "./services/optionChainDetailsMessageHandler";
import { OptionSeriesQuotesResponse } from "./services/optionSeriesQuotesMessageHandler";
import {
OptionQuotesRequestParams,
OptionQuotesResponse,
} from "./services/optionQuotesMessageHandler";
import {
PlaceLimitOrderRequestParams,
PlaceOrderSnapshotResponse,
} from "./services/placeOrderMessageHandler";
import { OrderEventsResponse } from "./services/orderEventsMessageHandler";
import { QuotesResponse } from "./services/quotesMessageHandler";
import { InstrumentSearchResponse } from "./services/instrumentSearchMessageHandler";
import { UserPropertiesResponse } from "./services/userPropertiesMessageHandler";

export default class MockWsJsonClient implements WsJsonClient {
async *accountPositions(_: string): AsyncIterable<PositionsResponse> {

Check warning on line 31 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 31 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 31 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return yield {
positions: [],
};
}

authenticate(): Promise<RawLoginResponseBody | null> {
return Promise.resolve(null);
}

cancelAlert(_: number): Promise<AlertsResponse> {

Check warning on line 41 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 41 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 41 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return Promise.resolve({
alerts: [],
});
}

cancelOrder(_: number): Promise<CancelOrderResponse> {

Check warning on line 47 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 47 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 47 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return Promise.resolve({
service: "cancel_order",
orderId: 123,
type: "snapshot",
body: {},
});
}

async *chart(_: ChartRequestParams): AsyncIterable<ChartResponse> {

Check warning on line 56 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 56 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 56 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return yield {
symbol: "",
candles: [],
};
}

createAlert(_: CreateAlertRequestParams): Promise<AlertsResponse> {

Check warning on line 63 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 63 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 63 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return Promise.resolve({
alerts: [],
});
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
disconnect(): void {}

// eslint-disable-next-line @typescript-eslint/no-empty-function
ensureConnected(): void {}

isConnected(): boolean {
return true;
}

isConnecting(): boolean {
return false;
}

async *lookupAlerts(): AsyncIterable<AlertsResponse> {
return yield {
alerts: [],
};
}

optionChain(_: string): Promise<OptionChainResponse> {

Check warning on line 89 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 89 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 89 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
return Promise.resolve({
series: [],
service: "optionSeries",
});
}

optionChainDetails(
_: OptionChainDetailsRequest

Check warning on line 97 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 97 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 97 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
): Promise<OptionChainDetailsResponse> {
return Promise.resolve({
seriesDetails: [],
});
}

async *optionChainQuotes(
_: string

Check warning on line 105 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 105 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 105 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
): AsyncIterable<OptionSeriesQuotesResponse> {
return yield {
series: [],
service: "optionSeries/quotes",
};
}

async *optionQuotes(
_: OptionQuotesRequestParams

Check warning on line 114 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 114 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 114 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
): AsyncIterable<OptionQuotesResponse> {
return yield {
items: [],
service: "quotes/options",
};
}

placeOrder(
_: PlaceLimitOrderRequestParams

Check warning on line 123 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'_' is defined but never used

Check warning on line 123 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'_' is defined but never used

Check warning on line 123 in src/client/mockWsJsonClient.ts

View workflow job for this annotation

GitHub Actions / build (19.x)

'_' is defined but never used
): Promise<PlaceOrderSnapshotResponse> {
return Promise.resolve({
service: "place_order",
orders: [],
});
}

async *quotes(_: string[]): AsyncIterable<QuotesResponse> {
return yield {
quotes: [],
};
}

replaceOrder(
_: Required<PlaceLimitOrderRequestParams>
): Promise<OrderEventsResponse> {
return Promise.resolve({
service: "order_events",
orders: [],
});
}

searchInstruments(_: string): Promise<InstrumentSearchResponse> {
return Promise.resolve({
instruments: [],
});
}

userProperties(): Promise<UserPropertiesResponse> {
return Promise.resolve({
defaultAccountCode: "foo",
nickname: "foo",
plDisplayMethod: "foo",
stocksOrderDefaultType: "foo",
stocksOrderDefaultQuantity: 0,
stocksOrderQuantityIncrement: 0,
optionsOrderDefaultType: "foo",
optionsOrderDefaultQuantity: 0,
optionsOrderQuantityIncrement: 0,
futuresOrderOrderDefaultType: "foo",
futuresOrderDefaultType: "foo",
futuresOrderDefaultQuantity: 0,
futuresOrderQuantityIncrement: 0,
futureOptionsOrderDefaultType: "foo",
futureOptionsOrderDefaultQuantity: 0,
futureOptionsOrderQuantityIncrement: 0,
forexOrderDefaultType: "foo",
forexOrderDefaultQuantity: 0,
forexOrderQuantityIncrement: 0,
});
}

async *workingOrders(_: string): AsyncIterable<OrderEventsResponse> {
return yield {
orders: [],
service: "order_events",
};
}
}
Loading

0 comments on commit 2a0bdbe

Please sign in to comment.