0.1.1 • Published 3 months ago

@koibanx/swapper-sdk v0.1.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
3 months ago

Koibanx Swapper SDK

Swapper SDK based in module Swapper

Description

Swapper module allows to virtually segragate the liquidiy from an external liquidity provider (ELP) into accounts, transfer them between those accounts, and swap liquidity, within a given account, between different assets the ELP provides. The rate will be given from an external exchange wich will provide the exchange rates, and the trading methods needed for the swapper to operate. The segregation is virtual because the module can't move the real balance, but uses a representation (ledger token) to disperse the funds between accounts.

What can be done?

  • Create a master account tracking a liquidity provider's balance
  • Create an account from a master account
  • Transfer crypto between accounts
  • Swap account's cryptos

Use case example

Having an ELP (lets say Bitgo) with different cryptoassets, you can configure each asset as an external source and segregate your liquidity to other players using the accounts. This accounts can transfer assets between them (a closed loop operation), buy or sell coin from your main account (segregate) or swap an asset for another asset, using Bitgo's rate.

SDK Documentation

Feast yourself

Installation

npm install @koibanx/swapper-sdk

NOTE: you must have the npm token in your .npmrc file

Initialization

Node

Using ES6 import

import SwapperSdk from '@koibanx/swapper-sdk';

const swapper = SwapperSdk({
  baseURL: 'http://your-url',
});

With require

exports.__esModule = true;
const SwapperSdk = require('@koibanx/swapper-sdk')["default"];

const swapper = SwapperSdk({
  baseURL: 'http://your-url',
});

Types

  • Typescript (@koibanx/swapper-sdk/dist/index.d.ts)

Examples

Using ES6 import

import SwapperSdk from "@koibanx/swapper-sdk";

const swapperSDK = SwapperSdk({
    baseURL: 'http://your-url',
})

const catchError = (err, modulo) => {
  console.log('Modulo: ', modulo);
  console.log('details: ', err.details);
  console.log('shortMessage: ', err.message);
  console.log('errorCode: ', err.code);
}

// Create Master Account

swapper.account.createMasterAccount({
  credentials: [
    {
      type: 'bitso',
      apiKey: 'IegAxnLvEY',
      secret: '140ae1d278h650cfd34c1f59dc57509c',
    },
  ],
  allowRed: false,
}).then((data) => {
  console.log('createMasterAccount', JSON.stringify(data._id));
}).catch((e) => catchError(e, 'createMasterAccount'));

// Create Account

swapper.account.createAccount({
  parentId: '63c614d967520921f328dcf2',
}).then((data) => {
  console.log('createAccount', JSON.stringify(data._id));
}).catch((e) => catchError(e, 'createAccount'));

// Get Account

swapper.account.getAccount({
  id: '63c614d967520921f328dcf2',
}).then((acc1) => {
  console.log('getAccount', JSON.stringify(acc1._id));
}).catch((e) => catchError(e, 'getAccount'));

// Implemented

swapper.account.createMasterAccount({
  credentials: [
    {
      type: 'bitso',
      apiKey: 'IegAxnLvEY',
      secret: '140ae1d278h650cfd34c1f59dc57509c',
    },
  ],
  allowRed: false,
}).then((data) => {
  console.log('createMasterAccount', JSON.stringify(data._id));
  p.account.createAccount({
    parentId: data._id,
  }).then((acc) => {
    console.log('createAccount', JSON.stringify(acc._id));
    swapper.account.getAccount({
      id: acc._id,
    }).then((acc1) => {
      console.log('getAccount', JSON.stringify(acc1._id));
    }).catch((e) => catchError(e, 'getAccount'));
  }).catch((e) => catchError(e, 'createAccount'));
}).catch((e) => catchError(e, 'createMasterAccount'));
0.1.1

3 months ago

0.1.0

6 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.1

1 year ago