Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neg Risk Flag Resolution #119

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build:
@echo "Building ts code..."
rm -rf dist
tsc --module commonjs
yarn tsc --module commonjs

.PHONY: test
test:
Expand Down
21 changes: 20 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
MarketReward,
UserRewardsEarning,
TotalUserEarning,
NegRisk,
} from "./types";
import { createL1Headers, createL2Headers } from "./headers";
import {
Expand Down Expand Up @@ -83,6 +84,7 @@ import {
GET_BALANCE_ALLOWANCE,
IS_ORDER_SCORING,
GET_TICK_SIZE,
GET_NEG_RISK,
ARE_ORDERS_SCORING,
GET_SIMPLIFIED_MARKETS,
GET_SAMPLING_SIMPLIFIED_MARKETS,
Expand Down Expand Up @@ -121,6 +123,8 @@ export class ClobClient {

readonly tickSizes: TickSizes;

readonly negRisk: NegRisk;

readonly geoBlockToken?: string;

constructor(
Expand Down Expand Up @@ -148,6 +152,7 @@ export class ClobClient {
funderAddress,
);
this.tickSizes = {};
this.negRisk = {};
this.geoBlockToken = geoBlockToken;
}

Expand Down Expand Up @@ -215,6 +220,19 @@ export class ClobClient {
return this.tickSizes[tokenID];
}

public async getNegRisk(tokenID: string): Promise<boolean> {
if (tokenID in this.negRisk) {
return this.negRisk[tokenID];
}

const result = await this.get(`${this.host}${GET_NEG_RISK}`, {
params: { token_id: tokenID },
});
this.negRisk[tokenID] = result.neg_risk as boolean;

return this.negRisk[tokenID];
}

/**
* Calculates the hash for the given orderbook
* @param orderbook
Expand Down Expand Up @@ -524,7 +542,6 @@ export class ClobClient {
const { tokenID } = userOrder;

const tickSize = await this._resolveTickSize(tokenID, options?.tickSize);
const negRisk = options?.negRisk ?? false;

if (!priceValid(userOrder.price, tickSize)) {
throw new Error(
Expand All @@ -534,6 +551,8 @@ export class ClobClient {
);
}

const negRisk = options?.negRisk ?? await this.getNegRisk(tokenID);
poly-rodr marked this conversation as resolved.
Show resolved Hide resolved

return this.orderBuilder.buildOrder(userOrder, {
tickSize,
negRisk,
Expand Down
1 change: 1 addition & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const GET_SPREADS = "/spreads";
export const GET_LAST_TRADE_PRICE = "/last-trade-price";
export const GET_LAST_TRADES_PRICES = "/last-trades-prices";
export const GET_TICK_SIZE = "/tick-size";
export const GET_NEG_RISK = "/neg-risk";

// Order endpoints
export const POST_ORDER = "/order";
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ export interface TickSizes {
[tokenId: string]: TickSize;
}

export interface NegRisk {
[tokenId: string]: boolean;
}

export interface PaginationPayload {
readonly limit: number;
readonly count: number;
Expand Down
Loading