Пример #1
0
def coin_avg_price_change(coin_list, time_gap):
    t_rate = []
    for c_name in coin_list:
        c = Coin(c_name, "usdt")
        k_line = spotAPI.get_kline(c.get_instrument_id(), '', '', 60)
        now = float(k_line[0][4])
        last = float(k_line[time_gap][1])
        rate = (now - last) / last * 100
        t_rate.append(rate)
    return t_rate
Пример #2
0
                usdt_size = float(usdt_itme['size'])
                total_fee += float(fee_item['fee'])
                price = float(coin_item['price'])
                created_at = fee_item['created_at']
                if coin_item['side'] == 'buy' and usdt_itme['side'] == 'sell':
                    total_coin += coin_size
                    total_usdt -= usdt_size
                    print('%s: buy %.1f eos at price: %.4f, usdt: -%.4f' % (created_at, coin_size, price, usdt_size))
                elif coin_item['side'] == 'sell' and usdt_itme['side'] == 'buy':
                    total_coin -= coin_size
                    total_usdt += usdt_size
                    print('%s: sell %.1f eos at price: %.4f, usdt: +%.4f' % (created_at, coin_size, price, usdt_size))
                time.sleep(0.1)
        print('after %d transactions, total_coin: %.4f, total_usdt: %.4f, total_fee: %.4f\r\n' % (
        count, total_coin, total_usdt, total_fee))
        time.sleep(1)


if __name__ == '__main__':
    coin = Coin("eos", "usdt")
    instrument_id = coin.get_instrument_id()
    df = get_spot_macd(spotAPI, instrument_id, 300)
    diff = list(df['diff'])
    dea = list(df['dea'])
    time = list(df['time'])
    for i in range(1,10):
        print('time: ' + str(time[-1 * i]) + ", diff: " + str(diff[-1 * i]) + ", macd: " + str(2 * (diff[-1 * i] - dea[-1 * i])))



Пример #3
0
from trade import buyin_less, buyin_more, ensure_buyin_less, \
    ensure_buyin_more, cancel_uncompleted_order, gen_orders_data, send_email, buyin_more_price, \
    buyin_less_price, pend_order
from strategy import get_macd
from entity import Coin, Indicator, DealEntity
from config_quick import vol_1m_line, vol_3s_line, vol_1m_bal, vol_3s_bal, incr_5m_rate, incr_1m_rate, incr_10s_rate
import time
import json

import traceback
from collections import deque
import websocket
import codecs

# 默认币种handle_deque
coin = Coin("etc", "usdt")
time_type = "quarter"
file_transaction, file_deal = coin.gen_future_file_name()

deque_min = deque()
deque_10s = deque()
deque_3s = deque()
deque_5m = deque()
latest_price = 0
ind_1min = Indicator(60)
ind_10s = Indicator(10)
ind_3s = Indicator(3)
ind_5m = Indicator(300)
more = 0
less = 0
last_avg_price = 0
Пример #4
0
try:
    import thread
except ImportError:
    import _thread as thread
from utils import timestamp2string, cal_rate, inflate, string2timestamp
from strategy import get_spot_macd, check_trend
from entity import Coin, Indicator, DealEntity
from trade_spot_v3 import sell_all_position, buy_all_position
import time
from config_strict import spotAPI
import traceback
import codecs

# 默认币种handle_deque
coin = Coin("okb", "usdt")
instrument_id = coin.get_instrument_id()
file_transaction, file_deal = coin.gen_future_file_name()
buy_thread = 0.00005

if __name__ == '__main__':
    more = 0
    last_macd = 0
    first = True
    order_id_queue = []
    last_minute_ts = 0
    del_list = []
    while True:
        try:
            ts = time.time()
            # 获取未完成订单
def on_close(ws):
    print("### closed ###")


def on_open(ws):
    print("websocket connected...")
    ws.send(
        "{'event':'addChannel','channel':'ok_sub_futureusd_%s_trade_quarter'}"
        % coin.name)


if __name__ == '__main__':
    if len(sys.argv) > 1:
        coin_name = sys.argv[1]
        coin = Coin(coin_name, 'usdt')
        time_type = coin.name.upper() + "-USD-190329"
        file_transaction, file_deal = coin.gen_future_file_name()
        ws = websocket.WebSocketApp(
            "wss://real.okex.com:10440/websocket/okexapi?compress=true",
            on_message=on_message,
            on_error=on_error,
            on_close=on_close)
        ws.on_open = on_open
        while True:
            ws.run_forever(ping_interval=20, ping_timeout=10)
            print("write left lines into file...")
            with codecs.open(file_deal, 'a+', 'UTF-8') as f:
                f.writelines(write_lines)
                write_lines = []
    else:
Пример #6
0

def on_open(ws):
    print("websocket connected...")
    ws.send("{\"op\": \"subscribe\", \"args\": [\"spot/ticker:%s-USDT\"]}" %
            (coin.name.upper()))
    ws.send(
        "{\"op\": \"subscribe\", \"args\": [\"swap/ticker:%s-USD-SWAP\"]}" %
        (coin.name.upper()))


