-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-511] e2e test for limit order matching (#901)
- Loading branch information
Showing
18 changed files
with
653 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,58 @@ | ||
import { | ||
IPlaceOrder, Order_Side, Order_TimeInForce, OrderFlags, | ||
} from '@dydxprotocol/v4-client-js'; | ||
import Long from 'long'; | ||
|
||
import { OrderDetails } from './types'; | ||
|
||
export const DYDX_LOCAL_ADDRESS = 'dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4'; | ||
export const DYDX_LOCAL_MNEMONIC = 'merge panther lobster crazy road hollow amused security before critic about cliff exhibit cause coyote talent happy where lion river tobacco option coconut small'; | ||
export const DYDX_LOCAL_ADDRESS_2 = 'dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs'; | ||
export const DYDX_LOCAL_MNEMONIC_2 = 'color habit donor nurse dinosaur stable wonder process post perfect raven gold census inside worth inquiry mammal panic olive toss shadow strong name drum'; | ||
|
||
export const MNEMONIC_TO_ADDRESS: Record<string, string> = { | ||
[DYDX_LOCAL_MNEMONIC]: DYDX_LOCAL_ADDRESS, | ||
[DYDX_LOCAL_MNEMONIC_2]: DYDX_LOCAL_ADDRESS_2, | ||
}; | ||
|
||
export const ADDRESS_TO_MNEMONIC: Record<string, string> = { | ||
[DYDX_LOCAL_ADDRESS]: DYDX_LOCAL_MNEMONIC, | ||
[DYDX_LOCAL_ADDRESS_2]: DYDX_LOCAL_MNEMONIC_2, | ||
}; | ||
|
||
export const PERPETUAL_PAIR_BTC_USD: number = 0; | ||
export const quantums: Long = new Long(1_000_000_000); | ||
export const subticks: Long = new Long(1_000_000_000); | ||
|
||
export const defaultOrder: IPlaceOrder = { | ||
clientId: 0, | ||
orderFlags: OrderFlags.SHORT_TERM, | ||
clobPairId: PERPETUAL_PAIR_BTC_USD, | ||
side: Order_Side.SIDE_BUY, | ||
quantums, | ||
subticks, | ||
timeInForce: Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED, | ||
reduceOnly: false, | ||
clientMetadata: 0, | ||
}; | ||
|
||
export const orderDetails: OrderDetails[] = [ | ||
{ | ||
mnemonic: DYDX_LOCAL_MNEMONIC, | ||
timeInForce: 0, | ||
orderFlags: 64, | ||
side: 1, | ||
clobPairId: PERPETUAL_PAIR_BTC_USD, | ||
quantums: 10000000, | ||
subticks: 5000000000, | ||
}, | ||
{ | ||
mnemonic: DYDX_LOCAL_MNEMONIC_2, | ||
timeInForce: 0, | ||
orderFlags: 64, | ||
side: 2, | ||
clobPairId: PERPETUAL_PAIR_BTC_USD, | ||
quantums: 5000000, | ||
subticks: 5000000000, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type OrderDetails = { | ||
mnemonic: string; | ||
timeInForce: number; | ||
orderFlags: number; | ||
side: number; | ||
clobPairId: number; | ||
quantums: number; | ||
subticks: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
import { IPlaceOrder, Network, SocketClient } from '@dydxprotocol/v4-client-js'; | ||
import Long from 'long'; | ||
|
||
import { defaultOrder } from './constants'; | ||
import { OrderDetails } from './types'; | ||
|
||
export async function sleep(milliseconds: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, milliseconds)); | ||
} | ||
|
||
export function createModifiedOrder( | ||
order: OrderDetails, | ||
): IPlaceOrder { | ||
const modifiedOrder: IPlaceOrder = defaultOrder; | ||
modifiedOrder.clientId = Math.floor(Math.random() * 1000000000); | ||
modifiedOrder.goodTilBlock = 0; | ||
modifiedOrder.clobPairId = order.clobPairId; | ||
modifiedOrder.timeInForce = order.timeInForce; | ||
modifiedOrder.reduceOnly = false; | ||
modifiedOrder.orderFlags = order.orderFlags; | ||
modifiedOrder.side = order.side; | ||
modifiedOrder.quantums = Long.fromNumber(order.quantums); | ||
modifiedOrder.subticks = Long.fromNumber(order.subticks); | ||
return modifiedOrder; | ||
} | ||
|
||
export function connectAndValidateSocketClient(validateMessage: Function): void { | ||
const mySocket = new SocketClient( | ||
Network.local().indexerConfig, | ||
() => {}, | ||
() => {}, | ||
(message) => { | ||
if (typeof message.data === 'string') { | ||
const data = JSON.parse(message.data as string); | ||
validateMessage(data, mySocket); | ||
} | ||
}, | ||
); | ||
mySocket.connect(); | ||
} |
Oops, something went wrong.