aggr icon indicating copy to clipboard operation
aggr copied to clipboard

[Suggestion] ccxt library implementation for future trading pane options

Open yerb opened this issue 3 years ago • 6 comments

Is it possible to implement ccxt library for API interaction with exchanges?

https://github.com/ccxt/ccxt

For example for future possibility to make it easier to create "Trading" and "Automation" panes for directly executing API requests to exchanges.

yerb avatar Jun 14 '21 11:06 yerb

Would be nice to be able to see open positions, stop loss, take profit. as well as edit SL/TP

lmvdz avatar Jun 14 '21 22:06 lmvdz

Would be funny to place trades on aggr 😄

I never used CCXT, considered it at first but I think it never really delivered the promised WS support

WebSocket and FIX implementations in JavaScript, PHP, Python are available in CCXT Pro, which is a professional addon to CCXT with support for WebSocket streams.

^ from their readme... this doesn't look too promising to me

Also about CCXT, performance on aggr trade is a major concern when you open 15+ very busy ws streams in the browser, thus the choice for implementing custom - lightweight - interfaces when communicating with exchange (src/exchanges/).

Tucsky avatar Jun 17 '21 22:06 Tucsky

Also most exchange don't support placing trades through websocket, just streaming positions update / fills REST API requires a server because of CORS issue or going through some kind of cors proxy (like aggr.trade do when fetching exchanges pairs). But wouldn't go so well with private exchanges api keys, lmao Wrapping aggr.trade in Electron can fix that issue.

For this repo (official aggr.trade repo) I can only see allowing to connect to private apis to stream orders & fills Draw orders on chart (horizontal lines) etc .

Placing /modifying orders : good side project I guess, convert the project to Electron and continue from there

Tucsky avatar Jun 17 '21 22:06 Tucsky

This is how I would go with streaming orders and fills on aggr.trade

  • in the pane settings (settings.ts for model, Settings.vue for view) have a section dedicated to api keys, for each exchanges (each one have their own process, own keys names, most of the time it's an api key and a secret key but this would require some research)
  • once a key is entered, validated in the vue (required filled are filled and have the right length etc) , send it to the worker (aggregator.worker.ts)
  • have an "authenticated" flag on each exchanges (src/worker/exchanges/*.ts) which will determine if we need to login or already logged
  • when a orders / fills pane is added, send message to worker asking to connect to whatever channel the exchange have for this kind of stream. (Login first then subscribe)
  • stream orders, or fills (each exchanges/*.ts) normalize (exchange.ts), dispatch to vue (aggregator.worker.ts -> aggregatorService.ts)
  • the pane listen to that and display every orders, (maybe grouped by pairs)
  • notification when fill, play some song as well
  • the chart should start listen as well IMO, for each open orders matching the pane's markets add a line on the chart and keep track of them (for adding/deleting without duplicates etc)

( just taking notes 📝)

Tucsky avatar Jun 17 '21 22:06 Tucsky

Thank you for extensive explanations. And your notes :)

I was fiddling with ccxt and discovered that it doesn't do the job well at all. It would probably be better to add official API connectors for each exchange, which is a whole project on itself.

For now I will try to make a simple "trading" pane according to your notes :) Just basic price, amount, buy and sell buttons for deribit, just to to get my feet wet.

The goal is to make some advanced order tools like this https://github.com/yerb/deribit-scaled-orders

yerb avatar Jun 23 '21 19:06 yerb

I was able to get Electron working pretty easily, then I went ahead and added the exchange I use (Phemex) to get a bit familiar with the inner workings of aggr. #40

In the Electron version I've added:

  • API Key/Secret fields to each of the exchanges in the settings and stored them in the store.
    • To get authenticated I know Phemex requires every request have calculated headers using API Key/Secret
    • Bittrex had their system setup where you authenticate once every X minutes and receive a token which is passed along as a header as well
    • Mainly we need to cover all bases when it comes to using API Keys/Secrets to make requests.
  • Used Electron ipc + axios to make the calls to avoid CORS like @Tucsky suggested

lmvdz avatar Jun 24 '21 02:06 lmvdz

That was an interesting read. This issue is a bit antiquated and drifted out of the initial scope. Closing this down.

adeacetis avatar Jun 09 '23 09:06 adeacetis