Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tay innovation #1

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f672746
Add bity reporting
peachbits Apr 29, 2020
d340361
Save last queried month and year, minus 1 month.
peachbits Apr 30, 2020
409b6c0
Merge pull request #40 from EdgeApp/matthew/addBityReporting
paullinator Apr 30, 2020
5b61857
Add bity and switchain to config.json.sample
peachbits May 1, 2020
be05466
Convert BCH fork codes to match coinmarketcap api
peachbits May 1, 2020
95674eb
Add switchain.js and include txs in totals
peachbits May 1, 2020
b1cacb5
Clean up console.logs and comments
peachbits May 1, 2020
4e10e2f
Fixes error when offset doesn't exist
peachbits May 5, 2020
8b44355
Merge pull request #42 from EdgeApp/matthew/addOffset
paullinator May 5, 2020
6429037
Merge pull request #41 from EdgeApp/matthew/addSwitchain
paullinator May 6, 2020
ad2cf79
Add order id
peachbits May 6, 2020
bddb54c
Merge pull request #43 from EdgeApp/matthew/bityId
paullinator May 6, 2020
08ac652
Concat a UTC timezone designator to the ISO date string to ensure it …
peachbits May 13, 2020
4563bb4
Merge pull request #44 from EdgeApp/matthew/bityUTC
peachbits May 13, 2020
d0a3757
Add Transak report integration code
harshit00027 Mar 19, 2020
40a9c4c
Add limit & skip parameter for the pagination.
agarwalyeshu May 7, 2020
5ab12e8
Formatting autofixes
peachbits May 20, 2020
1de50ee
Add transak to config.json.sample and fix offset, apiResponse url, an…
peachbits May 29, 2020
716eb2d
Merge pull request #45 from EdgeApp/matthew/transak
peachbits May 29, 2020
00a1c28
Disable all but Simplex
kylanhurt Jun 6, 2020
3a57a12
Upgrade Simplex to API
kylanhurt Jun 9, 2020
fc5eebe
Revert "Disable all but Simplex"
kylanhurt Jun 9, 2020
082322d
Merge pull request #46 from EdgeApp/kylan/simplex
kylanhurt Jun 9, 2020
6640f83
Ignore oboe test file
peachbits Jun 11, 2020
d2f6035
Fix typo in query
peachbits Jun 11, 2020
2c3af2e
Merge pull request #48 from EdgeApp/matthew/fixTypo
peachbits Jun 11, 2020
8ac0f7f
Add comments for Simplex routine
kylanhurt Jun 15, 2020
c52a81a
Allow non-camel case
kylanhurt Jun 16, 2020
5eadfb6
Change Simplex to use page cursor during fetch calls
kylanhurt Jun 16, 2020
3e19875
Change 'offset' parameter to lastTxTimestamp for Simplex
kylanhurt Jun 16, 2020
b38d7eb
Update date field
peachbits Jul 1, 2020
9133a1b
Merge pull request #50 from EdgeApp/matthew/fixBanxa
paullinator Jul 2, 2020
b9711b9
fix Banxa to allow legacy time key
paullinator Jul 2, 2020
b9e1126
Merge pull request #51 from EdgeApp/kylan/simplex
paullinator Jul 2, 2020
7d00ab0
Fix Bity to not throw if we query a page with no transactions
paullinator Jul 16, 2020
df56ebe
Tweak Simplex plugin.
paullinator Jul 16, 2020
7df4b65
Auto format
paullinator Jul 16, 2020
01be0b5
Add query to rates.edge.app
paullinator Jul 16, 2020
aea4d8f
Bump lodash from 4.17.5 to 4.17.19
dependabot[bot] Jul 17, 2020
5f22885
Merge pull request #52 from EdgeApp/dependabot/npm_and_yarn/lodash-4.…
paullinator Jul 17, 2020
edc3dce
Add Paytrie
peachbits Jul 31, 2020
104fe2b
Merge pull request #53 from EdgeApp/matthew/paytrie
peachbits Jul 31, 2020
7093d42
change API start date
paullinator Aug 11, 2020
c9b9560
update wyre
paullinator Aug 12, 2020
33ef693
Changed Banxa to use API
Aug 18, 2020
5495a55
Added Z to end of date
Aug 18, 2020
06b587f
Merge pull request #54 from iain-bitcoin/master
paullinator Aug 19, 2020
eca79ef
Fix BANXA date rollback mechanism
paullinator Aug 19, 2020
982ab6a
URL gets set with new offset
itoi06 Oct 8, 2020
44a1309
Merge pull request #57 from EdgeApp/thomas/safelloFix
thehobbit85 Oct 8, 2020
1d0bc69
File sync from EdgeApp/edge-workflows
Jul 8, 2021
45644ac
File sync from EdgeApp/edge-workflows
Jul 8, 2021
758609d
File sync from EdgeApp/edge-workflows
Jul 8, 2021
795ee87
File sync from EdgeApp/edge-workflows
Nov 10, 2021
c1e2d2d
File sync from EdgeApp/edge-workflows
Nov 17, 2021
ec7907c
File sync from EdgeApp/edge-workflows
Nov 17, 2021
ce25d0b
File sync from EdgeApp/edge-workflows
Feb 2, 2022
d599923
File sync from EdgeApp/edge-workflows
May 3, 2022
b1d3731
File sync from EdgeApp/edge-workflows
May 10, 2022
416d0f0
File sync from EdgeApp/edge-workflows
Mar 2, 2023
2b75930
File sync from EdgeApp/edge-workflows
Mar 2, 2023
655d14c
File sync from EdgeApp/edge-workflows
Mar 2, 2023
076efec
File sync from EdgeApp/edge-workflows
Mar 6, 2023
0bc0e24
File sync from EdgeApp/edge-workflows
Jun 7, 2023
bf7d5ff
File sync from EdgeApp/edge-workflows
Sep 13, 2023
8d3afa7
File sync from EdgeApp/edge-workflows
Oct 10, 2023
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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"parser": "babel-eslint",
"plugins": ["flowtype", "standard"],
"rules": {
"camelcase": "error",
"camelcase": "off",
"flowtype/generic-spacing": "off",
"no-throw-literal": "error",
"no-var": "error",
Expand Down
2 changes: 2 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<PROJECT_ROOT>/lib/.*.js.flow

.*/node_modules/oboe/test/json/incomplete.json

[include]

[libs]
Expand Down
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

- [ ] Yes
- [ ] No

### Dependencies

<!-- Replace line with PRs which this PR depends if any --> none

### Description

<!-- Describe your changes textually and/or pictorially if necessary --> none
1 change: 1 addition & 0 deletions .github/workflows/asana-attachment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# removed
1 change: 1 addition & 0 deletions .github/workflows/asana-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# removed
9 changes: 9 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: PR Checks
on: [pull_request]
jobs:
block-wip-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Block WIP PR
uses: samholmes/[email protected]
28 changes: 28 additions & 0 deletions .github/workflows/pr-rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Rebase
on:
issue_comment:
types: [created]
jobs:
rebase:
name: Rebase
if: >-
github.event.issue.pull_request != '' &&
(
contains(github.event.comment.body, '/autosquash') ||
contains(github.event.comment.body, '/fixup') ||
contains(github.event.comment.body, '/rebase')
)
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- name: Automatic Rebase
uses: EdgeApp/rebase@changelog-resolver
with:
autosquash: ${{ true }}
changelogResolver: ${{ true }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-scripts true
11 changes: 11 additions & 0 deletions config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"coinMarketCapAPiKey": "xxx",
"shapeShiftApiKey": "xxx",
"shapeShiftToken": "xxx",
"banxaToken": "xxx",
"libertyXApiKey": "xxx",
"changellyApiKey": "xxx",
"changenowApiKey": "xxx",
Expand All @@ -32,6 +33,16 @@
"wyre": {
"periscopeClientKey": "xxx"
},
"bity": {
"clientId": "",
"clientSecret": ""
},
"paytrieCredentials": {
"apiKey": "xxx",
"secretToken": "xxx"
},
"switchainApiKey" : "",
"transak_api_secret": "xxx",
"coinMarketCapExcludeLookup": ["USD", "EUR", "GBP"],
"coinApiExcludeLookup": ["USD", "EUR", "GBP"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
"dependencies": {
"api-changelly": "git://github.com/changelly/api-changelly.git#8e350f3",
"await-sleep": "0.0.1",
"axios": "^0.19.2",
"biggystring": "^3.0.1",
"changelly_api": "git://github.com/changelly/api-changelly.git#8e350f3",
"csvtojson": "^2.0.10",
"json-format": "^1.0.1",
"jsonfile": "^4.0.0",
"node-fetch": "^1.7.3",
"sleep": "^6.3.0",
"sprintf-js": "^1.1.1",
"web3": "^1.0.0-beta.52"
},
Expand Down
175 changes: 143 additions & 32 deletions src/banxa.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
// @flow
import type { StandardTx, SwapFuncParams } from './checkSwapService.js'
const js = require('jsonfile')
const fs = require('fs')
const fetch = require('node-fetch')
const { checkSwapService } = require('./checkSwapService.js')
const csv = require('csvtojson')
const crypto = require('crypto')
const sleep = require('sleep')
const confFileName = './config.json'
const config = js.readFileSync(confFileName)

const BANXA_CACHE = './cache/banRaw.json'
const BANXA_FOLDER = './cache/banxa'

const MONTH_MAP = {
'Jan': '01',
'Feb': '02',
'Mar': '03',
'Apr': '04',
'May': '05',
'Jun': '06',
'Jul': '07',
'Aug': '08',
'Sep': '09',
'Oct': '10',
'Nov': '11',
'Dec': '12'
}

async function doBanxa (swapFuncParams: SwapFuncParams) {
return checkSwapService(fetchBanxa,
Expand All @@ -16,50 +33,144 @@ async function doBanxa (swapFuncParams: SwapFuncParams) {
)
}

async function callBanxaAPI (queryDate, pageLimit, page) {
const nonce = Math.floor(new Date() / 1000)

const apiQuery = `/api/orders?start_date=${queryDate}&end_date=${queryDate}&per_page=${pageLimit}&page=${page}`

const text = `GET\n${apiQuery}\n${nonce}`
const secret = config.banxaToken
const key = 'EDGE'
const hmac = crypto.createHmac('sha256', secret)
.update(text)
.digest('hex')
const authHeader = key + ':' + hmac + ':' + nonce

const headers = {
'Authorization': 'Bearer ' + authHeader,
'Content-Type': 'application/json'
}

return fetch(`https://edge.banxa.com${apiQuery}`, {headers: headers})
}

function processOrders (orders, ssFormatTxs) {
for (const order of orders) {
if (order.status === 'complete') {
// Reformat the date from DD-MMM-YYYY HH:MM:SS to YYYY-MM-DDTHH:MM:SS
const origDateTime = order.created_at
const dateTimeParts = origDateTime.split(' ')
const dateParts = dateTimeParts[0].split('-')
const month = MONTH_MAP[dateParts[1]]
const reformattedDate = `${dateParts[2]}-${month}-${dateParts[0]}T${dateTimeParts[1]}Z`

// Flip the amounts if the order is a SELL
let inputAmount = order.fiat_amount
let inputCurrency = order.fiat_code
let outputAmount = order.coin_amount
let outputCurrency = order.coin_code
if (order.order_type === 'CRYPTO-SELL') {
inputAmount = order.coin_amount
inputCurrency = order.coin_code
outputAmount = order.fiat_amount
outputCurrency = order.fiat_code
}

const ssTx: StandardTx = {
status: 'complete',
inputTXID: order.ref.toString(),
inputAddress: '',
inputCurrency: inputCurrency,
inputAmount: inputAmount,
outputAddress: order.wallet_address,
outputCurrency: outputCurrency,
outputAmount: outputAmount,
timestamp: new Date(reformattedDate).getTime() / 1000
}
ssFormatTxs.push(ssTx)
}
}
}

async function fetchBanxa (swapFuncParams: SwapFuncParams) {
if (!swapFuncParams.useCache) {
console.log('Fetching Banxa from CSV...')
console.log('Fetching Banxa from API...')
}
let diskCache = { txs: [] }
let diskCache = { last_date: '2019-08-26', txs: [] }

try {
diskCache = js.readFileSync(BANXA_CACHE)
} catch (e) {}

const transactionMap = {}
const ssFormatTxs: Array<StandardTx> = []

const files = await fs.readdirSync(BANXA_FOLDER)
const cachedLastDate = new Date(diskCache.last_date)

for (const fileName of files) {
const filePath = `./cache/banxa/${fileName}`
const csvData = await csv().fromFile(filePath)
for (const order of csvData) {
const date = new Date(order['UTC Time'])
const timestamp = date.getTime() / 1000
const uniqueIdentifier = order['Order Id']
const ssTx: StandardTx = {
status: 'complete',
inputTXID: uniqueIdentifier,
inputAddress: '',
inputCurrency: order['Source Currency'],
inputAmount: parseFloat(order['Source Amount']),
outputAddress: '',
outputCurrency: order['Target Currency'],
outputAmount: order['Target Amount'],
timestamp: timestamp
// Go back a week just to make sure you capture any late completing orders
const startQueryDate = new Date(cachedLastDate.getTime() - 7 * 86400000)

const now = new Date()
const today = new Date(now.toISOString().split('T')[0]).getTime()

let queryDate = startQueryDate.toISOString().split('T')[0]

if (!swapFuncParams.useCache) {
console.log(`BANXA: Loading orders starting from ${queryDate}`)
// Loop through the days
while (startQueryDate.getTime() !== today) {
let page = 1
const pageLimit = 100
queryDate = startQueryDate.toISOString().split('T')[0]
// Move last date on 1 day
startQueryDate.setTime(startQueryDate.getTime() + 86400000)
let attempt = 0

// Loop through the pages for this day
while (1) {
let orders = []

let apiResponse
while (attempt < 3) {
console.log(
`BANXA: Calling API with date ${queryDate}, result size ${pageLimit} and offset ${page} for attempt ${attempt}`
)
apiResponse = await callBanxaAPI(queryDate, pageLimit, page)
const status = await apiResponse.status
// Handle the situation where the API is rate limiting the requests
if (status !== 200) {
console.log(
`BANXA: Response code ${status}. Retrying after 2 second sleep...`
)
sleep.sleep(2)
attempt++
} else {
break
}
}
if (attempt === 3) break

if (apiResponse) {
const ordersData = await apiResponse.json()

if (ordersData && ordersData.data && ordersData.data.orders.length) {
orders = ordersData.data.orders
} else break

processOrders(orders, ssFormatTxs)

if (orders.length < pageLimit) break
page++
}
}
if (attempt === 3) {
console.log(`BANXA: Unable to process date ${queryDate}`)
break
}
// console.log('ssTx: ', ssTx)
transactionMap[uniqueIdentifier] = ssTx
}
}
for (const id in transactionMap) {
ssFormatTxs.push(transactionMap[id])
ssFormatTxs.sort((a, b) => a.timestamp - b.timestamp)
}

// console.log('ssFormatTxs is: ', ssFormatTxs)
diskCache.last_date = queryDate > cachedLastDate ? queryDate : cachedLastDate

console.log(`lastDate ${queryDate}`)
const out = {
diskCache,
newTransactions: ssFormatTxs
Expand Down
Loading