0.5.1-alpha.4622.0 • Published 6 years ago

@energyweb/exchange v0.5.1-alpha.4622.0

Weekly downloads
27,047
License
GPL-3.0-or-later
Repository
github
Last release
6 years ago

Exchange package provides the order book based exchange functionality for the certificates issued by issuer package. The major difference between classic (asset, time, price) order book system is the product based matching engine, providing the ability to create custom matching rules.

Main features

  • Order book matching engine for time, price and product matching
  • ERC 1155 / ERC 1888 compatible
  • Supply / Demand modules

Trading product concept

Definition

Product defines the characteristics of the given producing device as well as buyers preferences . Currently it's represented as:

export class Product {
    public deviceType?: string[];

    public location?: string[];

    public deviceVintage?: number;
}

Where

  • deviceType - describes the type of the device for e.g. using I-REC types
  • location - describes the location of the the device for e.g. can be multi-level like Country->Region->Province
  • deviceVintage - describes the vintage of the device for e.g. the start year of the device operation

For a producing device all fields are mandatory.

Development

Default TypeOrm configuration requires running PostgreSQL database. The detailed config with .env parameters is:

TypeOrmModule.forRoot({
            type: 'postgres',
            name: 'ExchangeConnection',
            host: process.env.DB_HOST ?? 'localhost',
            port: Number(process.env.DB_PORT) ?? 5432,
            username: process.env.DB_USERNAME ?? 'postgres',
            password: process.env.DB_PASSWORD ?? 'postgres',
            database: process.env.DB_DATABASE ?? 'origin',
            entities: [Demand, Order, Trade, Asset, Transfer, Account],
            synchronize: true,
            logging: ['info']
        }),
yarn
yarn start

PostgreSQL installation using Docker

docker pull postgres
docker run --name origin-postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres

pgAdmin

docker pull dpage/pgadmin4
docker run -p 80:80 \
    -e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' \
    -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
    -d dpage/pgadmin4

SQL dump

example/example.sql contains a dump of database filled in with the example data:

  1. User with id=1 as a buyer (owner of the bid orders)
  2. User with id=2 as a seller (owner of the ask orders), with confirmed deposit of 100MWh (100000000)
  3. 3 open bids with prices 90,85,75 for {"deviceType":["Solar;Photovoltaic;Classic silicon"],"location":["Thailand;Central;Nakhon Pathom"],"deviceVintage":{"year":2016}}
  4. 3 open asks with prices 110,120,130 for {"deviceType":["Solar;Photovoltaic;Classic silicon"],"location":["Thailand;Central;Nakhon Pathom"],"deviceVintage":{"year":2016}}
  5. 3 open bids with prices 79,78,77 for {"deviceType":["Wind"],"location":["Thailand;Northeast"]
  6. 3 open asks with prices 80,85,86 for {"deviceType":["Wind;Onshore"],"location":["Thailand;Northeast;Nakhon Ratchasima"],"deviceVintage":{"year":2014}}
  7. 1 filled ask
  8. 1 partially filled bid
  9. 1 trade

In order to deploy the data please use pgadmin or psql or similar tools to import *.sql tool.

Notice that you might need to remove previously imported data in case of PK violations. Use

TRUNCATE "account","asset","demand","order","trade","transfer" CASCADE

with caution.

Bypassing auth for testing purpose

It's possible to run the exchange in bypass auth mode by running:

yarn start:noauth

This can be used for fast integrations and testing

Swagger

Swagger endpoint can be found at

http://localhost:3033/api

1.14.1

4 years ago

1.14.0

4 years ago

1.13.1

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago