@0xtorch/csv 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/.DS_Store +0 -0
  2. package/_cjs/formatCsvRows.js +67 -0
  3. package/_cjs/formatCsvRows.js.map +1 -0
  4. package/_cjs/index.js +12 -0
  5. package/_cjs/index.js.map +1 -0
  6. package/_cjs/package.json +1 -0
  7. package/_cjs/parseCsvFileToAccountActions.js +26 -0
  8. package/_cjs/parseCsvFileToAccountActions.js.map +1 -0
  9. package/_cjs/parseCsvFileToText.js +15 -0
  10. package/_cjs/parseCsvFileToText.js.map +1 -0
  11. package/_cjs/parseCsvRowToNormalAction/asset.js +62 -0
  12. package/_cjs/parseCsvRowToNormalAction/asset.js.map +1 -0
  13. package/_cjs/parseCsvRowToNormalAction/condition.js +32 -0
  14. package/_cjs/parseCsvRowToNormalAction/condition.js.map +1 -0
  15. package/_cjs/parseCsvRowToNormalAction/index.js +6 -0
  16. package/_cjs/parseCsvRowToNormalAction/index.js.map +1 -0
  17. package/_cjs/parseCsvRowToNormalAction/nft.js +15 -0
  18. package/_cjs/parseCsvRowToNormalAction/nft.js.map +1 -0
  19. package/_cjs/parseCsvRowToNormalAction/parseCsvRowToNormalAction.js +83 -0
  20. package/_cjs/parseCsvRowToNormalAction/parseCsvRowToNormalAction.js.map +1 -0
  21. package/_cjs/parseCsvRowToNormalAction/text.js +31 -0
  22. package/_cjs/parseCsvRowToNormalAction/text.js.map +1 -0
  23. package/_cjs/parseCsvRowToNormalAction/timestamp.js +12 -0
  24. package/_cjs/parseCsvRowToNormalAction/timestamp.js.map +1 -0
  25. package/_cjs/parseCsvRowToNormalAction/transfer.js +29 -0
  26. package/_cjs/parseCsvRowToNormalAction/transfer.js.map +1 -0
  27. package/_cjs/parseCsvRowsToAccountActions.js +49 -0
  28. package/_cjs/parseCsvRowsToAccountActions.js.map +1 -0
  29. package/_cjs/parseCsvText.js +15 -0
  30. package/_cjs/parseCsvText.js.map +1 -0
  31. package/_cjs/schemas/formatter.js +15 -0
  32. package/_cjs/schemas/formatter.js.map +1 -0
  33. package/_cjs/schemas/formatterTypes.js +37 -0
  34. package/_cjs/schemas/formatterTypes.js.map +1 -0
  35. package/_cjs/schemas/index.js +6 -0
  36. package/_cjs/schemas/index.js.map +1 -0
  37. package/_cjs/schemas/parser.js +80 -0
  38. package/_cjs/schemas/parser.js.map +1 -0
  39. package/_cjs/schemas/schemas.js +14 -0
  40. package/_cjs/schemas/schemas.js.map +1 -0
  41. package/_cjs/types.js +3 -0
  42. package/_cjs/types.js.map +1 -0
  43. package/_esm/formatCsvRows.js +67 -0
  44. package/_esm/formatCsvRows.js.map +1 -0
  45. package/_esm/index.js +5 -0
  46. package/_esm/index.js.map +1 -0
  47. package/_esm/package.json +1 -0
  48. package/_esm/parseCsvFileToAccountActions.js +22 -0
  49. package/_esm/parseCsvFileToAccountActions.js.map +1 -0
  50. package/_esm/parseCsvFileToText.js +11 -0
  51. package/_esm/parseCsvFileToText.js.map +1 -0
  52. package/_esm/parseCsvRowToNormalAction/asset.js +58 -0
  53. package/_esm/parseCsvRowToNormalAction/asset.js.map +1 -0
  54. package/_esm/parseCsvRowToNormalAction/condition.js +28 -0
  55. package/_esm/parseCsvRowToNormalAction/condition.js.map +1 -0
  56. package/_esm/parseCsvRowToNormalAction/index.js +2 -0
  57. package/_esm/parseCsvRowToNormalAction/index.js.map +1 -0
  58. package/_esm/parseCsvRowToNormalAction/nft.js +11 -0
  59. package/_esm/parseCsvRowToNormalAction/nft.js.map +1 -0
  60. package/_esm/parseCsvRowToNormalAction/parseCsvRowToNormalAction.js +81 -0
  61. package/_esm/parseCsvRowToNormalAction/parseCsvRowToNormalAction.js.map +1 -0
  62. package/_esm/parseCsvRowToNormalAction/text.js +27 -0
  63. package/_esm/parseCsvRowToNormalAction/text.js.map +1 -0
  64. package/_esm/parseCsvRowToNormalAction/timestamp.js +8 -0
  65. package/_esm/parseCsvRowToNormalAction/timestamp.js.map +1 -0
  66. package/_esm/parseCsvRowToNormalAction/transfer.js +25 -0
  67. package/_esm/parseCsvRowToNormalAction/transfer.js.map +1 -0
  68. package/_esm/parseCsvRowsToAccountActions.js +47 -0
  69. package/_esm/parseCsvRowsToAccountActions.js.map +1 -0
  70. package/_esm/parseCsvText.js +11 -0
  71. package/_esm/parseCsvText.js.map +1 -0
  72. package/_esm/schemas/formatter.js +12 -0
  73. package/_esm/schemas/formatter.js.map +1 -0
  74. package/_esm/schemas/formatterTypes.js +35 -0
  75. package/_esm/schemas/formatterTypes.js.map +1 -0
  76. package/_esm/schemas/index.js +2 -0
  77. package/_esm/schemas/index.js.map +1 -0
  78. package/_esm/schemas/parser.js +100 -0
  79. package/_esm/schemas/parser.js.map +1 -0
  80. package/_esm/schemas/schemas.js +11 -0
  81. package/_esm/schemas/schemas.js.map +1 -0
  82. package/_esm/types.js +2 -0
  83. package/_esm/types.js.map +1 -0
  84. package/_types/formatCsvRows.d.ts +11 -0
  85. package/_types/formatCsvRows.d.ts.map +1 -0
  86. package/_types/index.d.ts +6 -0
  87. package/_types/index.d.ts.map +1 -0
  88. package/_types/parseCsvFileToAccountActions.d.ts +12 -0
  89. package/_types/parseCsvFileToAccountActions.d.ts.map +1 -0
  90. package/_types/parseCsvFileToText.d.ts +2 -0
  91. package/_types/parseCsvFileToText.d.ts.map +1 -0
  92. package/_types/parseCsvRowToNormalAction/asset.d.ts +17 -0
  93. package/_types/parseCsvRowToNormalAction/asset.d.ts.map +1 -0
  94. package/_types/parseCsvRowToNormalAction/condition.d.ts +10 -0
  95. package/_types/parseCsvRowToNormalAction/condition.d.ts.map +1 -0
  96. package/_types/parseCsvRowToNormalAction/index.d.ts +2 -0
  97. package/_types/parseCsvRowToNormalAction/index.d.ts.map +1 -0
  98. package/_types/parseCsvRowToNormalAction/nft.d.ts +12 -0
  99. package/_types/parseCsvRowToNormalAction/nft.d.ts.map +1 -0
  100. package/_types/parseCsvRowToNormalAction/parseCsvRowToNormalAction.d.ts +20 -0
  101. package/_types/parseCsvRowToNormalAction/parseCsvRowToNormalAction.d.ts.map +1 -0
  102. package/_types/parseCsvRowToNormalAction/text.d.ts +11 -0
  103. package/_types/parseCsvRowToNormalAction/text.d.ts.map +1 -0
  104. package/_types/parseCsvRowToNormalAction/timestamp.d.ts +8 -0
  105. package/_types/parseCsvRowToNormalAction/timestamp.d.ts.map +1 -0
  106. package/_types/parseCsvRowToNormalAction/transfer.d.ts +18 -0
  107. package/_types/parseCsvRowToNormalAction/transfer.d.ts.map +1 -0
  108. package/_types/parseCsvRowsToAccountActions.d.ts +16 -0
  109. package/_types/parseCsvRowsToAccountActions.d.ts.map +1 -0
  110. package/_types/parseCsvText.d.ts +4 -0
  111. package/_types/parseCsvText.d.ts.map +1 -0
  112. package/_types/schemas/formatter.d.ts +4 -0
  113. package/_types/schemas/formatter.d.ts.map +1 -0
  114. package/_types/schemas/formatterTypes.d.ts +10 -0
  115. package/_types/schemas/formatterTypes.d.ts.map +1 -0
  116. package/_types/schemas/index.d.ts +2 -0
  117. package/_types/schemas/index.d.ts.map +1 -0
  118. package/_types/schemas/parser.d.ts +1505 -0
  119. package/_types/schemas/parser.d.ts.map +1 -0
  120. package/_types/schemas/schemas.d.ts +806 -0
  121. package/_types/schemas/schemas.d.ts.map +1 -0
  122. package/_types/types.d.ts +13 -0
  123. package/_types/types.d.ts.map +1 -0
  124. package/formatCsvRows.ts +97 -0
  125. package/index.ts +5 -0
  126. package/package.json +50 -0
  127. package/parseCsvFileToAccountActions.ts +40 -0
  128. package/parseCsvFileToText.ts +11 -0
  129. package/parseCsvRowToNormalAction/asset.ts +92 -0
  130. package/parseCsvRowToNormalAction/condition.ts +39 -0
  131. package/parseCsvRowToNormalAction/index.ts +1 -0
  132. package/parseCsvRowToNormalAction/nft.ts +27 -0
  133. package/parseCsvRowToNormalAction/parseCsvRowToNormalAction.ts +146 -0
  134. package/parseCsvRowToNormalAction/text.ts +37 -0
  135. package/parseCsvRowToNormalAction/timestamp.ts +19 -0
  136. package/parseCsvRowToNormalAction/transfer.ts +55 -0
  137. package/parseCsvRowsToAccountActions.ts +67 -0
  138. package/parseCsvText.ts +14 -0
  139. package/schemas/formatter.ts +13 -0
  140. package/schemas/formatterTypes.ts +44 -0
  141. package/schemas/index.ts +1 -0
  142. package/schemas/parser.ts +110 -0
  143. package/schemas/schemas.ts +11 -0
  144. package/tests/assets.ts +28 -0
  145. package/tests/coincheck-standard.csv +17 -0
  146. package/tests/coincheck.ts +137 -0
  147. package/types.ts +17 -0
