GithubHelp home page GithubHelp logo

economicnetwork / archon Goto Github PK

View Code? Open in Web Editor NEW
75.0 16.0 32.0 936 KB

Trading framework

License: MIT License

Dockerfile 0.05% Python 99.95%
trading cryptocurrency algotrading exchange algo-trading algorithmic-trading

archon's People

Contributors

tebzzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

archon's Issues

order router

introduce order-route

orders can be routed, i.e. the exchange is selected based on any criteria. start with only limit-price order

fees

incorporate fees
maker/taker per exchange

broker and arch

currently broker and arch are redundant. there should be only a single broker interface.

  • rename broker to facade
  • rename arch to broker

ubuntu install doc

  1. install python3

https://docs.python-guide.org/starting/install3/linux/

  1. install python3-pip
sudo apt-get update -y
sudo apt-get -y install python3-pip
  1. git clone [email protected]:economicnetwork/archon.git

  2. inside archon directory

pip3 install -r requirements.txt

create file apikeys.toml, see apikeys_example.toml as an example

(create file conf.toml, see example_conf.toml as an example)

  1. try running examples

export PYTHONPATH=/Users/someuser/archon
cd examples
python3 balance_example.py

  1. install mongo

mongodb

multi-user

currently archon broker is a single-user interface/gateway. the api keys are set only once and then the clients communication with exchange.

multi-user requires:

  • some identifier for users. this will be handled by a service which users archon
  • handling several connections to exchange

PnL calculation

for realised PnL

get all transactions
for each symbol
if its sell
volume weight exit price - volume weighted entry price

for unrealised PnL

average entry
(value current balance)
(not considering deposits and withdraws)

bitmex UUID

File "/Users/ben/archon/archon/exchange/bitmex/bitmex.py", line 401, in _query_bitmex
    self.logger.error("429 Too Many Requests for url. Request: %s \n %s" % (url, json.dumps(postdict)))

raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type UUID is not JSON serializable

order states

INITIALIZING: 'INITIALIZING',
// Created and send to the exchange, but no acknowledgement received yet
SUBMITTED: 'SUBMITTED',
// Order is open on the exchange
OPEN: 'OPEN',
// Order is completely filled
FILLED: 'FILLED',
// Order was succesfully cancelled
CANCELLED: 'CANCELLED',
// Order was rejected by the exchange
REJECTED: 'REJECTED',
ERROR: 'ERROR'

add bitmex

add bitmex exchange

  • account for ability to short
  • account for margin

bitmex orderbook timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "store_prices.py", line 77, in <module>
    show()
  File "store_prices.py", line 40, in show
    book = bitmex_get_book()
  File "store_prices.py", line 35, in bitmex_get_book
    book = abroker.afacade.get_orderbook(smarket, exc.BITMEX)
  File "/Users/ben/archon/archon/broker/facade.py", line 190, in get_orderbook
    ob = client.market_depth(market,depth=bookdepth)
  File "/Users/ben/archon/archon/exchange/bitmex/bitmex.py", line 124, in market_depth
    result = self._query_bitmex(path=path, query={'symbol': symbol, 'depth': depth})
  File "/Users/ben/archon/archon/exchange/bitmex/bitmex.py", line 464, in _query_bitmex
    return self._query_bitmex(path, query, postdict, timeout, verb)
  File "/Users/ben/archon/archon/exchange/bitmex/bitmex.py", line 458, in _query_bitmex
    raise ConnectionError("bitmex error")
archon.exchange.bitmex.bitmex.ConnectionError: bitmex error

examples complete

for all exchanges

  • market transactions
  • trades
  • candles
  • orderbook
  • openorders
  • balances

bitmex orderbook stream

bitmex_test_public

Traceback (most recent call last):
  File "bitmex_test_public.py", line 30, in <module>
    run()
  File "bitmex_test_public.py", line 24, in run
    logger.info("Market Depth: %s" % ws.market_depth())
  File "/home/mm/.local/lib/python3.6/site-packages/bitmex_websocket.py", line 91, in market_depth
    return self.data['orderBookL2']
KeyError: 'orderBookL2'

balance in broker

currently the broker assumes that balances belong to an agent. in the future agent should be registered with broker and have it assign any balance

facade log

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/root/trading/archon/archon/brokersrv/feeder.py", line 101, in run
self.publish_bitmex()
File "/root/trading/archon/archon/brokersrv/feeder.py", line 75, in publish_bitmex
book = self.abroker.afacade.orderbook(self.mex_sym, exc.BITMEX)
File "/root/trading/archon/archon/brokersrv/facader.py", line 87, in orderbook
self.logger.debug("get orderbook %s %i" %(str(market),exchange))
TypeError: %i format: a number is required, not str

windows setup

import os
if os.name == 'nt':
.... windows part
elif os.name == ''posix':
... mac part

bitmex: import time

"[archon.exchange.bitmex.bitmex] init bitmex - (2019-03-13 15:08:24,818) 56
name 'time' is not defined"

bitmex: duplicate oid

[archon.exchange.bitmex.bitmex] Unhandled Error: 400 Client Error: Bad Request for url: https://www.bitmex.com/api/v1/order {"error":{"message":"Duplicate clOrdID","name":"HTTPError"}} - (2019-03-08 13:27:06,162) 457

Object of type 'UUID' is not JSON serializable

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/mm/exch/makers/strat.py", line 150, in run
    self.handle_books(book)
  File "simple_maker.py", line 232, in handle_books
    self.handle_no_position()
  File "simple_maker.py", line 174, in handle_no_position
    result = self.abroker.submit_order_post(order, exc.BITMEX)
  File "/home/mm/exch/archon/archon/brokersrv/brokerservice.py", line 274, in submit_order_post
    result = self.afacade.submit_order_post(order, exchange)
  File "/home/mm/exch/archon/archon/facader.py", line 159, in submit_order_post
    order_result = client.buy_post(quantity=qty, price=order_price, symbol=market)
  File "/home/mm/exch/archon/archon/exchange/bitmex/bitmex.py", line 216, in wrapped
    return fn(self, *args, **kwargs)
  File "/home/mm/exch/archon/archon/exchange/bitmex/bitmex.py", line 269, in buy_post
    return self.place_order_post(symbol, directional_quantity, price)
  File "/home/mm/exch/archon/archon/exchange/bitmex/bitmex.py", line 216, in wrapped
    return fn(self, *args, **kwargs)
  File "/home/mm/exch/archon/archon/exchange/bitmex/bitmex.py", line 328, in place_order_post
    return self._query_bitmex(path=endpoint, postdict=postdict, verb="POST")
  File "/home/mm/exch/archon/archon/exchange/bitmex/bitmex.py", line 423, in _query_bitmex
    self.logger.error("429 Too Many Requests for url. Request: %s \n %s" % (url, json.dumps(postdict)))
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'UUID' is not JSON serializable

0x integration

0x is a Ethereum-DEX protocol. archon has a generic broker architecture which can allow to trade against CEX or DEX at the same time. archon's role is to make it easier to use exchange wrappers and any exchange communication by adding middleware i.e. a "trading broker" described here [1]. the middleware makes it easy to write strategy code by bridging polling or streaming protocols, track orders and execution. 0x can be integrated by adding a exchange gateway to the broker

the calls needed are:

  • get open orders
  • get balance
  • get orderbook
  • submit order
  • cancel order
  • get transaction history

the broker will poll the smart contracts/relayers. the frontend of archon can be used to display the relevant data i.e. orderbooks, balances, orders, executions

relevant libraries that can be used is the python backend from makerdao
https://github.com/makerdao/pymaker
https://github.com/makerdao/pyexchange
https://github.com/0xProject/0x-monorepo/

[1] https://gist.github.com/benjyz/d9faef0926b20473716cf28286df77ed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.