Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
notVitaliy committed Dec 25, 2020
0 parents commit ee0db88
Show file tree
Hide file tree
Showing 15 changed files with 615 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REDIS_HOST=localhost
REDIS_PORT=6379
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
node_modules
.env
dist
.idea
.vscode
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./src
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15.3.0
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "always",
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"printWidth": 180,
"tabWidth": 2
}
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @notVitaliy
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Vitaliy Isikov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @magic8bot/smq

A simple message queue for magic8bot.
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@magic8bot/smq",
"version": "1.0.2",
"description": "Cryptocurrency trading bot",
"bugs": "https://github.com/magic8bot/smq/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/magic8bot/smq.git"
},
"main": "./dist/index.js",
"scripts": {
"clean": "rimraf ./dist",
"build": "tsc",
"dist": "npm run build",
"rebuild": "npm run clean && npm run dist",
"prepub": "npm run rebuild",
"pub": "npm publish --access=public"
},
"dependencies": {
"dotenv": "^8.2.0",
"rsmq": "^0.12.2"
},
"devDependencies": {
"@types/dotenv": "^8.2.0",
"@types/node": "^14.14.14",
"prettier": "^2.2.0",
"rimraf": "^3.0.2",
"tslint": "^6.1.3",
"typescript": "^4.1.2"
}
}
5 changes: 5 additions & 0 deletions src/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Channel {
NewPeriod = 'NewPeriod',
SyncTrades = 'SyncTrades',
Strategy = 'Strategy',
}
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { config } from 'dotenv'
config()

export * from './channels'
export * from './smq'
35 changes: 35 additions & 0 deletions src/smq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Channel } from './channels'
import RedisSMQ from 'rsmq'

const config = {
host: process.env.REDIS_HOST,
port: Number(process.env.REDIS_PORT),
}

const rsmq = new RedisSMQ(config)

export class Smq {
constructor() {
this.init()
}

async init() {
const queues = await rsmq.listQueuesAsync()
const noQ = Object.keys(Channel).filter((channel) => !queues.includes(channel))
if (noQ.length) return

return Promise.allSettled(noQ.map((qname) => rsmq.createQueueAsync({ qname })))
}

sendMessage(qname: Channel, message: Record<string, any>) {
return rsmq.sendMessageAsync({ qname, message: JSON.stringify(message) })
}

receiveMessage(qname: Channel) {
return rsmq.receiveMessageAsync({ qname })
}

deleteMessage(qname: Channel, id: string) {
return rsmq.deleteMessageAsync({ qname, id })
}
}
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"baseUrl": ".",
"outDir": "./dist",
"rootDir": "./src",
"declaration": true
}
}
153 changes: 153 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"extends": "tslint:latest",
"linterOptions": {
"exclude": [
"./legacy"
]
},
"rules": {
"no-unnecessary-type-assertion": true,
"no-console": false,
"array-type": [
true,
"array"
],
"ban-types": {
"options": [
[
"Object",
"Avoid using the `Object` type. Did you mean `object`?"
],
[
"Function",
"Avoid using the `Function` type. Prefer a specific function type, like `() => void`, or use `ts.AnyFunction`."
],
[
"Boolean",
"Avoid using the `Boolean` type. Did you mean `boolean`?"
],
[
"Number",
"Avoid using the `Number` type. Did you mean `number`?"
],
[
"String",
"Avoid using the `String` type. Did you mean `string`?"
]
]
},
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": [
true,
"ignore-same-line"
],
"forin": false,
"indent": [
true,
"spaces"
],
"interface-name": [
true,
"never-prefix"
],
"interface-over-type-literal": true,
"jsdoc-format": true,
"linebreak-style": [
true,
"LF"
],
"max-line-length": [
true,
180
],
"no-inferrable-types": true,
"no-internal-module": true,
"no-null-keyword": false,
"no-object-literal-type-assertion": false,
"no-submodule-imports": false,
"no-switch-case-fall-through": true,
"no-this-assignment": false,
"no-trailing-whitespace": [
true,
"ignore-template-strings"
],
"no-unnecessary-qualifier": true,
"no-var-keyword": true,
"no-var-requires": false,
"object-literal-shorthand": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"ordered-imports": false,
"prefer-const": true,
"quotemark": [
true,
"single",
"avoid-escape",
"jsx-double"
],
"semicolon": [
true,
"never"
],
"space-within-parens": true,
"trailing-comma": [
true,
{
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "never",
"typeLiterals": "ignore"
},
"esSpecCompliant": true
}
],
"triple-equals": true,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type"
],
"no-implicit-dependencies": false,
"object-literal-key-quotes": [
true,
"consistent-as-needed"
],
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-leading-underscore",
"allow-pascal-case"
]
}
}
Loading

0 comments on commit ee0db88

Please sign in to comment.