From fd3bb2b044678f3b758c71c0d9ebaec4fbe9a481 Mon Sep 17 00:00:00 2001 From: Brendan Lane Date: Wed, 23 Dec 2020 01:12:43 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Start=20patch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/Group.ts | 78 +++++++++++++++++++++++++++- src/modules/TransactionHub.ts | 3 ++ src/modules/interfaces/Interfaces.ts | 12 ++--- 3 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/modules/Group.ts b/src/modules/Group.ts index cc22e75..517dfd1 100644 --- a/src/modules/Group.ts +++ b/src/modules/Group.ts @@ -2,6 +2,7 @@ // Written by Brendan Lane - https://brndnln.dev/ import axios from 'axios' +import { EntityUser } from './interfaces/Interfaces' import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types' const groupURL = 'https://api.spookvooper.com/group' @@ -34,7 +35,7 @@ class Group { }) } - public async sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise { + public async sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: EntityUser): Promise { if (typeof to === 'string') { return await new Promise((resolve, reject) => { axios.get(`${ecoURL}/sendTransactionByIds`, { @@ -157,6 +158,81 @@ class Group { this.accountid = svid } + + public async getStockOffers (ticker: string): Promise { + return await new Promise((resolve, reject) => { + axios.get(`${ecoURL}/getUserStockOffers`, { + params: { + ticker: ticker, + svid: this.accountid + } + }) + .then((response) => { + resolve(response.data) + }) + .catch((error) => { + reject(error) + }) + }) + } + + public async buyStock (ticker: string, amount: number, price: CreditAmount, auth: AuthEntity): Promise { + return await new Promise((resolve, reject) => { + axios.get(`${ecoURL}/submitStockBuy`, { + params: { + ticker: ticker, + count: amount, + price: price, + accountid: this.accountid, + auth: auth.apikey + } + }) + .then((response) => { + resolve(response.data) + }) + .catch((error) => { + reject(error) + }) + }) + } + + public async sellStock (ticker: string, amount: number, price: CreditAmount, auth: AuthEntity): Promise { + return await new Promise((resolve, reject) => { + axios.get(`${ecoURL}/submitStockSell`, { + params: { + ticker: ticker, + count: amount, + price: price, + accountid: this.accountid, + auth: auth.apikey + } + }) + .then((response) => { + resolve(response.data) + }) + .catch((error) => { + reject(error) + }) + }) + } + + public async cancelOffer (orderid: number, auth: AuthEntity): Promise { + return await new Promise((resolve, reject) => { + axios.get(`${ecoURL}/cancelOrder`, { + params: { + orderid: orderid, + accountid: this.accountid, + auth: auth.apikey + } + }) + .then((response) => { + resolve(response.data) + }) + .catch((error) => { + reject(error) + }) + }) + } } export default Group diff --git a/src/modules/TransactionHub.ts b/src/modules/TransactionHub.ts index 2c228f8..1a96ed5 100644 --- a/src/modules/TransactionHub.ts +++ b/src/modules/TransactionHub.ts @@ -23,6 +23,9 @@ class TransactionHub { public fromAccount: string public toAccount: string + public fromType: string + public toType: string + public event = new Observable((observer) => { this.connection.on('NotifyTransaction', (recieved: string) => { this.val = JSON.parse(recieved) diff --git a/src/modules/interfaces/Interfaces.ts b/src/modules/interfaces/Interfaces.ts index eebb544..fa9ea2e 100644 --- a/src/modules/interfaces/Interfaces.ts +++ b/src/modules/interfaces/Interfaces.ts @@ -1,7 +1,7 @@ // SpookVooper API - modules/interfaces/Interfaces.ts // Written by Brendan Lane - https://brndnln.dev/ -import { DistrictWealthType, SenatorDistrict } from '../types/Types' +import { CreditAmount, DistrictWealthType, PaymentEntity, SenatorDistrict } from '../types/Types' interface EntityUser { svid: string @@ -9,12 +9,12 @@ interface EntityUser { getUser: () => Promise getUsername: () => Promise getBalance: () => Promise - hasDiscordRole: () => Promise + hasDiscordRole: (role: string) => Promise getDiscordRoles: () => Promise - sendCredits: () => Promise - getStockOffers: () => Promise - buyStock: () => Promise - sellStock: () => Promise + sendCredits: (amount: CreditAmount, to: PaymentEntity, reason: string) => Promise + getStockOffers: (ticker: string) => Promise + buyStock: (ticker: string, amount: number, price: CreditAmount) => Promise + sellStock: (ticker: string, amount: number, price: CreditAmount) => Promise } interface EntityGroup {