Exemple #1
0
def get_trading_signals_figure(order_reader: OrderReader, security_id: str,
                               provider: Union[str, Provider], level):
    security_type, _, _ = decode_security_id(security_id)
    security_factor = TechnicalFactor(security_type=security_type,
                                      security_list=[security_id],
                                      level=level,
                                      provider=provider)

    if df_is_not_null(security_factor.get_data_df()):
        print(security_factor.get_data_df().tail())

    # generate the annotation df
    order_reader.move_on(timeout=0)
    df = order_reader.get_data_df().copy()
    if df_is_not_null(df):
        df['value'] = df['order_price']
        df['flag'] = df['order_type'].apply(lambda x: order_type_flag(x))
        df['color'] = df['order_type'].apply(lambda x: order_type_color(x))
    print(df.tail())

    data, layout = security_factor.draw(render=None,
                                        figures=go.Candlestick,
                                        annotation_df=df)

    return go.Figure(data=data, layout=layout)
Exemple #2
0
def load_traders():
    global trader_domains
    global trader_names

    trader_domains = get_trader(return_type='domain')
    for trader in trader_domains:
        account_readers.append(
            AccountReader(trader_names=[trader.trader_name],
                          level=trader.level))
        order_readers.append(OrderReader(trader_names=[trader.trader_name]))

    trader_names = [item.trader_name for item in trader_domains]
Exemple #3
0
def update_trader_status(n_clicks, security_list, exchanges, codes, start_timestamp, end_timestamp, provider, level,
                         trader_name, real_time, kdata_use_begin_time, trader_index):
    if n_clicks and (trader_index is not None):
        if trader_name not in account_readers:
            trader = traders[trader_index][1](security_list, exchanges, codes, start_timestamp, end_timestamp, provider,
                                              level, trader_name, real_time, kdata_use_begin_time)
            process_run(trader)
            account_readers[trader.trader_name] = AccountReader(trader_names=[trader.trader_name], level=trader.level)
            order_readers[trader.trader_name] = OrderReader(trader_names=[trader.trader_name])

            return html.Label('trader is running'.format(trader_name))

    return html.Label('trader status')
Exemple #4
0
def get_trader_details(account_reader: AccountReader,
                       order_reader: OrderReader, provider: Union[str,
                                                                  Provider]):
    graph_list = []

    account_data, account_layout = account_reader.draw(render=None,
                                                       value_field='all_value',
                                                       keep_ui_state=False)

    for trader_name in account_reader.trader_names:
        graph_list.append(
            dcc.Graph(id='{}_account'.format(trader_name),
                      figure={
                          'data': account_data,
                          'layout': account_layout
                      }))

    df_account = account_reader.get_data_df()

    if df_is_not_null(df_account):
        df_orders = order_reader.get_data_df()

        if df_is_not_null(df_orders):
            grouped = df_orders.groupby('security_id')

            for security_id, order_df in grouped:
                security_type, _, _ = decode_security_id(security_id)
                security_factor = TechnicalFactor(security_type=security_type,
                                                  security_list=[security_id],
                                                  level=account_reader.level,
                                                  provider=provider)
                if df_is_not_null(security_factor.get_data_df()):
                    print(security_factor.get_data_df().tail())
                data, layout = security_factor.draw(figure=go.Candlestick,
                                                    render=None,
                                                    keep_ui_state=False)

                graph_list.append(
                    dcc.Graph(id='{}_signals'.format(security_id),
                              figure={
                                  'data': data,
                                  'layout': layout
                              }))

    return graph_list
Exemple #5
0
def get_trader_detail_figures(trader_domain: business.Trader,
                              account_reader: AccountReader,
                              order_reader: OrderReader):
    graph_list = []

    if account_reader:
        account_data, account_layout = account_reader.draw(
            render=None, value_fields=['all_value'], keep_ui_state=False)

        for trader_name in account_reader.trader_names:
            graph_list.append(
                dcc.Graph(id='{}-account'.format(trader_name),
                          figure={
                              'data': account_data,
                              'layout': account_layout
                          }))

    order_reader.move_on(timeout=0)
    df_orders = order_reader.get_data_df().copy()

    if df_is_not_null(df_orders):
        grouped = df_orders.groupby('security_id')

        for security_id, order_df in grouped:
            security_type, _, _ = decode_security_id(security_id)

            indicators = []
            indicators_param = []
            indicator_cols = []
            if trader_domain.technical_factors:
                tech_factors = simplejson.loads(
                    trader_domain.technical_factors)
                for factor in tech_factors:
                    indicators += factor['indicators']
                    indicators_param += factor['indicators_param']
                    indicator_cols += factor['indicator_cols']

            security_factor = TechnicalFactor(
                security_type=security_type,
                security_list=[security_id],
                start_timestamp=trader_domain.start_timestamp,
                end_timestamp=trader_domain.end_timestamp,
                level=trader_domain.level,
                provider=trader_domain.provider,
                indicators=indicators,
                indicators_param=indicators_param)

            # generate the annotation df
            df = order_df.copy()
            if df_is_not_null(df):
                df['value'] = df['order_price']
                df['flag'] = df['order_type'].apply(
                    lambda x: order_type_flag(x))
                df['color'] = df['order_type'].apply(
                    lambda x: order_type_color(x))
            print(df.tail())

            data, layout = security_factor.draw_with_indicators(
                render=None,
                annotation_df=df,
                indicators=indicator_cols,
                height=620)
            if trader_domain.real_time:
                result = get_current_price(security_list=[security_id])
                bid_ask = result.get(security_id)

                if bid_ask:
                    graph_list.append(
                        daq.LEDDisplay(id='ask',
                                       label=f'ask price',
                                       value=bid_ask[0],
                                       color="#00da3c"))

                    graph_list.append(
                        daq.LEDDisplay(id='bid',
                                       label=f'bid price',
                                       value=bid_ask[1],
                                       color="#FF5E5E"))

            graph_list.append(
                dcc.Graph(id='{}-{}-signals'.format(trader_domain.trader_name,
                                                    security_id),
                          figure={
                              'data': data,
                              'layout': layout
                          }))

    return graph_list
