Skip to content

kancom/hq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

################################################################################

test task for HQ

################################################################################ Market Clients

Terminology 1 Common 1 Development 1

Recommendations for writing clients 3

Code 5

Test task 6

Common terminology 

Currency (Currency) - currency, type of money. For example, the US dollar or Bitcoin.

Currency pair - a pair of currencies, which means the ratio of one currency to another. As with simple math, order matters. For example, the US dollar to bitcoin.

Symbol (Symbol) - a symbol of a currency or currency pair. For example, USD or USDBTC.

Platform (Platform) - system (which is the basis for different activities). A software platform is a software system, usually with its own API.

Exchange (Exchange) - the institution for the conclusion of financial and commercial transactions. Often the exchange is implemented as a software platform accessible via the Internet anywhere in the world. Development

Connector (Connector) - in a broad sense, it is a class or group of classes through which we connect to the API of individual platforms in order to perform an action. In our case, such connectors are broken down into clients that lead the REST and WS interfaces of individual platforms to a single interface at the code level, that is, implemented in a class, as well as connectors in a narrow sense that clients use and implement more complex logic of using API platforms which includes reconnects, error handling, fixing downloaded and missing data that needs to be downloaded later and so on.

Client (Client) - a class through which we in the program refer to other external API: REST and WS API exchanges, for example. In other words, it converts an external general API into an API at the class level of a specific programming language. Usually, through the same software interface, you can access different platforms, whose own APIs differ.

Recommendations for writing clients 

Now only trades are made and only for three platforms: Binance, Bitfinex and BitMEX (basic source code), so it is obvious that the code will change and should not be taken as something complete or, moreover, dogma. The remaining methods and clients for other platforms can and should be done on the model. To quickly deal with the code, below are some of the principles and the general scheme by which it was written.

To understand the code, it is recommended to go from files binance.py, bitfinex.py, bitmex.py, that is, from examples of specific implementations to the base, to base classes. After that, you can go back: from base classes to specific implementations. The result of the work on adding new clients and implementing new functions will be similar to the code from these three files: binance.py, bitfinex.py, bitmex.py.

The client library for different platforms of exchanges is based on the position that all exchanges mostly implement the same functionality: they all give a list of orders, trades and so on. But they do it in different ways. The main difference is in the data format. Therefore, in the code, the converter was taken as the basis, which converts the format of each platform into our common format.

This leads to the main goal of the library: to bring all (ideally all) stock exchanges to a single format, or to provide access to all exchanges through a single interface. Our library should be considered as a single point of access to all exchanges in general.

The format is based on terms and what they mean. Each stock exchange has differences in terminology. Our goal is to eliminate these differences by developing a single, most accurate system of terms. This is the most important, and therefore in the document it is at the very beginning.

The minimum that the library provides is an interface, an empty base class with given function signatures: their names and parameters.

Second: this is the converter of our names into the names of a specific platform. For many exchanges, it will be enough to configure the matching dictionaries of these names to make it work.

For the rest, you will have to make certain adjustments to the converter to convert certain values ​​and other things. This is provided by splitting the process of parsing and transformation into separate methods-steps, each of which can be easily redefined in a subclass. Thus, in the client itself, changes are made only in exceptional cases. Probably, platform APIs will come across that will require significant rework in the base classes of the library.

Note.

The library code is not perfect and is in the process of development. The drawbacks of the main library are drawbacks, that is, they need to be fixed, and not repeated or taken as a model for their code.

Code 

To be able to easily navigate the code, we must always be sure that the same words and the names of variables, classes and methods mean the same concepts. In other words, the name must exactly match its value, the form - the content and vice versa.

For example, if we convert request parameters (params) into platform parameters, then we can no longer use the former name params, but should name the new variable platform_params. This not only makes the code understandable, but also allows you to avoid many errors due to a misunderstanding, and also speeds up development, since you no longer need to keep track of the origin of the value of a variable if we need to make changes in the little known or forgotten old code.

Test 

It is necessary to understand the original base classes and, using them, do the following:

Write a client class (along with a converter) for the OSTAx REST API v1, which implements 2 functions:
    Getting trades (fetch_trades_history method)
    Getting candles (kline / candlestick) (fetch_candles method) 
Write a client class (along with a converter) for Websocket API v1 of the Okex Exchange, which implements 2 functions:
    Receiving trades
    Getting candles (kline / candlestick) 

Base class source code is https://drive.google.com/file/d/1LGvnjVycOB8Mu2Wxc9ov5fEtFpe2eleS/view

Okex Exchange API Documentation - https://github.com/okcoin-okex/API-docs-OKEx.com/tree/master/API-For-Spot-EN

To check the efficiency of the written code, you can use the “run_demo.py” file in the project root.################################################################################

hqlib

Common library for HyperQuant projects on Python

Install

pipenv install

Run demo code

pipenv run python run_demo.py

About

test task for ТРЭЙДБОТМАРКЕТ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages