-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
867d930
commit 8818753
Showing
28 changed files
with
274 additions
and
1,382 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,5 +65,6 @@ | |
} | ||
}, | ||
"import/extensions": [".ts", ".tsx"] | ||
} | ||
}, | ||
"ignorePatterns": ["dist"] | ||
} |
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,5 @@ | ||
export * from '@/api/public/ticker' | ||
export * from '@/api/public/exchange_rate' | ||
export * from '@/api/public/trades' | ||
export * from '@/api/public/order_books' | ||
export * from '@/api/public/rate' |
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,40 @@ | ||
import fetch from 'node-fetch' | ||
|
||
import { BASE_URL, API_ORDER_BOOKS } from '@/constants/api' | ||
|
||
import type { RequestInit } from 'node-fetch' | ||
|
||
const reciever = (key: string, value: [string, string][]) => { | ||
if ( | ||
key === 'asks' || | ||
(key === 'bids' && Array.isArray(value) && !!value.length) | ||
) { | ||
return value.map((v) => { | ||
const [vv, vvv] = v | ||
return [parseFloat(vv), parseFloat(vvv)] | ||
}) | ||
} | ||
return value | ||
} | ||
|
||
type OrderBooksResponse = { | ||
asks: [number, number][] | ||
bids: [number, number][] | ||
} | ||
|
||
const orderBooks = async (init?: RequestInit): Promise<OrderBooksResponse> => { | ||
const url = new URL(API_ORDER_BOOKS, BASE_URL) | ||
|
||
const res = await fetch(url.toString(), init) | ||
|
||
if (!res.ok) { | ||
throw Error(res.statusText) | ||
} | ||
|
||
const text = await res.text() | ||
|
||
return JSON.parse(text, reciever) | ||
} | ||
|
||
export { orderBooks } | ||
export type { OrderBooksResponse } |
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,55 @@ | ||
import fetch from 'node-fetch' | ||
|
||
import { BASE_URL, API_RATE } from '../../constants/api' | ||
|
||
import { join } from 'path' | ||
|
||
import type { PublicAPI } from '@/shared/types' | ||
import type { Join } from '@/utils/types' | ||
import type { btc, jpy, etc, fct, mona, iost } from 'cryptocurrency-types' | ||
|
||
const ALL_RATE_PAIRS: RatePair[] = [ | ||
'btc_jpy', | ||
'etc_jpy', | ||
'fct_jpy', | ||
'iost_jpy', | ||
'mona_jpy' | ||
] | ||
|
||
type RatePair = | ||
| Join<btc, jpy> | ||
| Join<etc, jpy> | ||
| Join<fct, jpy> | ||
| Join<mona, jpy> | ||
| Join<iost, jpy> | ||
|
||
type RateOptions = { | ||
pair: RatePair | ||
} | ||
|
||
type RateResponse = { | ||
rate: number | ||
} | ||
|
||
const reciever = (key: string, value: unknown) => { | ||
if (key === 'rate' && typeof value === 'string') { | ||
return parseFloat(value) | ||
} | ||
return value | ||
} | ||
|
||
const rate: PublicAPI<RateOptions, RateResponse> = async ({ pair }, init) => { | ||
const url = new URL(join(API_RATE, pair), BASE_URL) | ||
const res = await fetch(url.toString(), init) | ||
|
||
if (!res.ok) { | ||
throw Error(res.statusText) | ||
} | ||
|
||
const text = await res.text() | ||
|
||
return JSON.parse(text, reciever) as RateResponse | ||
} | ||
|
||
export { rate, ALL_RATE_PAIRS } | ||
export type { RateOptions, RateResponse } |
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,73 @@ | ||
import fetch from 'node-fetch' | ||
|
||
import { ALL_EXCHANGE_RATE_PAIRS } from '@/api/public/exchange_rate' | ||
import type { ExchangeRatePair } from '@/api/public/exchange_rate' | ||
import { BASE_URL, API_TRADES } from '@/constants/api' | ||
import { DateRegExp } from '@/utils/regex' | ||
|
||
import type { PublicAPI, OrderType, Order } from '@/shared/types' | ||
|
||
type TradesPair = ExchangeRatePair | ||
|
||
const ALL_TRADES_PAIRS = ALL_EXCHANGE_RATE_PAIRS | ||
|
||
const reciever = (key: string, value: unknown) => { | ||
if ( | ||
key === 'created_at' && | ||
typeof value === 'string' && | ||
value.match(DateRegExp) | ||
) { | ||
return new Date(Date.parse(value)) | ||
} else if ( | ||
(key === 'amount' && typeof value === 'string') || | ||
(key === 'rate' && typeof value === 'string') | ||
) { | ||
return parseFloat(value) | ||
} | ||
|
||
return value | ||
} | ||
|
||
type TradesOptions = { | ||
pair: TradesPair | ||
} | ||
|
||
type TradesResponse = { | ||
success: boolean | ||
pagination: { | ||
limit: number | ||
order: Order | ||
starting_after: null | ||
ending_before: null | ||
} | ||
data: { | ||
id: number | ||
amount: number | ||
rate: number | ||
pair: TradesPair | ||
order_type: OrderType | ||
created_at: Date | ||
}[] | ||
} | ||
|
||
const trades: PublicAPI<TradesOptions, TradesResponse> = async ( | ||
{ pair }, | ||
init | ||
) => { | ||
const url = new URL(API_TRADES, BASE_URL) | ||
|
||
url.search = new URLSearchParams({ | ||
pair | ||
}).toString() | ||
const res = await fetch(url.toString(), init) | ||
|
||
if (!res.ok) { | ||
throw Error(res.statusText) | ||
} | ||
|
||
const text = await res.text() | ||
|
||
return JSON.parse(text, reciever) as TradesResponse | ||
} | ||
|
||
export { trades, ALL_TRADES_PAIRS } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.