Skip to content

Commit

Permalink
Improved checks and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
tomav committed Jan 7, 2024
1 parent 3f7831a commit ad55717
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ This example will open a market position, place a limit buy order, and set a sto
| **stop_market_sell** | x | x | | | |
| **close_position** | | | | | |

### Debug

```
curl -X POST -H "Content-Type: application/json" -d '{ "account": "first_account", "instrument": "BTC-PERPETUAL", "orders": [{ "t": "debug", "a": 10, "p": 10 }] }' http://localhost:3000/trade
```

### Endpoints

* `POST /trade` to place trades from tradingview
* `GET /exchanges` to list supported exhanges, useful to find a `ccxt id`
* `GET /exchanges/:exchange` to list available instruments (symbols) for a specific exchange

### FAQ

#### Amount unit is in Fiat or Asset?
It depends on the exchange. Example:
* deribit: it's fiat on `BTC-PERPETUAL`
* bitfinex: it's asset on `BTC/USD`

Refere to exchange or ccxt documentation.
3 changes: 3 additions & 0 deletions class_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Config {

getAccountParams(account) {
let exchange = this.exchanges.find(e => e.account === account)
if (!exchange) {
throw new Error(`No account named '${account}'`);
}
let params = exchange.hasOwnProperty('params') ? exchange.params : {}
return params
}
Expand Down
2 changes: 1 addition & 1 deletion class_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Order {
}
console.log("-> Processing", this.order)
if (this.order.t == 'debug') {
console.log("<- Debug mode, no order placed.")
console.log("-x Debug mode, no order placed.")
return "executed debug order"
} else {
switch (this.order.t) {
Expand Down
1 change: 1 addition & 0 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ test('getAccountParams() returns correct data', () => {
expect(global.config.getAccountParams("first_account")).toStrictEqual({ "currency": "BTC" });
expect(global.config.getAccountParams("second_account")).toStrictEqual({ "currency": "ETH" });
expect(global.config.getAccountParams("third_account")).toStrictEqual({});
expect(() => global.config.getAccountParams("unknown_account")).toThrow("No account named 'unknown_account'");
});

0 comments on commit ad55717

Please sign in to comment.