From c7daa5d5b502c48c348c8142e842b915db675cb8 Mon Sep 17 00:00:00 2001 From: 117 <16513382+117@users.noreply.github.com> Date: Sat, 23 Mar 2024 21:45:57 -0600 Subject: [PATCH] Update trade and marketData exports --- api/index.ts | 2 +- api/marketData/index.ts | 8 ++++++- api/trade/{index.ts => consumer.ts} | 36 +++++++++++++++++------------ api/types/shared.ts | 3 +++ factory/createClient.ts | 7 ++++-- 5 files changed, 37 insertions(+), 19 deletions(-) rename api/trade/{index.ts => consumer.ts} (98%) create mode 100644 api/types/shared.ts diff --git a/api/index.ts b/api/index.ts index ff193ea..572bd0f 100644 --- a/api/index.ts +++ b/api/index.ts @@ -1,2 +1,2 @@ export { default as marketData } from "./marketData/index.ts"; -export { default as trade } from "./trade/index.ts"; +export { default as trade } from "./trade/consumer.ts"; diff --git a/api/marketData/index.ts b/api/marketData/index.ts index 3848a1e..820c916 100644 --- a/api/marketData/index.ts +++ b/api/marketData/index.ts @@ -40,7 +40,7 @@ import { TradeResponse, } from "./types/stocks.ts"; -export default ({ request }: ClientContext) => ({ +const methods = ({ request }: ClientContext) => ({ v1beta1: { corporateActions: (queryParams: CorporateActionsQueryParams) => request({ @@ -412,3 +412,9 @@ export default ({ request }: ClientContext) => ({ }, }, }); + +export default >( + context: ClientContext +): T => { + return methods(context) as T; +}; diff --git a/api/trade/index.ts b/api/trade/consumer.ts similarity index 98% rename from api/trade/index.ts rename to api/trade/consumer.ts index 432f49e..3522a72 100644 --- a/api/trade/index.ts +++ b/api/trade/consumer.ts @@ -4,15 +4,9 @@ import { } from "./types/portfolio.ts"; import { - AddAssetToWatchlistParams, - CreateWatchlistParams, - DeleteSymbolFromWatchlistParams, - DeleteWatchlistByNameParams, - GetWatchlistByNameParams, - UpdateWatchlistByNameParams, - UpdateWatchlistParams, - Watchlist, -} from "./types/watchlist.ts"; + AnnouncementsQueryParams, + CorporateActionAnnouncement, +} from "./types/corporate.ts"; import { Account, @@ -21,11 +15,6 @@ import { UpdatedAccountConfigurations, } from "./types/account.ts"; -import { - AnnouncementsQueryParams, - CorporateActionAnnouncement, -} from "./types/corporate.ts"; - import { CryptoFundingTransfer, CryptoFundingWallet, @@ -36,6 +25,17 @@ import { WithdrawalParams, } from "./types/cryptoFunding.ts"; +import { + AddAssetToWatchlistParams, + CreateWatchlistParams, + DeleteSymbolFromWatchlistParams, + DeleteWatchlistByNameParams, + GetWatchlistByNameParams, + UpdateWatchlistByNameParams, + UpdateWatchlistParams, + Watchlist, +} from "./types/watchlist.ts"; + import { ClientContext } from "../../factory/createClient.ts"; import { Asset } from "./types/asset.ts"; import { MarketCalendar } from "./types/calendar.ts"; @@ -44,7 +44,7 @@ import { OptionContract, OptionContractsQueryParams } from "./types/options.ts"; import { CreateOrderOptions, Order, PatchOrderOptions } from "./types/order.ts"; import { ClosePositionOptions, Position } from "./types/position.ts"; -export default ({ request }: ClientContext) => ({ +const methods = ({ request }: ClientContext) => ({ v2: { account: { get: () => @@ -382,3 +382,9 @@ export default ({ request }: ClientContext) => ({ }, }, }); + +export default >( + context: ClientContext +): T => { + return methods(context) as T; +}; diff --git a/api/types/shared.ts b/api/types/shared.ts new file mode 100644 index 0000000..6202596 --- /dev/null +++ b/api/types/shared.ts @@ -0,0 +1,3 @@ +import { ClientContext } from "../../factory/createClient.ts"; + +export type ClientContextConsumer = (context: ClientContext) => T; diff --git a/factory/createClient.ts b/factory/createClient.ts index 7c93591..d48c105 100644 --- a/factory/createClient.ts +++ b/factory/createClient.ts @@ -4,6 +4,7 @@ import { StockDataWebSocket } from "../api/trade/types/websocket_2.ts"; import { CryptoWebSocket } from "../api/trade/types/websocket_3.ts"; import { NewsWebSocket } from "../api/trade/types/websocket_4.ts"; import { OptionsWebSocket } from "../api/trade/types/websocket_5.ts"; +import { ClientContextConsumer } from "../api/types/shared.ts"; import { TokenBucketOptions, createTokenBucket } from "./createTokenBucket.ts"; // Used to share the client options and request function between the different API methods @@ -32,8 +33,10 @@ type RequestOptions = { // The client object that is returned by createClient export type Client = { rest: { - trade: ReturnType; - marketData: ReturnType; + trade: ReturnType>>; + marketData: ReturnType< + ClientContextConsumer> + >; }; websocket: { trade: TradeWebSocket;