Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
117 committed Jul 26, 2023
1 parent 43ec1b4 commit 8d79a67
Show file tree
Hide file tree
Showing 95 changed files with 468 additions and 886 deletions.
100 changes: 56 additions & 44 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import type { OpenAPIConfig } from "./core/OpenAPI.js";
import type { BaseHttpRequest } from "./core/BaseHttpRequest.js";
import type { BaseHttpRequest } from "./rest/BaseHttpRequest";
import type { ApiRequestOptions } from "./rest/ApiRequestOptions";

import { AxiosHttpRequest } from "./core/AxiosHttpRequest.js";
import { AxiosHttpRequest } from "./rest/AxiosHttpRequest";
import { Logos } from "./paths/logos";
import { News } from "./paths/news";
import { Clock } from "./paths/clock";
import { Orders } from "./paths/orders";
import { Assets } from "./paths/assets";
import { AccountService } from "./paths/AccountService.js";
import { Calendar } from "./paths/calendar";
import { Crypto } from "./paths/crypto";
import { Stocks } from "./paths/stocks";
import { Screener } from "./paths/screener";
import { Positions } from "./paths/positions";
import { Watchlists } from "./paths/watchlists";
import { Account } from "./paths/account";
import { PortfolioHistoryService } from "./paths/PortfolioHistoryService.js";
import { AccountConfigurations } from "./paths/AccountConfigurations";

import { LogoService } from "./services/LogoService.js";
import { NewsService } from "./services/NewsService.js";
import { ClockService } from "./services/ClockService.js";
import { OrdersService } from "./services/OrdersService.js";
import { AssetsService } from "./services/AssetsService.js";
import { AccountService } from "./services/AccountService.js";
import { CalendarService } from "./services/CalendarService.js";
import { CryptoDataService } from "./services/CryptoDataService.js";
import { StockDataService } from "./services/StockDataService.js";
import { ScreenerService } from "./services/ScreenerService.js";
import { PositionsService } from "./services/PositionsService.js";
import { WatchlistsService } from "./services/WatchlistsService.js";
import { AccountActivitiesService } from "./services/AccountActivitiesService.js";
import { PortfolioHistoryService } from "./services/PortfolioHistoryService.js";
import { AccountConfigurationsService } from "./services/AccountConfigurationsService.js";
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
type Headers = Record<string, string>;

export type OpenAPIConfig = {
BASE: string;
HEADERS?: Headers | Resolver<Headers> | undefined;
};

export const OpenAPI: OpenAPIConfig = {
BASE: "https://paper-api.alpaca.markets",
HEADERS: undefined,
};

type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;

