# @energyweb/exchange

> A service project hosting order book based exchange

Latest version **1.14.1** (published 2022-03-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @energyweb/exchange
pnpm add @energyweb/exchange
yarn add @energyweb/exchange
bun add @energyweb/exchange
```

Provides the command `origin-exchange-migrate`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.14.1 |
| Published | 2022-03-16 |
| First published | 2020-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 29 |
| Unpacked size | 797.5 KB |
| Known vulnerabilities | 0 (+14 in 7 direct dependencies) |
| Install scripts | no |
| GitHub stars | 110 |
| Author | EnergyWeb DevHub GmbH; Piotr Kosinski, piotr.kosinski@energyweb.org |
| Maintainers | kyleiankian, energywebdev, aznagy, bagaric, pkosin, drgorb, kroy, manihagh |

## Links

- npm: https://www.npmjs.com/package/@energyweb/exchange
- Repository: https://github.com/energywebfoundation/origin
- Homepage: https://github.com/energywebfoundation/origin/tree/master/packages/exchange#readme
- Issues: https://github.com/energywebfoundation/origin/issues
- npm.io page: https://npm.io/package/@energyweb/exchange

## Dependencies (29)

- [pg](https://npm.io/package/pg.md) 8.7.1
- [rxjs](https://npm.io/package/rxjs.md) 7.4.0
- [bn.js](https://npm.io/package/bn.js.md) 5.2.0
- [ethers](https://npm.io/package/ethers.md) 5.3.1
- [moment](https://npm.io/package/moment.md) 2.29.1
- [typeorm](https://npm.io/package/typeorm.md) 0.2.41
- [polly-js](https://npm.io/package/polly-js.md) 1.8.3
- [immutable](https://npm.io/package/immutable.md) 4.0.0
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) 8.1.1
- [@nestjs/cqrs](https://npm.io/package/@nestjs/cqrs.md) 8.0.0
- [moment-range](https://npm.io/package/moment-range.md) 4.0.2
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) 8.1.1
- [@nestjs/config](https://npm.io/package/@nestjs/config.md) 1.0.2
- [@nestjs/swagger](https://npm.io/package/@nestjs/swagger.md) 5.1.4
- [@nestjs/testing](https://npm.io/package/@nestjs/testing.md) 8.1.1
- [@nestjs/typeorm](https://npm.io/package/@nestjs/typeorm.md) 8.0.2
- [class-validator](https://npm.io/package/class-validator.md) 0.13.2
- [@nestjs/passport](https://npm.io/package/@nestjs/passport.md) 8.0.1
- [@nestjs/schedule](https://npm.io/package/@nestjs/schedule.md) 1.0.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) 0.1.13
- [@energyweb/issuer](https://npm.io/package/@energyweb/issuer.md) 7.0.1
- [class-transformer](https://npm.io/package/class-transformer.md) 0.3.1
- [swagger-ui-express](https://npm.io/package/swagger-ui-express.md) 4.2.0
- [@energyweb/exchange-core](https://npm.io/package/@energyweb/exchange-core.md) 3.2.7
- [@energyweb/utils-general](https://npm.io/package/@energyweb/utils-general.md) 11.2.3
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) 8.1.1
- [@energyweb/origin-backend-core](https://npm.io/package/@energyweb/origin-backend-core.md) 8.2.3
- [@energyweb/origin-backend-utils](https://npm.io/package/@energyweb/origin-backend-utils.md) 1.8.3
- [@energyweb/exchange-token-account](https://npm.io/package/@energyweb/exchange-token-account.md) 1.0.4

## Recent versions

- 1.14.1 (latest) — 2022-03-16
- 1.13.2-alpha.1658756736.0 (canary) — 2022-07-25
- 0.5.1-preview.4091.0 (preview) — 2020-03-16
- 1.13.2-alpha.1658745615.0 — 2022-07-25
- 1.13.2-alpha.1657642980.0 — 2022-07-12
- 1.13.2-alpha.1654697952.0 — 2022-06-08
- 1.13.2-alpha.1651489311.0 — 2022-05-02
- 1.13.2-alpha.1651149594.0 — 2022-04-28
- 1.14.2-alpha.1650636678.0 — 2022-04-22
- 1.14.0 — 2022-03-15
- 1.13.2-alpha.1646656455.0 — 2022-03-07
- 1.13.2-alpha.1646058469.0 — 2022-02-28
- 1.13.2-alpha.1646056819.0 — 2022-02-28
- 1.13.1 — 2022-01-18
- 1.13.1-alpha.1642431088.0 — 2022-01-17
- … 1340 more at https://npm.io/package/@energyweb/exchange/versions

## README

<p align="center">
  <a href="https://www.energyweb.org" target="blank"><img src="../../../docs/images/EW.png" width="120" alt="Energy Web Foundation Logo" /></a>
</p>

# Exchange

## Description

The Exchange package is a [NestJS](https://docs.nestjs.com/) application that provides backend services to manage the Exchange's functionality (account management and buying, selling and transferring Energy Attribute Certificates through an order book system).

It is a component of [Energy Web Origin's](https://energy-web-foundation-origin.readthedocs-hosted.com/en/latest/) Trade SDK.

## Documentation

-   [Exchange](https://energy-web-foundation-origin.readthedocs-hosted.com/en/latest/trade/exchange/)
-   [Trade SDK](https://energy-web-foundation-origin.readthedocs-hosted.com/en/latest/trade/)

## Contributing Guidelines

See [contributing.md](../../../contributing.md)

# Energy Web Decentralized Operating System

EW-Origin is a component of the Energy Web Decentralized Operating System (EW-DOS).

The purpose of EW-DOS is to develop and deploy an open and decentralized digital operating system for the energy sector in support of a low-carbon, customer-centric energy future.

We develop blockchain technology, full-stack applications and middleware packages that facilitate participation of Distributed Energy Resources on the grid and create open market places for transparent and efficient renewable energy trading.

-   To learn about more about the EW-DOS tech stack, see our [documentation](https://app.gitbook.com/@energy-web-foundation/s/energy-web/)

For a deep-dive into the motivation and methodology behind our technical solutions, read our White Papers:

-   [Energy Web White Paper on Vision and Purpose](https://www.energyweb.org/reports/EWDOS-Vision-Purpose/)
-   [Energy Web White Paper on Technology Detail](https://www.energyweb.org/wp-content/uploads/2020/06/EnergyWeb-EWDOS-PART2-TechnologyDetail-202006-vFinal.pdf)

## Connect with Energy Web

-   [Twitter](https://twitter.com/energywebx)
-   [Discord](https://discord.com/channels/706103009205288990/843970822254362664)
-   [Telegram](https://t.me/energyweb)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

## Development

Exchange project is currently not meant to be run as a separate nest application. In order to run exchange project please refer to https://github.com/energywebfoundation/origin/tree/master/packages/origin-backend-app

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

```
DB_HOST      - default 'localhost'
DB_PORT      - default 5432
DB_USERNAME  - default 'postgres',
DB_PASSWORD  - default 'postgres',
DB_DATABASE  - default 'origin',
```

or

```
DATABASE_URL  - postgres://{user}:{password}@{host}:{port}/{database}
```

### Using TypeORM migrations

Exchange project uses TypeORM mechanism to perform SQL data migrations. For detailed information please refer to https://github.com/typeorm/typeorm/blob/master/docs/migrations.md

-   `yarn typeorm:run` to update DB to latest exchange tables schema
-   `yarn typeorm:migrate SampleMigrationName` to create new migration file based on the changes in the code entities

Development flow:

-   run `yarn typeorm:run` - to apply latest migrations
-   apply changes in the entities, like change the variable name or type
-   run `yarn typeorm:migrate LastestChanges...`
-   inspect newly created migration in /migrations folder
-   run `yarn typeorm:run` to apply newly created migration

**Warning:**

**Existing migration files from `/migration` folder should never be edited after being committed.**

### 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.

This can be used for fast integrations and testing

### Swagger

Swagger endpoint can be found at

`http://localhost:3033/api`

---
_Source: https://npm.io/package/@energyweb/exchange · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
