Skip to content

Commit

Permalink
Crypto contract test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Mar 9, 2024
1 parent 8a93d4f commit e6fb5b9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/api/contract/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import SecType from "../data/enum/sec-type";
import { Contract } from "./contract";

/**
* Crypto contract.
*/
export class Crypto implements Contract {
constructor(
public symbol: string,
public exchange?: string,
public currency?: string,
) {
this.currency = this.currency ?? "USD";
this.exchange = this.exchange ?? "SMART";
}

public secType = SecType.CRYPTO;
}

export default Crypto;
27 changes: 23 additions & 4 deletions src/tests/unit/api-next-live/get-contract-details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Subscription } from "rxjs";
import { IBApiNext, IBApiNextError } from "../../..";
import {
sample_bond,
sample_future,
sample_crypto,
sample_option,
sample_stock,
} from "../contracts";
Expand Down Expand Up @@ -71,13 +71,13 @@ describe("ApiNext: getContractDetails()", () => {

test("Future contract details", (done) => {
api
.getContractDetails(sample_future)
.getContractDetails(sample_crypto)
.then((result) => {
// console.log(result);
expect(result.length).toBeGreaterThan(0);
if (result.length) {
expect(result[0].contract.symbol).toEqual(sample_future.symbol);
expect(result[0].contract.secType).toEqual(sample_future.secType);
expect(result[0].contract.symbol).toEqual(sample_crypto.symbol);
expect(result[0].contract.secType).toEqual(sample_crypto.secType);
}
done();
})
Expand Down Expand Up @@ -124,4 +124,23 @@ describe("ApiNext: getContractDetails()", () => {
);
});
});

test("Crypto contract details", (done) => {
api
.getContractDetails(sample_crypto)
.then((result) => {
// console.log(result);
expect(result.length).toBeGreaterThan(0);
if (result.length) {
expect(result[0].contract.symbol).toEqual(sample_crypto.symbol);
expect(result[0].contract.secType).toEqual(sample_crypto.secType);
}
done();
})
.catch((err: IBApiNextError) => {
done(
`getContractDetails failed with '${err.error.message}' (Error #${err.code})`,
);
});
});
});
2 changes: 2 additions & 0 deletions src/tests/unit/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OptionType,
Stock,
} from "../..";
import Crypto from "../../api/contract/crypto";

export const sample_stock: Contract = new Stock("AAPL");
export const sample_etf: Contract = new Stock("SPY");
Expand All @@ -29,3 +30,4 @@ export const sample_option: Contract = new Option(
export const sample_bond: Contract = new Bond("912828C57");
export const sample_index: Contract = new Index("ES", "USD");
export const sample_dax_index: Contract = new Index("DAX", "EUR", "EUREX");
export const sample_crypto: Contract = new Crypto("BTC");

0 comments on commit e6fb5b9

Please sign in to comment.