@dydxprotocol/solo
Advanced tools
Comparing version 0.14.0 to 0.14.1
@@ -1,2 +0,2 @@ | ||
import { address, Integer, ApiOrder, ApiAccount, ApiFill } from '../types'; | ||
import { address, Integer, ApiOrder, ApiAccount, ApiFill, ApiTrade } from '../types'; | ||
import { LimitOrders } from './LimitOrders'; | ||
@@ -7,3 +7,3 @@ export declare class Api { | ||
constructor(limitOrders: LimitOrders, endpoint?: string); | ||
placeOrder({ makerAccountOwner, makerMarket, takerMarket, makerAmount, takerAmount, makerAccountNumber, expiration, fillOrKill, }: { | ||
placeOrder({ makerAccountOwner, makerMarket, takerMarket, makerAmount, takerAmount, makerAccountNumber, expiration, fillOrKill, clientId, }: { | ||
makerAccountOwner: address; | ||
@@ -17,2 +17,3 @@ makerAccountNumber: Integer | string; | ||
fillOrKill: boolean; | ||
clientId?: string; | ||
}): Promise<{ | ||
@@ -36,6 +37,11 @@ order: ApiOrder; | ||
}>; | ||
getOrder({ id, }: { | ||
id: string; | ||
}): Promise<{ | ||
order: ApiOrder; | ||
}>; | ||
getFills({ makerAccountOwner, startingBefore, limit, pairs, makerAccountNumber, }: { | ||
makerAccountOwner: address; | ||
makerAccountOwner?: address; | ||
startingBefore?: Date; | ||
limit: number; | ||
limit?: number; | ||
pairs?: string[]; | ||
@@ -46,2 +52,11 @@ makerAccountNumber?: Integer | string; | ||
}>; | ||
getTrades({ makerAccountOwner, startingBefore, limit, pairs, makerAccountNumber, }: { | ||
makerAccountOwner?: address; | ||
startingBefore?: Date; | ||
limit?: number; | ||
pairs?: string[]; | ||
makerAccountNumber?: Integer | string; | ||
}): Promise<{ | ||
trades: ApiTrade; | ||
}>; | ||
getAccountBalances({ accountOwner, accountNumber, }: { | ||
@@ -48,0 +63,0 @@ accountOwner: address; |
@@ -44,2 +44,3 @@ "use strict"; | ||
var query_string_1 = __importDefault(require("query-string")); | ||
var lodash_1 = require("lodash"); | ||
var types_1 = require("../types"); | ||
@@ -57,5 +58,5 @@ var FOUR_WEEKS_IN_SECONDS = 60 * 60 * 24 * 28; | ||
Api.prototype.placeOrder = function (_a) { | ||
var makerAccountOwner = _a.makerAccountOwner, makerMarket = _a.makerMarket, takerMarket = _a.takerMarket, makerAmount = _a.makerAmount, takerAmount = _a.takerAmount, _b = _a.makerAccountNumber, makerAccountNumber = _b === void 0 ? new bignumber_js_1.default(0) : _b, _c = _a.expiration, expiration = _c === void 0 ? new bignumber_js_1.default(FOUR_WEEKS_IN_SECONDS) : _c, _d = _a.fillOrKill, fillOrKill = _d === void 0 ? false : _d; | ||
var makerAccountOwner = _a.makerAccountOwner, makerMarket = _a.makerMarket, takerMarket = _a.takerMarket, makerAmount = _a.makerAmount, takerAmount = _a.takerAmount, _b = _a.makerAccountNumber, makerAccountNumber = _b === void 0 ? new bignumber_js_1.default(0) : _b, _c = _a.expiration, expiration = _c === void 0 ? new bignumber_js_1.default(FOUR_WEEKS_IN_SECONDS) : _c, _d = _a.fillOrKill, fillOrKill = _d === void 0 ? false : _d, clientId = _a.clientId; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var realExpiration, order, typedSignature, jsonOrder; | ||
var realExpiration, order, typedSignature, jsonOrder, body; | ||
return __generator(this, function (_e) { | ||
@@ -95,10 +96,12 @@ switch (_e.label) { | ||
}; | ||
body = { | ||
fillOrKill: fillOrKill, | ||
clientId: clientId, | ||
order: jsonOrder, | ||
}; | ||
return [2 /*return*/, request_promise_native_1.default({ | ||
body: lodash_1.omit(body, lodash_1.isUndefined), | ||
uri: this.endpoint + "/v1/dex/orders", | ||
method: 'POST', | ||
json: true, | ||
body: { | ||
fillOrKill: fillOrKill, | ||
order: jsonOrder, | ||
}, | ||
})]; | ||
@@ -163,2 +166,14 @@ } | ||
}; | ||
Api.prototype.getOrder = function (_a) { | ||
var id = _a.id; | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, request_promise_native_1.default({ | ||
uri: this.endpoint + "/v1/dex/orders/" + id, | ||
method: 'GET', | ||
json: true, | ||
})]; | ||
}); | ||
}); | ||
}; | ||
Api.prototype.getFills = function (_a) { | ||
@@ -194,2 +209,32 @@ var makerAccountOwner = _a.makerAccountOwner, startingBefore = _a.startingBefore, limit = _a.limit, pairs = _a.pairs, makerAccountNumber = _a.makerAccountNumber; | ||
}; | ||
Api.prototype.getTrades = function (_a) { | ||
var makerAccountOwner = _a.makerAccountOwner, startingBefore = _a.startingBefore, limit = _a.limit, pairs = _a.pairs, makerAccountNumber = _a.makerAccountNumber; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var queryObj, query; | ||
return __generator(this, function (_b) { | ||
queryObj = { makerAccountOwner: makerAccountOwner }; | ||
if (startingBefore) { | ||
queryObj.startingBefore = startingBefore.toISOString(); | ||
} | ||
if (limit) { | ||
queryObj.limit = limit; | ||
} | ||
if (pairs) { | ||
queryObj.pairs = pairs.join(); | ||
} | ||
if (makerAccountNumber) { | ||
queryObj.makerAccountNumber = new bignumber_js_1.default(makerAccountNumber).toFixed(0); | ||
} | ||
else { | ||
queryObj.makerAccountNumber = '0'; | ||
} | ||
query = query_string_1.default.stringify(queryObj); | ||
return [2 /*return*/, request_promise_native_1.default({ | ||
uri: this.endpoint + "/v1/dex/trades?" + query, | ||
method: 'GET', | ||
json: true, | ||
})]; | ||
}); | ||
}); | ||
}; | ||
Api.prototype.getAccountBalances = function (_a) { | ||
@@ -196,0 +241,0 @@ var accountOwner = _a.accountOwner, _b = _a.accountNumber, accountNumber = _b === void 0 ? new bignumber_js_1.default(0) : _b; |
@@ -425,2 +425,10 @@ import BigNumber from 'bignumber.js'; | ||
} | ||
export interface ApiTrade extends ApiModel { | ||
status: ApiFillStatus; | ||
transactionHash: string; | ||
makerOrder: ApiOrder; | ||
makerOrderId: string; | ||
takerOrder: ApiOrder; | ||
takerOrderId: string; | ||
} | ||
interface ApiModel { | ||
@@ -427,0 +435,0 @@ uuid: string; |
{ | ||
"name": "@dydxprotocol/solo", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"description": "Ethereum Smart Contracts and TypeScript library used for the dYdX Solo-Margin Trading Protocol", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
import request from 'request-promise-native'; | ||
import BigNumber from 'bignumber.js'; | ||
import queryString from 'query-string'; | ||
import { omit, isUndefined } from 'lodash'; | ||
import { | ||
@@ -12,2 +13,3 @@ LimitOrder, | ||
ApiFill, | ||
ApiTrade, | ||
} from '../types'; | ||
@@ -42,2 +44,3 @@ import { LimitOrders } from './LimitOrders'; | ||
fillOrKill = false, | ||
clientId, | ||
}: { | ||
@@ -52,2 +55,3 @@ makerAccountOwner: address, | ||
fillOrKill: boolean, | ||
clientId?: string, | ||
}): Promise<{ order: ApiOrder }> { | ||
@@ -90,10 +94,13 @@ const realExpiration = new BigNumber(expiration).eq(0) ? | ||
const body = { | ||
fillOrKill, | ||
clientId, | ||
order: jsonOrder, | ||
}; | ||
return request({ | ||
body: omit(body, isUndefined), | ||
uri: `${this.endpoint}/v1/dex/orders`, | ||
method: 'POST', | ||
json: true, | ||
body: { | ||
fillOrKill, | ||
order: jsonOrder, | ||
}, | ||
}); | ||
@@ -168,2 +175,14 @@ } | ||
public async getOrder({ | ||
id, | ||
}: { | ||
id: string, | ||
}): Promise<{ order: ApiOrder }> { | ||
return request({ | ||
uri: `${this.endpoint}/v1/dex/orders/${id}`, | ||
method: 'GET', | ||
json: true, | ||
}); | ||
} | ||
public async getFills({ | ||
@@ -176,5 +195,5 @@ makerAccountOwner, | ||
}: { | ||
makerAccountOwner: address, | ||
makerAccountOwner?: address, | ||
startingBefore?: Date, | ||
limit: number, | ||
limit?: number, | ||
pairs?: string[], | ||
@@ -209,2 +228,41 @@ makerAccountNumber?: Integer | string, | ||
public async getTrades({ | ||
makerAccountOwner, | ||
startingBefore, | ||
limit, | ||
pairs, | ||
makerAccountNumber, | ||
}: { | ||
makerAccountOwner?: address, | ||
startingBefore?: Date, | ||
limit?: number, | ||
pairs?: string[], | ||
makerAccountNumber?: Integer | string, | ||
}): Promise<{ trades: ApiTrade }> { | ||
const queryObj: any = { makerAccountOwner }; | ||
if (startingBefore) { | ||
queryObj.startingBefore = startingBefore.toISOString(); | ||
} | ||
if (limit) { | ||
queryObj.limit = limit; | ||
} | ||
if (pairs) { | ||
queryObj.pairs = pairs.join(); | ||
} | ||
if (makerAccountNumber) { | ||
queryObj.makerAccountNumber = new BigNumber(makerAccountNumber).toFixed(0); | ||
} else { | ||
queryObj.makerAccountNumber = '0'; | ||
} | ||
const query: string = queryString.stringify(queryObj); | ||
return request({ | ||
uri: `${this.endpoint}/v1/dex/trades?${query}`, | ||
method: 'GET', | ||
json: true, | ||
}); | ||
} | ||
public async getAccountBalances({ | ||
@@ -211,0 +269,0 @@ accountOwner, |
@@ -521,2 +521,11 @@ /* | ||
export interface ApiTrade extends ApiModel { | ||
status: ApiFillStatus; | ||
transactionHash: string; | ||
makerOrder: ApiOrder; | ||
makerOrderId: string; | ||
takerOrder: ApiOrder; | ||
takerOrderId: string; | ||
} | ||
interface ApiModel { | ||
@@ -523,0 +532,0 @@ uuid: string; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2215257
41974