Skip to content

improve types for DB #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions simple-market-making-bot/lib/cancelOrders.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BotDB } from "../types/database";
import { AllDocsResult } from "../types/order";

interface CancelResult {
escrowAddr:string;
}


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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion simple-market-making-bot/lib/getCurrentOrders.ts
Original file line number Diff line number Diff line change
@@ -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<string>):Promise<AllDocsResult> => {
const currentEscrows:AllDocsResult = await escrowDB.allDocs({include_docs: true});
currentEscrows.rows.forEach(escrow => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BotDB } from '../../types/database';
import convertToDBObject from '../convertToDBObject';

interface ValidResult {
Expand All @@ -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 => {
Expand Down
3 changes: 2 additions & 1 deletion simple-market-making-bot/simple-market-making-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion simple-market-making-bot/types/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BotDB } from "./database";

type Environment = 'mainnet' | 'testnet';

export interface BotConfig {
assetId:number,
walletAddr:string,
minSpreadPerc:number,
nearestNeighborKeep:number,
escrowDB:any,
escrowDB:BotDB,
ladderTiers:number,
useTinyMan:boolean,
environment:Environment,
Expand Down
7 changes: 7 additions & 0 deletions simple-market-making-bot/types/database.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AllDocsResult, DBOrder } from "./order";

interface BotDB {
allDocs({include_docs:boolean}?): Promise<AllDocsResult>
remove(order:DBOrder):any
put(any):any
}