diff --git a/simple-market-making-bot/lib/cancelOrders.ts b/simple-market-making-bot/lib/cancelOrders.ts index b258307..b0f7e64 100644 --- a/simple-market-making-bot/lib/cancelOrders.ts +++ b/simple-market-making-bot/lib/cancelOrders.ts @@ -1,3 +1,4 @@ +import { BotDB } from "../types/database"; import { AllDocsResult } from "../types/order"; interface CancelResult { @@ -5,7 +6,7 @@ interface CancelResult { } -export const convertCancelResultsToDBPromises = (escrowDB:any, results:CancelResult[][], +export const convertCancelResultsToDBPromises = (escrowDB:BotDB, results:CancelResult[][], orders:AllDocsResult) => { const addrs = results.map(result => result[0].escrowAddr); const resultAddrs = new Set(addrs); @@ -18,7 +19,7 @@ export const convertCancelResultsToDBPromises = (escrowDB:any, results:CancelRes return removeFromDBPromises; }; -export const cancelOrders = async (escrowDB:any, orders:AllDocsResult, cancelPromises:any) => { +export const cancelOrders = async (escrowDB:BotDB, orders:AllDocsResult, cancelPromises:any) => { return await Promise.all(cancelPromises).then(async function(results) { const removeFromDBPromises = convertCancelResultsToDBPromises(escrowDB, results, orders); diff --git a/simple-market-making-bot/lib/getCurrentOrders.ts b/simple-market-making-bot/lib/getCurrentOrders.ts index b1c996b..e51e7ee 100644 --- a/simple-market-making-bot/lib/getCurrentOrders.ts +++ b/simple-market-making-bot/lib/getCurrentOrders.ts @@ -1,6 +1,7 @@ +import { BotDB } from "../types/database"; import { AllDocsResult, OrderDoc } from "../types/order"; -const getCurrentOrders = async (escrowDB:any, indexer:any, +const getCurrentOrders = async (escrowDB:BotDB, indexer:any, openAccountSet:Set):Promise => { const currentEscrows:AllDocsResult = await escrowDB.allDocs({include_docs: true}); currentEscrows.rows.forEach(escrow => { diff --git a/simple-market-making-bot/lib/placeOrdersAndUpdateDB/addOrdersToDB.ts b/simple-market-making-bot/lib/placeOrdersAndUpdateDB/addOrdersToDB.ts index e85e882..eb17c19 100644 --- a/simple-market-making-bot/lib/placeOrdersAndUpdateDB/addOrdersToDB.ts +++ b/simple-market-making-bot/lib/placeOrdersAndUpdateDB/addOrdersToDB.ts @@ -1,3 +1,4 @@ +import { BotDB } from '../../types/database'; import convertToDBObject from '../convertToDBObject'; interface ValidResult { @@ -6,7 +7,7 @@ interface ValidResult { } } -const addOrdersToDB = async (escrowDB:any, validResults: ValidResult[]) => { +const addOrdersToDB = async (escrowDB:BotDB, validResults: ValidResult[]) => { const ordersAddToDB = validResults .filter(order => order[0].contract.amount > 0) .map(order => { diff --git a/simple-market-making-bot/simple-market-making-bot.ts b/simple-market-making-bot/simple-market-making-bot.ts index 7173192..549a3e8 100644 --- a/simple-market-making-bot/simple-market-making-bot.ts +++ b/simple-market-making-bot/simple-market-making-bot.ts @@ -20,6 +20,7 @@ import getOpenAccountSetFromAlgodex from './lib/getOpenAccountSetFromAlgodex'; import initAPI from './lib/initAPI'; import runLoop from './lib/runLoop'; +import { BotDB } from "./types/database"; // app.set('host', '127.0.0.1'); if (args.assetId == undefined || @@ -70,7 +71,7 @@ const walletAddr = const pouchUrl = process.env.POUCHDB_URL ? process.env.POUCHDB_URL + '/' : ''; const fullPouchUrl = pouchUrl + 'market_maker_' + assetId + '_' + walletAddr.slice(0, 8).toLowerCase(); -const escrowDB = new PouchDB(fullPouchUrl); +const escrowDB:BotDB = new PouchDB(fullPouchUrl); const ladderTiers = parseInt(process.env.LADDER_TIERS!) || 3; const useTinyMan = process.env.USE_TINYMAN && process.env.USE_TINYMAN.toLowerCase() !== 'false' || false; diff --git a/simple-market-making-bot/types/config.d.ts b/simple-market-making-bot/types/config.d.ts index 730000f..2539bcb 100644 --- a/simple-market-making-bot/types/config.d.ts +++ b/simple-market-making-bot/types/config.d.ts @@ -1,3 +1,5 @@ +import { BotDB } from "./database"; + type Environment = 'mainnet' | 'testnet'; export interface BotConfig { @@ -5,7 +7,7 @@ export interface BotConfig { walletAddr:string, minSpreadPerc:number, nearestNeighborKeep:number, - escrowDB:any, + escrowDB:BotDB, ladderTiers:number, useTinyMan:boolean, environment:Environment, diff --git a/simple-market-making-bot/types/database.d.ts b/simple-market-making-bot/types/database.d.ts new file mode 100644 index 0000000..78afa9c --- /dev/null +++ b/simple-market-making-bot/types/database.d.ts @@ -0,0 +1,7 @@ +import { AllDocsResult, DBOrder } from "./order"; + +interface BotDB { + allDocs({include_docs:boolean}?): Promise + remove(order:DBOrder):any + put(any):any +} \ No newline at end of file