Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

♻️ Refactoring exchanges services #15

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

>
> This project is under construction 🚧
> Only USD based markets are supported for now
>

Minimalist service designed to execute [TradingView](https://www.tradingview.com/) webhooks and process them to cryptocurrencies exchanges from [AWS lightsail](https://lightsail.aws.amazon.com/).
Expand All @@ -27,13 +26,17 @@ You can use the bot with :

### 🏦 Supported exchanges

| logo | id | name | doc |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------|:------------------------------------------------------------------:|
>
> Only USD based markets are supported for now
>

| logo | id | name | doc |
|-|-|-|:-:|
| [![binance](https://user-images.githubusercontent.com/1294454/29604020-d5483cdc-87ee-11e7-94c7-d1a8d9169293.jpg)](https://www.binance.com/) | binance | [Binance (spot)](https://www.binance.com/) | [API](https://binance-docs.github.io/apidocs/spot/en) |
| [![binanceusdm](https://user-images.githubusercontent.com/1294454/117738721-668c8d80-b205-11eb-8c49-3fad84c4a07f.jpg)](https://www.binance.com/) | binanceusdm | [Binance USDⓈ-M (futures)](https://www.binance.com/) | [API](https://binance-docs.github.io/apidocs/spot/en) |
| [![ftx](https://user-images.githubusercontent.com/1294454/67149189-df896480-f2b0-11e9-8816-41593e17f9ec.jpg)](https://ftx.com/) | ftx | [FTX (spot & futures)](https://ftx.com/) | [API](https://github.com/ftexchange/ftx) |
| [![kraken](https://user-images.githubusercontent.com/51840849/76173629-fc67fb00-61b1-11ea-84fe-f2de582f58a3.jpg)](https://www.kraken.com) | kraken | [Kraken (spot)](https://www.kraken.com) | [API](https://www.kraken.com/features/api) |
| [![kucoin](https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg)](https://www.kucoin.com/) | kucoin | [KuCoin (spot)](https://www.kucoin.com/) | [API](https://docs.kucoin.com) |
| [![kraken](https://user-images.githubusercontent.com/51840849/76173629-fc67fb00-61b1-11ea-84fe-f2de582f58a3.jpg)](https://www.kraken.com) | kraken | [Kraken (spot)](https://www.kraken.com) | [API](https://www.kraken.com/features/api) |
<!-- | [![binancecoinm](https://user-images.githubusercontent.com/1294454/117738721-668c8d80-b205-11eb-8c49-3fad84c4a07f.jpg)](https://www.binance.com/) | binancecoinm | [Binance COIN-M](https://www.binance.com/) | * | [API](https://binance-docs.github.io/apidocs/spot/en) |-->

### 🚧 Features
Expand All @@ -46,10 +49,13 @@ You can use the bot with :
- list account balances
- list exchange markets
- process multiple trades at once

<!-- - close a position and open another in the opposite direction (Futures only)
- close a position while reducing on oversell / overbuy (Futures only) -->
- close a position and open another in the opposite direction (Futures only)
- close a position while reducing on oversell / overbuy (Futures only)

### 💡 Contributions

Feel free to submit [Github issues](https://github.com/thibaultyou/tradingview-alerts-processor/issues) if you find anything you want me to add, fix or improve.

Best way to show your support to this tool is by hitting the star button [![Stars](https://img.shields.io/github/stars/thibaultyou/tradingview-alerts-processor?style=social)](https://github.com/thibaultyou/tradingview-alerts-processor/stargazers), you can also [!["Buy Me A Coffee"](https://img.shields.io/badge/-buy_me_a%C2%A0coffee-gray?logo=buy-me-a-coffee)](https://www.buymeacoffee.com/thibaultyou).

You can join us on the Jackrabbit Discord server [![Discord](https://img.shields.io/discord/664206005881536512)](https://discord.gg/mNMVWXpAGd) where I'll be happy to answer questions there, you'll also find great strategies to use with this tool.
6 changes: 2 additions & 4 deletions docs/2_Alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
[{ "stub": "dev", "direction": "long", "symbol": "ETH-PERP", "size": "50" }, { "stub": "dev", "direction": "long", "symbol": "BTC-PERP", "size": "50" }]
```

<!--
- Short position and close opened Long position if any :

```json
Expand All @@ -73,7 +72,7 @@
```json
{ "stub": "dev", "direction": "long", "symbol": "ETH-PERP", "size": "50", "mode": "reverse" }
```

- Close Long position if Short size is greater than opened position :

```json
Expand All @@ -84,5 +83,4 @@

```json
{ "stub": "dev", "direction": "long", "symbol": "ETH-PERP", "size": "50", "mode": "overflow" }
``` -->

```
3 changes: 1 addition & 2 deletions docs/3_Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
curl -d '[{"stub": "test", "symbol": "ETH-PERP", "size": "11", "direction": "long" }, {"stub": "test", "symbol": "BTC-PERP", "size": "11", "direction": "long" }]' -X POST http:https://YOUR.STATIC.IP.ADDRESS/trades -H 'Content-Type: application/json; charset=utf-8'
```

<!--
- __Close a short position__ and __open a long position__ on ETH-PERP using `test` account :

```sh
Expand All @@ -105,4 +104,4 @@

```sh
curl -d '{"stub": "test", "symbol": "ETH-PERP", "direction": "short", "size": "100", "mode": "overflow" }' -X POST http:https://YOUR.STATIC.IP.ADDRESS/trades -H 'Content-Type: application/json; charset=utf-8'
``` -->
```
15 changes: 10 additions & 5 deletions src/entities/trade.entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
Matches,
ValidateIf
} from 'class-validator';
import { SIDES, Side } from '../constants/trading.constants';
import {
SIDES,
Side,
TRADING_MODES,
TradingMode
} from '../constants/trading.constants';

export class Trade {
@IsString()
Expand All @@ -19,10 +24,10 @@ export class Trade {
@IsOptional()
max?: string;

// @IsString()
// @IsIn(TRADING_MODES)
// @IsOptional()
// mode?: TradingMode;
@IsString()
@IsIn(TRADING_MODES)
@IsOptional()
mode?: TradingMode;

@IsString()
@Matches(/.*(PERP|USD).*/)
Expand Down
53 changes: 53 additions & 0 deletions src/interfaces/exchanges/base/base.exchange.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Exchange, Order, Ticker } from 'ccxt';
import { Account } from '../../../entities/account.entities';
import { Trade } from '../../../entities/trade.entities';
import { IMarket } from '../../market.interfaces';
import { IOrderOptions } from '../../trading.interfaces';
import { IBalance, ISession } from '../common.exchange.interfaces';

export interface IBaseExchange {
checkCredentials(account: Account, instance: Exchange): Promise<boolean>;

refreshSession(account: Account): Promise<ISession>;

getBalances(account: Account, instance?: Exchange): Promise<IBalance[]>;

getTicker(symbol: string): Promise<Ticker>;

getMarkets(): Promise<IMarket[]>;

getAvailableFunds(account: Account, ticker: Ticker): Promise<number>;

getOpenOrderOptions(
account: Account,
ticker: Ticker,
trade: Trade
): Promise<IOrderOptions>;

openOrder(account: Account, trade: Trade): Promise<Order>;

getCloseOrderOptions(
account: Account,
ticker: Ticker,
trade: Trade
): Promise<IOrderOptions>;

closeOrder(
account: Account,
trade: Trade,
ticker?: Ticker // can be preloaded in openOrder
): Promise<Order>;

handleOrderModes(
account: Account,
ticker: Ticker,
trade: Trade
): Promise<boolean>;

handleMaxBudget(
account: Account,
ticker: Ticker,
trade: Trade,
balance: number
): Promise<void>;
}
26 changes: 26 additions & 0 deletions src/interfaces/exchanges/base/futures.exchange.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Exchange, Ticker } from 'ccxt';
import { Account } from '../../../entities/account.entities';
import { Trade } from '../../../entities/trade.entities';
import { FuturesPosition } from '../../../types/exchanges.types';

export interface IFuturesExchange {
handleReverseOrder(
account: Account,
ticker: Ticker,
trade: Trade
): Promise<void>;

handleOverflow(
account: Account,
ticker: Ticker,
trade: Trade
): Promise<boolean>;

fetchPositions(instance: Exchange): Promise<FuturesPosition[]>;

getPositions(account: Account): Promise<FuturesPosition[]>;

getTickerPosition(account: Account, ticker: Ticker): Promise<FuturesPosition>;

getTickerPositionSize(account: Account, ticker: Ticker): Promise<number>;
}
3 changes: 3 additions & 0 deletions src/interfaces/exchanges/base/spot.exchange.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-interface */

export interface ISpotExchange {}
Loading