Expand All @@ -31,34 +43,34 @@ interface ClientOptions {

// bundle all account services into one class for convenience
class AccountServices extends AccountService {
activities: AccountActivitiesService;
configurations: AccountConfigurationsService;
positions: PositionsService;
orders: OrdersService;
activities: Account;
configurations: AccountConfigurations;
positions: Positions;
orders: Orders;
portfolioHistory: PortfolioHistoryService;

constructor(httpRequest: BaseHttpRequest) {
super(httpRequest);
this.activities = new AccountActivitiesService(httpRequest);
this.configurations = new AccountConfigurationsService(httpRequest);
this.positions = new PositionsService(httpRequest);
this.orders = new OrdersService(httpRequest);
this.activities = new Account(httpRequest);
this.configurations = new AccountConfigurations(httpRequest);
this.positions = new Positions(httpRequest);
this.orders = new Orders(httpRequest);
this.portfolioHistory = new PortfolioHistoryService(httpRequest);
}
}

export class Client {
private readonly request: BaseHttpRequest;

public readonly calendar: CalendarService;
public readonly clock: ClockService;
public readonly assets: AssetsService;
public readonly crypto: CryptoDataService;
public readonly logo: LogoService;
public readonly news: NewsService;
public readonly screener: ScreenerService;
public readonly stocks: StockDataService;
public readonly watchlists: WatchlistsService;
public readonly calendar: Calendar;
public readonly clock: Clock;
public readonly assets: Assets;
public readonly crypto: Crypto;
public readonly logo: Logos;
public readonly news: News;
public readonly screener: Screener;
public readonly stocks: Stocks;
public readonly watchlists: Watchlists;
public readonly account: AccountServices;

constructor(
Expand All @@ -81,14 +93,14 @@ export class Client {
});

this.account = new AccountServices(this.request);
this.watchlists = new WatchlistsService(this.request);
this.calendar = new CalendarService(this.request);
this.clock = new ClockService(this.request);
this.assets = new AssetsService(this.request);
this.crypto = new CryptoDataService(this.request);
this.logo = new LogoService(this.request);
this.news = new NewsService(this.request);
this.screener = new ScreenerService(this.request);
this.stocks = new StockDataService(this.request);
this.watchlists = new Watchlists(this.request);
this.calendar = new Calendar(this.request);
this.clock = new Clock(this.request);
this.assets = new Assets(this.request);
this.crypto = new Crypto(this.request);
this.logo = new Logos(this.request);
this.news = new News(this.request);
this.screener = new Screener(this.request);
this.stocks = new Stocks(this.request);
}
}
25 changes: 0 additions & 25 deletions src/core/AxiosHttpRequest.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/BaseHttpRequest.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/core/OpenAPI.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/models/Account.ts → src/entities/Account.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { AccountStatus } from "./AccountStatus.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* The account configuration API provides custom configurations about your trading account settings. These configurations control various allow you to modify settings to suit your trading needs.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/models/AccountStatus.ts → src/entities/AccountStatus.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* An enum representing the various possible account status values.
*
Expand Down
5 changes: 0 additions & 5 deletions src/models/ActivityType.ts → src/entities/ActivityType.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* - FILL
* Order fills (both partial and full fills)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Append an asset for the symbol to the end of watchlist asset list
*/
Expand Down
5 changes: 0 additions & 5 deletions src/models/AssetClass.ts → src/entities/AssetClass.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Represents what class of asset this is. Currently only supports `us_equity` or `crypto`
*/
Expand Down
5 changes: 0 additions & 5 deletions src/models/Assets.ts → src/entities/Assets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { AssetClass } from "./AssetClass.js";
import type { Exchange } from "./Exchange.js";

Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions src/models/BarsResponse.ts → src/entities/BarsResponse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Bar } from "./Bar.js";

export type BarsResponse = {
Expand Down
5 changes: 0 additions & 5 deletions src/models/Calendar.ts → src/entities/Calendar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type Calendar = {
/**
* Date string in “%Y-%m-%d” format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Represents the result of a request to cancel and order
*/
Expand Down
5 changes: 0 additions & 5 deletions src/models/Clock.ts → src/entities/Clock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type Clock = {
/**
* Current timestamp
Expand Down
5 changes: 0 additions & 5 deletions src/models/Exchange.ts → src/entities/Exchange.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Represents the current exchanges Alpaca supports. List is currently:
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Returns an object representing the exchanges we support. The keys are the short form codes you will see in our responses and the values are their respective full names.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { News } from "./News.js";

export type GetNewsResponse = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Bar } from "./Bar.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Bar } from "./Bar.js";

/**
Expand Down
5 changes: 5 additions & 0 deletions src/entities/LatestMultiQuotesResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Quote } from "./Quote.js";

export type LatestMultiQuotesResponse = {
quotes: Record<string, Quote>;
};
5 changes: 5 additions & 0 deletions src/entities/LatestMultiTradesResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Trade } from "./Trade.js";

export type LatestMultiTradesResponse = {
trades: Record<string, Trade>;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Quote } from "./Quote.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Trade } from "./Trade.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

/**
* Name or source of given news article
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { MarketMoverAsset } from "./MarketMoverAsset.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Bar } from "./Bar.js";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Quote } from "./Quote.js";

/**
Expand Down
Loading

0 comments on commit 8d79a67

Please sign in to comment.