Exemple #6
0
# -*- coding: utf-8 -*-

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

from zvt.charts.dcc_components import get_trader_details
from zvt.domain import TradingLevel
from zvt.reader.business_reader import AccountReader, OrderReader

trader = 'cointrader'

account_reader = AccountReader(trader_names=['cointrader'],
                               level=TradingLevel.LEVEL_1MIN)
order_reader = OrderReader(trader_names=['cointrader'])


def serve_layout():
    layout = html.Div([
        html.Div(id='content'),
        dcc.Interval(
            id='interval-component',
            interval=10 * 1000,  # in milliseconds
            n_intervals=0)
    ])

    return layout


app = dash.Dash(__name__)
import dash_html_components as html
from dash.dependencies import Input, Output

from zvt.api.business import get_trader
from zvt.charts.dcc_components import get_trader_detail_figures
from zvt.domain import TradingLevel, CoinTickKdata
from zvt.reader.business_reader import AccountReader, OrderReader
from zvt.reader.reader import DataReader

trader = 'singlecointrader'
security = 'coin_binance_EOS/USDT'

trader_domain = get_trader(trader_name=trader, return_type='domain')[0]
account_reader = AccountReader(trader_names=['singlecointrader'],
                               level=TradingLevel.LEVEL_1MIN)
order_reader = OrderReader(trader_names=['singlecointrader'])
price_reader = DataReader(security_list=[security],
                          data_schema=CoinTickKdata,
                          provider='ccxt',
                          start_timestamp=trader_domain.start_timestamp,
                          end_timestamp=trader_domain.end_timestamp,
                          level=TradingLevel.LEVEL_TICK,
                          real_time=True)


def serve_layout():
    layout = html.Div([
        daq.LEDDisplay(id='current_price',
                       label="EOS/USDT current price",
                       value=price_reader.get_data_df()['price'][-1],
                       color="#FF5E5E"),
Exemple #8
0
def get_trader_detail_figures(trader_domain: business.Trader,
                              account_reader: AccountReader,
                              order_reader: OrderReader):
    graph_list = []

    account_data, account_layout = account_reader.draw(
        render=None, value_fields=['all_value'], keep_ui_state=False)

    for trader_name in account_reader.trader_names:
        graph_list.append(
            dcc.Graph(id='{}-account'.format(trader_name),
                      figure={
                          'data': account_data,
                          'layout': account_layout
                      }))

    df_orders = order_reader.get_data_df()

    if df_is_not_null(df_orders):
        grouped = df_orders.groupby('security_id')

        for security_id, order_df in grouped:
            security_type, _, _ = decode_security_id(security_id)
            # TODO:just show the indicators used by the trader
            security_factor = TechnicalFactor(
                security_type=security_type,
                security_list=[security_id],
                start_timestamp=trader_domain.start_timestamp,
                end_timestamp=trader_domain.end_timestamp,
                level=trader_domain.level,
                provider=trader_domain.provider,
                indicators=['ma', 'ma'],
                indicators_param=[{
                    'window': 5
                }, {
                    'window': 10
                }])

            # if df_is_not_null(security_factor.get_data_df()):
            #     print(security_factor.get_data_df().tail())

            # generate the annotation df
            order_reader.move_on(timeout=0)
            df = order_reader.get_data_df().copy()
            if df_is_not_null(df):
                df['value'] = df['order_price']
                df['flag'] = df['order_type'].apply(
                    lambda x: order_type_flag(x))
                df['color'] = df['order_type'].apply(
                    lambda x: order_type_color(x))
            print(df.tail())

            data, layout = security_factor.draw_with_indicators(
                render=None, annotation_df=df)

            graph_list.append(
                dcc.Graph(id='{}-{}-signals'.format(trader_domain.trader_name,
                                                    security_id),
                          figure={
                              'data': data,
                              'layout': layout
                          }))

    return graph_list
Exemple #9
0
# -*- coding: utf-8 -*-

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

from zvt.api.business import get_trader
from zvt.charts.dcc_components import get_trader_detail_figures
from zvt.domain import TradingLevel
from zvt.reader.business_reader import AccountReader, OrderReader

account_reader = AccountReader(trader_names=['cointrader'],
                               level=TradingLevel.LEVEL_1MIN)
order_reader = OrderReader(trader_names=['cointrader'])

account_readers = []
order_readers = []

# init the data
trader_domains = get_trader(return_type='domain')
for trader in trader_domains:
    account_readers.append(
        AccountReader(trader_names=[trader.trader_name], level=trader.level))
    order_readers.append(OrderReader(trader_names=[trader.trader_name]))

trader_names = [item.trader_name for item in trader_domains]


def serve_layout():
    layout = html.Div([