Created
November 28, 2019 23:17
-
-
Save molekilla/db8cea945821396d368f4370c389d46d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Markets } from './tradingview/Markets'; | |
import { MarginBot } from './binance/MarginBot'; | |
import { BookTicker } from "./binance/BookTicker"; | |
import { BinanceOrder } from "./binance/BinanceOrder"; | |
import { forkJoin } from 'rxjs'; | |
import { MMMBotDB } from './MMMBotDB'; | |
import { Position } from './binance/Position'; | |
import { Dashboard } from './dashboard'; | |
import BigNumber from 'bignumber.js'; | |
// Main Loop Cancel Token | |
let dashboard: Dashboard; | |
let isStarted = false; | |
let binanceBot: MarginBot; | |
const bootInit = async () => { | |
// Create Positions DB and initialize | |
const positionsDb = new MMMBotDB(); | |
await positionsDb.init(); | |
binanceBot = new MarginBot(positionsDb); | |
// Fetch Exchange Info, required to get price step sizes | |
await binanceBot.exchangeInfo(); | |
binanceBot.cancelStrandedBuyOrders(); | |
const isScalping = process.env.SCALPING_MODE; | |
if (isScalping) console.log('Scalping mode'); | |
const positions= await binanceBot.syncPositions(process.env.MARGIN_PAIRS); | |
await binanceBot.updatePositionsIndicators(positions); | |
binanceBot.marginUserDataEvent.subscribe(async ({ balances, execution }) => { | |
await binanceBot.scanForPositionChanges(balances, execution); | |
await binanceBot.updatePositionsIndicators(); | |
}); | |
binanceBot.subscribeTrades(process.env.MARGIN_PAIRS.split(',')); | |
binanceBot.tradeEvent.subscribe(log => console.log(log)); | |
setTimeout(() => { | |
if (!isStarted) { | |
dashboard = new Dashboard(positionsDb, binanceBot); | |
dashboard.startWebServer(); | |
isStarted = true; | |
} | |
}) | |
} | |
try { | |
bootInit(); | |
console.log('exit') | |
} catch (e) { console.log(e) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment