Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,18 @@ const cpsTradesLinks = [
title: 'GET /cps/trades/{id}',
to: '/debug/cps/details',
},
{
title: 'GET /cps/signatures/presign',
to: '/debug/cps/presign',
},
{
title: 'POST /cps/signatures',
to: '/debug/cps/signature',
},
{
title: 'POST /cps/signatures/funding/presign',
to: '/debug/cps/funding-presign',
},
]

const miniVariant = ref(false)
Expand Down
69 changes: 64 additions & 5 deletions lib/cpsTradesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export interface Consideration {
}

export interface PiFXTraderDetails {
recipient: string
recipient?: string
deadline: number
nonce: number
fee: number
consideration: Consideration
}

Expand All @@ -43,6 +44,12 @@ export interface CreatePiFXSignaturePayload {
signature: string
}

export interface FundingPresignPayload {
contractTradeIds: string[]
fundingMode: 'gross' | 'net'
traderType: 'maker' | 'taker'
}

const instance = axios.create({
baseURL: getAPIHostname(),
})
Expand Down Expand Up @@ -72,6 +79,13 @@ instance.interceptors.response.use(
},
)

const nullIfEmpty = (prop: string | undefined) => {
if (prop === '') {
return undefined
}
return prop
}

/** Returns the axios instance */
function getInstance() {
return instance
Expand Down Expand Up @@ -101,17 +115,38 @@ function createTrade(payload: CreateCpsTradePayload) {
/**
* Get CPS Trades
*/
function getTrades() {
return instance.get(CPS_TRADES_PATH)
function getTrades(
startCreateDateInclusive?: string,
endCreateDateInclusive?: string,
statuses?: string,
type?: string,
pageAfter?: string,
pageBefore?: string,
pageSize?: string,
) {
const queryParams = {
startCreateDateInclusive: nullIfEmpty(startCreateDateInclusive),
endCreateDateInclusive: nullIfEmpty(endCreateDateInclusive),
status: nullIfEmpty(statuses),
type: nullIfEmpty(type),
pageAfter: nullIfEmpty(pageAfter),
pageBefore: nullIfEmpty(pageBefore),
pageSize: nullIfEmpty(pageSize),
}

return instance.get(CPS_TRADES_PATH, { params: queryParams })
}

/**
* Get CPS Trade
*/
function getTrade(tradeId: string) {
function getTrade(tradeId: string, type?: string) {
const url = `${CPS_TRADES_PATH}/${tradeId}`
const queryParams = {
type: nullIfEmpty(type),
}

return instance.get(url)
return instance.get(url, { params: queryParams })
}

/**
Expand All @@ -121,11 +156,35 @@ function registerSignature(payload: CreatePiFXSignaturePayload) {
return instance.post(CPS_SIGNATURES_PATH, payload)
}

/**
* Get presign data for signing
*/
function getPresignData(
type: string,
tradeId: string,
recipientAddress?: string,
) {
const url = `/v1/exchange/cps/signatures/presign/${type}/${tradeId}`
const queryParams = recipientAddress ? { recipientAddress } : {}

return instance.get(url, { params: queryParams })
}

/**
* Get funding presign data
*/
function getFundingPresignData(payload: FundingPresignPayload) {
const url = '/v1/exchange/cps/signatures/funding/presign'
return instance.post(url, payload)
}

export default {
getInstance,
createQuote,
createTrade,
getTrades,
getTrade,
registerSignature,
getPresignData,
getFundingPresignData,
}
14 changes: 13 additions & 1 deletion pages/debug/cps/details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
:rules="[required]"
label="CPS Trade ID"
/>
<v-select
v-model="formData.type"
:items="typeOptions"
label="Type (optional)"
clearable
/>
<v-btn
variant="flat"
class="mb-7"
Expand Down Expand Up @@ -43,7 +49,13 @@ const { $cpsTradesApi } = useNuxtApp()
const validForm = ref(false)
const formData = reactive({
tradeId: '',
type: '',
})

const typeOptions = [
{ title: 'Taker', value: 'taker' },
{ title: 'Maker', value: 'maker' },
]
const error = ref<any>({})
const loading = ref(false)
const showError = ref(false)
Expand All @@ -63,7 +75,7 @@ const makeApiCall = async () => {
loading.value = true

try {
await $cpsTradesApi.getTrade(formData.tradeId)
await $cpsTradesApi.getTrade(formData.tradeId, formData.type || undefined)
} catch (err) {
error.value = err
showError.value = true
Expand Down
85 changes: 72 additions & 13 deletions pages/debug/cps/fetch.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
<template>
<v-layout>
<v-container>
<v-row>
<v-col cols="12" md="4">
<v-btn
depressed
class="mb-7"
color="primary"
:loading="loading"
:disabled="loading"
@click.prevent="makeApiCall"
>
Make api call
</v-btn>
<v-form>
<header>Optional filter params:</header>
<v-select
v-model="formData.statuses"
:items="statusOptions"
label="Status"
clearable
/>
<v-select
v-model="formData.type"
:items="typeOptions"
label="Type"
clearable
/>
<v-text-field
v-model="formData.startCreateDateInclusive"
label="Start Create Date (Inclusive)"
/>
<v-text-field
v-model="formData.endCreateDateInclusive"
label="End Create Date (Inclusive)"
/>
<v-text-field v-model="formData.pageSize" label="PageSize" />
<v-text-field v-model="formData.pageBefore" label="PageBefore" />
<v-text-field v-model="formData.pageAfter" label="PageAfter" />
<v-btn
variant="flat"
class="mb-7"
color="primary"
:loading="loading"
:disabled="loading"
@click.prevent="makeApiCall"
>
Make api call
</v-btn>
</v-form>
</v-col>
<v-col cols="12" md="8">
<RequestInfo
Expand All @@ -26,13 +52,38 @@
:show-error="showError"
@on-change="onErrorSheetClosed"
/>
</v-layout>
</v-container>
</template>

<script setup lang="ts">
const store = useMainStore()
const { $cpsTradesApi } = useNuxtApp()

const statusOptions = [
'pending',
'confirmed',
'pending_settlement',
'complete',
'failed',
'terminated',
'breaching',
'breached',
'taker_funded',
'maker_funded',
]

const typeOptions = ['taker', 'maker']

const formData = reactive({
startCreateDateInclusive: '',
endCreateDateInclusive: '',
statuses: '',
type: '',
pageSize: '',
pageBefore: '',
pageAfter: '',
})

const error = ref<any>({})
const loading = ref(false)
const showError = ref(false)
Expand All @@ -49,7 +100,15 @@ const onErrorSheetClosed = () => {
const makeApiCall = async () => {
loading.value = true
try {
await $cpsTradesApi.getTrades()
await $cpsTradesApi.getTrades(
formData.startCreateDateInclusive,
formData.endCreateDateInclusive,
formData.statuses,
formData.type,
formData.pageAfter,
formData.pageBefore,
formData.pageSize,
)
} catch (err) {
error.value = err
showError.value = true
Expand Down
Loading
Loading