@@ -0,0 +1,67 @@
1
+ import { greaterThan } from '@0xtorch/big-decimal'
2
+ import type { AccountAction, CryptoCurrency, FiatCurrency } from '@0xtorch/core'
3
+ import { parseNormalActionToAccountActions } from '@0xtorch/core'
4
+ import { parseCsvRowToNormalAction } from './parseCsvRowToNormalAction'
5
+ import type { FormattedRow, Parser } from './types'
6
+
7
+ type ParseCsvRowsToAccountActionsParameters = {
8
+ readonly rows: readonly FormattedRow[]
9
+ readonly service: string
10
+ readonly parsers: readonly Parser[]
11
+ readonly symbolAssetMap: { [symbol: string]: string } | undefined
12
+ readonly accountId: string
13
+ readonly cryptoCurrencies: readonly CryptoCurrency[]
14
+ readonly fiatCurrencies: readonly FiatCurrency[]
15
+ }
16
+
17
+ export const parseCsvRowsToAccountActions = ({
18
+ rows,
19
+ service,
20
+ parsers,
21
+ symbolAssetMap,
22
+ accountId,
23
+ cryptoCurrencies,
24
+ fiatCurrencies,
25
+ }: ParseCsvRowsToAccountActionsParameters): readonly AccountAction[] => {
26
+ // marketCap で降順 sort
27
+ const sortedCryptoCurrencies = cryptoCurrencies.toSorted((a, b) => {
28
+ if (a.market.marketCapUsd === undefined) {
29
+ return -1
30
+ }
31
+ if (b.market.marketCapUsd === undefined) {
32
+ return 1
33
+ }
34
+ return greaterThan(a.market.marketCapUsd, b.market.marketCapUsd) ? -1 : 1
35
+ })
36
+ const actions = rows.flatMap((row) => {
37
+ const result = parseCsvRowToNormalAction({
38
+ row,
39
+ service,
40
+ parsers,
41
+ symbolAssetMap,
42
+ accountId,
43
+ cryptoCurrencies: sortedCryptoCurrencies,
44
+ fiatCurrencies,
45
+ })
46
+ if (result === undefined) {
47
+ // TODO action が生成できなかった行を記録したい
48
+ return []
49
+ }
50
+ const { action, source } = result
51
+ return parseNormalActionToAccountActions({
52
+ action,
53
+ accountIds: new Set([accountId]),
54
+ source,
55
+ })
56
+ })
57
+ const mut_sources: string[] = []
58
+ const mut_actions: AccountAction[] = []
59
+ for (const action of actions) {
60
+ mut_actions.push({
61
+ ...action,
62
+ order: mut_sources.filter((source) => source === action.source).length,
63
+ })
64
+ mut_sources.push(action.source)
65
+ }
66
+ return mut_actions
67
+ }
@@ -0,0 +1,14 @@
1
+ import { parse } from 'papaparse'
2
+ import { z } from 'zod'
3
+
4
+ const schema = z.record(z.string())
5
+
6
+ export const parseCsvText = (
7
+ text: string,
8
+ ): readonly { [key: string]: string }[] => {
9
+ const result = parse(text, {
10
+ header: true,
11
+ skipEmptyLines: true,
12
+ })
13
+ return result.data.map((row) => schema.parse(row))
14
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod'
2
+
3
+ export const formatterValueTypeSchema = z.union([
4
+ z.literal('blank'),
5
+ z.literal('string'),
6
+ z.literal('big-decimal'),
7
+ z.literal('big-decimal-positive'),
8
+ z.literal('big-decimal-negative'),
9
+ z.literal('iso8601'),
10
+ z.literal('datetime-jp'),
11
+ ])
12
+
13
+ export const formatterSchema = z.record(z.array(formatterValueTypeSchema))
@@ -0,0 +1,44 @@
1
+ import { createBigDecimal } from '@0xtorch/big-decimal'
2
+ import { z } from 'zod'
3
+
4
+ export const blankTextSchema = z.literal('').transform(() => undefined)
5
+
6
+ export const stringTextSchema = z.string()
7
+
8
+ export const bigDecimalTextSchema = z
9
+ .string()
10
+ .regex(/^-?\d+(\.\d+)?$/)
11
+ .transform((v) => createBigDecimal(v))
12
+
13
+ export const bigDecimalPositiveTextSchema = z
14
+ .string()
15
+ .regex(/^\d+(\.\d+)?$/)
16
+ .transform((v) => createBigDecimal(v))
17
+
18
+ export const bigDecimalNegativeTextSchema = z
19
+ .string()
20
+ .regex(/^-\d+(\.\d+)?$/)
21
+ .transform((v) => createBigDecimal(v))
22
+
23
+ export const iso8601TextSchema = z
24
+ .string()
25
+ .regex(
26
+ /^\d{4}-?\d\d-?\d\d(?:(T|( ))\d\d(?::?\d\d(?::?\d\d(?:\.\d+)?)?)?( )?(?:Z|[+-]\d\d:?\d\d)?)?$/,
27
+ )
28
+ .transform((v) => new Date(v).getTime())
29
+
30
+ // TODO timezone 追加型 date を導入する
31
+ export const datetimeJpTextSchema = z
32
+ .string()
33
+ .regex(/^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}$/)
34
+ .transform((v) => new Date(`${v}+09:00`).getTime())
35
+
36
+ export const formatterValueSchema = z.union([
37
+ blankTextSchema,
38
+ stringTextSchema,
39
+ bigDecimalTextSchema,
40
+ bigDecimalPositiveTextSchema,
41
+ bigDecimalNegativeTextSchema,
42
+ iso8601TextSchema,
43
+ datetimeJpTextSchema,
44
+ ])
@@ -0,0 +1 @@
1
+ export { csvFormatSchema } from './schemas'
@@ -0,0 +1,110 @@
1
+ import { normalActionActionSchema } from '@0xtorch/core'
2
+ import { z } from 'zod'
3
+
4
+ export const conditionComponentSchema = z.object({
5
+ column: z.string(),
6
+ pattern: z.union([
7
+ // string
8
+ z.string(),
9
+ // number
10
+ z.number(),
11
+ // defined
12
+ z.object({
13
+ type: z.literal('defined'),
14
+ }),
15
+ // undefined
16
+ z.object({
17
+ type: z.literal('undefined'),
18
+ }),
19
+ // in
20
+ z.object({
21
+ type: z.literal('in'),
22
+ values: z.array(z.union([z.string(), z.number()])),
23
+ }),
24
+ // not-in
25
+ z.object({
26
+ type: z.literal('not-in'),
27
+ values: z.array(z.union([z.string(), z.number()])),
28
+ }),
29
+ ]),
30
+ })
31
+
32
+ export const columnComponentSchema = z.object({
33
+ type: z.literal('column'),
34
+ column: z.string(),
35
+ })
36
+
37
+ export const actionComponentSchema = z.object({
38
+ column: z.string(),
39
+ patterns: z.record(normalActionActionSchema),
40
+ })
41
+
42
+ const serviceComponentSchema = z.object({
43
+ type: z.literal('service'),
44
+ })
45
+
46
+ export const textComponentSchema = z.union([
47
+ // premitive string
48
+ z.string(),
49
+ // service
50
+ serviceComponentSchema,
51
+ // column
52
+ columnComponentSchema,
53
+ ])
54
+
55
+ export const nftComponentSchema = z.object({
56
+ type: z.literal('nft'),
57
+ id: z.array(textComponentSchema),
58
+ })
59
+
60
+ export const assetComponentSchema = z.union([
61
+ // asset id を直接指定
62
+ z.object({
63
+ type: z.literal('custom'),
64
+ assetType: z.union([
65
+ z.literal('CryptoCurrency'),
66
+ z.literal('FiatCurrency'),
67
+ z.literal('Nft'),
68
+ ]),
69
+ assetId: z.string(),
70
+ }),
71
+ // column と一致する symbol を持つ時価総額最大の asset
72
+ columnComponentSchema,
73
+ // nft
74
+ nftComponentSchema,
75
+ ])
76
+
77
+ export const transferComponentSchema = z.object({
78
+ direction: z.union([z.literal('in'), z.literal('out')]),
79
+ // TODO column を指定して値を決定する / 絶対値で値を受け取るようにする
80
+ amount: z.string(),
81
+ // TODO column を指定して値を決定する / 原則symbolが一致する時価総額最大の asset を選択する
82
+ // TODO 別途 symbol と asset の対応表に存在する symbol であればそちらを優先する
83
+ asset: assetComponentSchema,
84
+ })
85
+
86
+ // 同一の row でも、 action type によって処理が変わるのでは?
87
+ // 条件を提示して、その条件に合致した場合はこの action を生成する的なルールにした方が良いかも
88
+
89
+ export const parserSchema = z.object({
90
+ conditions: z.array(conditionComponentSchema),
91
+ action: normalActionActionSchema,
92
+ /** 指定した値群を結合して作成したテキストを代入 */
93
+ source: z.array(textComponentSchema),
94
+ /** 指定した column の値を timestamp に代入 */
95
+ timestamp: z.string(),
96
+ /** 指定した値群を結合して作成したテキストを代入 */
97
+ comment: z.array(textComponentSchema).optional(),
98
+ transfers: z.array(transferComponentSchema),
99
+ /** 指定した値群を結合して作成したテキストを代入 */
100
+ crossId: z.array(textComponentSchema).optional(),
101
+ crossType: z
102
+ .union([z.literal('start'), z.literal('middle'), z.literal('end')])
103
+ .optional(),
104
+ /** 指定した値群を結合して作成したテキストを代入 */
105
+ loanId: z.array(textComponentSchema).optional(),
106
+ target: nftComponentSchema.optional(),
107
+ // TODO crypto asset 対応表を作成する
108
+ })
109
+
110
+ export const parsersSchema = z.array(parserSchema)
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod'
2
+ import { formatterSchema } from './formatter'
3
+ import { parsersSchema } from './parser'
4
+
5
+ export const csvFormatSchema = z.object({
6
+ id: z.string(),
7
+ service: z.string(),
8
+ formatter: formatterSchema,
9
+ parsers: parsersSchema,
10
+ symbolAssetMap: z.record(z.string()).optional(),
11
+ })
@@ -0,0 +1,28 @@
1
+ import { createBigDecimal } from '@0xtorch/big-decimal'
2
+ import type { CryptoCurrency, FiatCurrency } from '@0xtorch/core'
3
+ import { ethereum, jpy, usd } from '@0xtorch/core'
4
+
5
+ /** Updated: 2024-05-12 14:00 */
6
+ export const testCryptoCurrencies: CryptoCurrency[] = [
7
+ {
8
+ type: 'CryptoCurrency',
9
+ id: 'bitcoin',
10
+ name: 'Bitcoin',
11
+ symbol: 'BTC',
12
+ icon: undefined,
13
+ market: {
14
+ coingeckoId: 'bitcoin',
15
+ marketCapUsd: createBigDecimal('1,205,095,120,187'),
16
+ },
17
+ updatedAt: Date.now(),
18
+ },
19
+ {
20
+ ...ethereum,
21
+ market: {
22
+ ...ethereum.market,
23
+ marketCapUsd: createBigDecimal('352,453,045,218'),
24
+ },
25
+ },
26
+ ]
27
+
28
+ export const testFiatCurrencies: FiatCurrency[] = [usd, jpy]
@@ -0,0 +1,17 @@
1
+ 取引日時,取引種別,取引形態,通貨ペア,増加通貨名,増加数量,減少通貨名,減少数量,約定価格/数量,単価,手数料通貨,手数料数量,送付元アドレス,送付先アドレス,登録番号,社名,備考
2
+ 2021/07/28 23:36:54,入金,,,JPY,260000.0,,,,,,,,,関東財務局長 第00014号,コインチェック株式会社,
3
+ 2021/07/28 23:38:14,購入,自己,ETH/JPY,ETH,0.99656,JPY,260000.0,260000.0,260897.48735651,,,,,関東財務局長 第00014号,コインチェック株式会社,
4
+ 2021/07/28 23:51:17,送付,,,,,ETH,0.99156,,,ETH,0.005,,0xF9b5E1202AC637BcfED4EEd026086531c5847D00,関東財務局長 第00014号,コインチェック株式会社,
5
+ 2021/07/31 10:16:18,入金,,,JPY,2500000.0,,,,,,,,,関東財務局長 第00014号,コインチェック株式会社,
6
+ 2021/07/31 11:08:48,購入,自己,ETH/JPY,ETH,8.9589,JPY,2500000.0,2500000.0,279052.11577314,,,,,関東財務局長 第00014号,コインチェック株式会社,
7
+ 2021/07/31 11:20:59,送付,,,,,ETH,8.9539,,,ETH,0.005,,0xF9b5E1202AC637BcfED4EEd026086531c5847D00,関東財務局長 第00014号,コインチェック株式会社,
8
+ 2021/10/04 10:25:54,入金,,,JPY,5000000.0,,,,,,,,,関東財務局長 第00014号,コインチェック株式会社,
9
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.05229,JPY,277980.01938,277980.01938,5316122.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
10
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.01,JPY,53161.45,53161.45,5316145.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
11
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.41386996,JPY,2200430.6937312,2200430.6937312,5316720.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
12
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.03,JPY,159510.0,159510.0,5317000.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
13
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.05126,JPY,272549.42,272549.42,5317000.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
14
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.05631,JPY,299400.27,299400.27,5317000.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
15
+ 2021/10/04 10:46:17,購入,媒介,BTC/JPY,BTC,0.32664995,JPY,1736797.78415,1736797.78415,5317000.0,,,,,関東財務局長 第00014号,コインチェック株式会社,
16
+ 2021/10/04 11:46:50,送付,,,,,BTC,0.001,,,BTC,0.0005,,1Ni8NuJrBmRvpctKcd516GYpUuxNoEis4R,関東財務局長 第00014号,コインチェック株式会社,
17
+ 2021/10/04 11:58:31,送付,,,,,BTC,0.93837991,,,BTC,0.0005,,1Ni8NuJrBmRvpctKcd516GYpUuxNoEis4R,関東財務局長 第00014号,コインチェック株式会社,
@@ -0,0 +1,137 @@
1
+ import type { CsvFormat } from '../types'
2
+
3
+ export const coincheckStandardFormat = {
4
+ id: 'coincheck-standard',
5
+ service: 'coincheck',
6
+ formatter: {
7
+ 取引日時: ['datetime-jp'],
8
+ 取引種別: ['string'],
9
+ 増加通貨名: ['blank', 'string'],
10
+ 増加数量: ['blank', 'big-decimal-positive'],
11
+ 減少通貨名: ['blank', 'string'],
12
+ 減少数量: ['blank', 'big-decimal-positive'],
13
+ '約定価格/数量': ['blank', 'big-decimal-positive'],
14
+ 単価: ['blank', 'big-decimal-positive'],
15
+ 手数料通貨: ['blank', 'string'],
16
+ 手数料数量: ['blank', 'big-decimal-positive'],
17
+ 送付元アドレス: ['string'],
18
+ 送付先アドレス: ['string'],
19
+ 備考: ['string'],
20
+ },
21
+ parsers: [
22
+ {
23
+ conditions: [
24
+ {
25
+ column: '取引種別',
26
+ pattern: {
27
+ type: 'in',
28
+ values: ['購入', '売却', '交換'],
29
+ },
30
+ },
31
+ {
32
+ column: '増加通貨名',
33
+ pattern: {
34
+ type: 'defined',
35
+ },
36
+ },
37
+ {
38
+ column: '増加数量',
39
+ pattern: {
40
+ type: 'defined',
41
+ },
42
+ },
43
+ {
44
+ column: '減少通貨名',
45
+ pattern: {
46
+ type: 'defined',
47
+ },
48
+ },
49
+ {
50
+ column: '減少数量',
51
+ pattern: {
52
+ type: 'defined',
53
+ },
54
+ },
55
+ ],
56
+ action: 'trade',
57
+ source: [
58
+ 'coincheck_',
59
+ {
60
+ type: 'column',
61
+ column: '取引日時',
62
+ },
63
+ ],
64
+ timestamp: '取引日時',
65
+ comment: [
66
+ {
67
+ type: 'column',
68
+ column: '備考',
69
+ },
70
+ ],
71
+ transfers: [
72
+ {
73
+ direction: 'in',
74
+ amount: '増加数量',
75
+ asset: {
76
+ type: 'column',
77
+ column: '増加通貨名',
78
+ },
79
+ },
80
+ {
81
+ direction: 'out',
82
+ amount: '減少数量',
83
+ asset: {
84
+ type: 'column',
85
+ column: '減少通貨名',
86
+ },
87
+ },
88
+ ],
89
+ },
90
+ {
91
+ conditions: [
92
+ {
93
+ column: '取引種別',
94
+ pattern: '送付',
95
+ },
96
+ {
97
+ column: '手数料通貨',
98
+ pattern: {
99
+ type: 'defined',
100
+ },
101
+ },
102
+ {
103
+ column: '手数料数量',
104
+ pattern: {
105
+ type: 'defined',
106
+ },
107
+ },
108
+ ],
109
+ action: 'fee',
110
+ source: [
111
+ 'coincheck_',
112
+ {
113
+ type: 'column',
114
+ column: '取引日時',
115
+ },
116
+ ],
117
+ timestamp: '取引日時',
118
+ comment: [
119
+ 'Transfer to ',
120
+ {
121
+ type: 'column',
122
+ column: '送付先アドレス',
123
+ },
124
+ ],
125
+ transfers: [
126
+ {
127
+ direction: 'out',
128
+ amount: '手数料数量',
129
+ asset: {
130
+ type: 'column',
131
+ column: '手数料通貨',
132
+ },
133
+ },
134
+ ],
135
+ },
136
+ ],
137
+ } satisfies CsvFormat
package/types.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { z } from 'zod'
2
+ import type { csvFormatSchema } from './schemas'
3
+ import type { formatterSchema } from './schemas/formatter'
4
+ import type { formatterValueSchema } from './schemas/formatterTypes'
5
+ import type { parserSchema } from './schemas/parser'
6
+
7
+ export type CsvFormat = z.infer<typeof csvFormatSchema>
8
+
9
+ export type Formatter = z.infer<typeof formatterSchema>
10
+
11
+ export type FormatterValue = z.infer<typeof formatterValueSchema>
12
+
13
+ export type FormattedRow = {
14
+ [column: string]: FormatterValue
15
+ }
16
+
17
+ export type Parser = z.infer<typeof parserSchema>