if __name__ == '__main__':
    if len(sys.argv) > 2:
        coin_name = sys.argv[1]
        # 默认币种handle_deque
        coin = Coin(coin_name, "usdt")
        instrument_id = coin_name.upper() + INSTRUMENT_ID_LINKER + 'USDT'
        future_instrument_id = coin.get_future_instrument_id()
        swap_instrument_id = instrument_id.split(
            INSTRUMENT_ID_LINKER)[0].upper() + '-USD-SWAP'
        print('swap_instrument_id: ' + swap_instrument_id)
        file_transaction, file_deal = coin.gen_file_name()
        config_file = sys.argv[2]
        if config_file == 'config_mother':
            from config_mother import leverAPI, futureAPI, swapAPI
        # elif config_file == 'config_son1':
        #     from config_son1 import spotAPI, okFuture, futureAPI
        # elif config_file == 'config_son3':
        #     from config_son3 import spotAPI, okFuture, futureAPI
        else:
            print(
Пример #7
0
                break
            else:
                return False
        return True
    except Exception as e:
        info = traceback.format_exc()
        log_trade_v3("In future sell_more func, error: %s\r\n traceback: %s" %
                     (repr(e), info))
        return False


def get_latest_future_price(future_api, future_instrument_id):
    try:
        ticker = future_api.get_specific_ticker(future_instrument_id)
        latest_future_price = float(ticker['last'])
        return latest_future_price
    except Exception as e:
        info = traceback.format_exc()
        log_trade_v3(
            "In get_latest_future_price func, error: %s \r\n traceback: %s" %
            (repr(e), info))
        return False


if __name__ == '__main__':
    from config_mother import futureAPI
    coin_name = "eos"
    coin = Coin(coin_name, "usdt")
    print(coin.get_future_instrument_id())
    print(get_latest_future_price(futureAPI, coin.get_future_instrument_id()))
Пример #8
0
            ret = futureAPI.take_order('', time_type, 4, '', amount, 1, lever_rate)
            log_trade_v3('In future sell_less func, sell less result: %s, time: %s' % (ret, now_time))
            if ret and ret['result']:
                break
            else:
                return False
        return True
    except Exception as e:
        info = traceback.format_exc()
        log_trade_v3("In future sell_less func, error: %s\r\n traceback: %s\r\n time: %s" % (repr(e), info, now_time))
        return False


if __name__ == '__main__':

    from config_mother import futureAPI
    time_type = "EOS-USD-190329"
    coin_name = "eos"
    # future api test
    coin = Coin(coin_name, "usdt")
    future_instrument_id = coin.get_future_instrument_id()
    result = futureAPI.get_coin_account(coin.name)
    print(result)
    # result = buyin_less(futureAPI, coin.name, future_instrument_id, 0.3)
    # time.sleep(3)
    # thread.start_new_thread(ensure_buyin_less, (futureAPI, coin.name, future_instrument_id, 0.3))
    # while True:
    #     time.sleep(10)
    #     holding_position = futureAPI.get_specific_position(future_instrument_id)
    #     log_trade_v3 (holding_position)
Пример #9
0
import codecs
try:
    import thread
except ImportError:
    import _thread as thread
from entity import Coin, DealEntity, Indicator, handle_deque
from okex_utils import timestamp2string, cal_rate, send_email, inflate
from strategy import get_macd
from collections import deque
from trade import buyin_less, buyin_more, ensure_buyin_less, \
    ensure_buyin_more, okFuture, cancel_uncompleted_order, gen_orders_data
import json
import time

# 默认币种
coin = Coin("eos", "usdt")
time_type = "quarter"
file_transaction, file_deal = coin.gen_file_name()
write_lines = []

deque_min = deque()
deque_10s = deque()
deque_3s = deque()
deque_5m = deque()
latest_price = 0
ind_1min = Indicator(60)
ind_10s = Indicator(10)
ind_3s = Indicator(3)
ind_5m = Indicator(300)
more = 0
less = 0
Пример #10
0
    import thread
except ImportError:
    import _thread as thread
from okex_utils import timestamp2string, cal_rate, inflate, cal_weighted
from trade_v3 import ensure_sell_more, ensure_sell_less, ensure_buyin_less, ensure_buyin_more, buyin_more, buyin_less, sell_less_batch, sell_more_batch
from entity import Coin, Indicator, DealEntity
from config_avg import futureAPI
import time
import json

import traceback
import websocket
import codecs

# 默认币种handle_deque
coin_etc = Coin("etc", "usdt")
coin_btc = Coin("btc", "usdt")
coin_ltc = Coin("ltc", "usdt")
coin_eth = Coin("eth", "usdt")
coin_eos = Coin("eos", "usdt")
coin_xrp = Coin("xrp", "usdt")

time_type = "EOS-USD-190329"
file_transaction, file_deal = coin_eos.gen_future_file_name()

latest_price = 0

more = 0
less = 0
buy_price = 0
last_5min_macd_ts = 0