npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tradeb0t/core

v0.4.1

Published

🤖 Core library for trading software with high integration possibilities

Downloads

11

Readme

tradeb0t/core 🤖

Core functionality for creating trading bots for exchanges.

See tradeb0t

Getting started

Install core:

npm install @tradeb0t/core

Describe your domain

Domain includes types of entities in the integrated exchange.

Technically, you can provide any types for DomainTemplate. But it is not recommended, as these types will be helpful in process of creating other modules.

import {DomainTemplate} from '@tradeb0t/core'
import {
    CurrencyType,
    CurrencyBalanceType,
    SecurityType,
    SecurityBalanceType,
    OrderType
} from '@exchange/sdk'

// Order of arguments matters
export type Domain = DomainTemplate<CurrencyType, CurrencyBalanceType, SecurityType, SecurityBalanceType, OrderType>

Implement ExchangeConnector

ExchangeConnector is layer between exchange and tradebot internal logic.

It also includes two submodules for splitting logic:

  • InfoModule - get different information from exchange;
  • TradeModule - send requests to place orders to exchange;
  • DomainMapper - for translation exchange types to tradebot types.

You can access ExchangeConnector instance with this.exchangeConnector from these modules.

Note, that you can provide object containing API methods to exchange (API in example). It will be available in ExchangeConnector instance as api.

DomainMapper

Also, you should implement DomainMapper to make it possible for tradebot to understand types of your exchange.

Internal domain of tradebot is provided by CommonDomain type in core library.

import {OperationType, OrderStatus, CommonDomain,
    AbstractDomainMapper,
    GetCurrencyBalanceType,
    GetCurrencyType,
    GetOrderType,
    GetSecurityBalanceType,
    GetSecurityType} from '@tradeb0t/core'
import type API from '@exchange/sdk'

import {Domain} from "../Domain";
export class DomainMapper extends AbstractDomainMapper<Domain, API>{
    async currency(currency: GetCurrencyType<Domain>): Promise<GetCurrencyType<CommonDomain>>{
        //...
    }
    //...
}

Note, that you can extract specific domains types from Domain or ExchangeConnector with following generic types:

  • GetCurrencyType<T>
  • GetCurrencyBalanceType<T>
  • GetSecurityType<T>
  • GetSecurityBalanceType<T>
  • GetOrderType<T>

InfoModule

import {AbstractInfoModule} from '@tradeb0t/core'
import type API from '@exchange/sdk'

import {Domain} from '../Domain'

export class InfoModule extends AbstractInfoModule<Domain, API>{/*...*/}

TradeModule

import {AbstractTradeModule} from '@tradeb0t/core'
import type API from '@exchange/sdk'

import {Domain} from '../Domain'

export class TradeModule extends AbstractTradeModule<Domain, API>{/*...*/}

ExchangeConnector

import {AbstractExchangeConnector} from '@tradeb0t/core'
import API from '@exchange/sdk'

import {Domain} from '../Domain'
import {TradeModule} from './TradeModule'
import {InfoModule} from './InfoModule'
import {DomainMapper} from "./DomainMapper"

export class ExchangeConnector extends AbstractExchangeConnector<Domain, API>{
    protected async initAccount(){
        const { api } = this
        // Something to prepare your client
        this.isAccountInitialized = true
    }

    async getPortfolio() {/*...*/}

    async getCurrenciesBalance() {/*...*/}
}

Start tradebot

Finally, start tradebot with runTradeBot function:

import {runTradeBot} from '@tradeb0t/core'
import API from '@exchange/sdk'

import { DomainMapper, ExchangeConnector, InfoModule, TradeModule } from './bot'
import {initAlgorithms} from './algorithms'

runTradeBot({
  ExchangeConnector: new ExchangeConnector({
    modules: {
      domainMapper: new DomainMapper(),
      infoModule: new InfoModule(),
      tradeModule: new TradeModule()
    },
    api: API
  }),
  initAlgorithmsCallback: initAlgorithms,
  config: {
    // ...
  }
})