Exemplo n.º 1
0
 def test__get_uri_when_unsigned(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertEqual(
         sut._BiPy__get_uri(bipy.BiPy.ENDPOINT_DEPTH,
                            False,
                            symbol='TRXBTC',
                            limit=20), self.RESULT_GET_URI_UNSIGNED)
Exemplo n.º 2
0
def main():
    #constants and config
    POLL_INTERVAL_SECONDS = 5
    TRADING_PAIR = 'TRXBTC'
    #load config
    config_mgr = util.ConfigManager('_config.json')
    #with open('_config.json', 'r') as f:
    config = config_mgr.get_config()

    #logon to binance
    secret = config['DEFAULT']['SECRET_KEY']
    key = config['DEFAULT']['API_KEY']
    #create client
    client = bp.BiPy(key, secret)
    order_watch_list = []
    #ping test
    ping_time(client)
    #load orders into watch-list
    get_orders(client, order_watch_list, symbol=TRADING_PAIR)
    first_order = get_min_order_id(order_watch_list)
    print(
        f'First open order id is: {first_order}. All orders will be fetched in respct of this until restart.'
    )

    #trade
    while True:
        ping_time(client)
        #check orders
        get_orders(client,
                   order_watch_list,
                   symbol=TRADING_PAIR,
                   orderId=str(first_order))
        #update watch list

        #evalaute watchlist
        price = client.get_price(symbol=TRADING_PAIR)['price']
        print(f'Current {TRADING_PAIR} price: {price}')
        #print(f'current {TRADING_PAIR} price: {price[1]}')
        #order_print(current_orders)
        #place orders
        time.sleep(POLL_INTERVAL_SECONDS)
Exemplo n.º 3
0
def main():
    # constants and config
    poll_interval_seconds = 5
    trading_pair = 'TRXBTC'
    # load config
    with open('_config.json', 'r') as f:
        config = json.load(f)

    # logon to binance
    secret = config['DEFAULT']['SECRET_KEY']
    key = config['DEFAULT']['API_KEY']
    # create client
    client = bp.BiPy(key, secret)
    order_watch_list = []
    # ping test
    ping_time(client)
    # load orders into watch-list
    get_orders(client, order_watch_list, symbol=trading_pair)
    first_order = get_min_order_id(order_watch_list)
    print(
        f'First open order id is: {first_order}. All orders will be fetched in respect of this until restart.'
    )

    # trade
    while True:
        ping_time(client)
        # check orders
        get_orders(client,
                   order_watch_list,
                   symbol=trading_pair,
                   orderId=str(first_order))
        # update watch list

        # evaluate watchlist
        price = client.get_price(symbol=trading_pair)['price']
        print(f'Current {trading_pair} price: {price}')
        # print(f'current {TRADING_PAIR} price: {price[1]}')
        # order_print(current_orders)
        # place orders
        time.sleep(poll_interval_seconds)
Exemplo n.º 4
0
import json
import bipy as bp

with open('_config.json', 'r') as f:
	config = json.load(f)

secret = config['DEFAULT']['SECRET_KEY']
key = config['DEFAULT']['API_KEY']

symbol = 'BTCUSDT'

client = bp.BiPy(key, secret)

resp_obj = client.get_all_orders(symbol=symbol)
# print(resp_obj)

print(resp_obj)

for r in resp_obj:
		if r['status'] == 'NEW':
			print('ORDER:')
			for i in r:
				print(f'	{i} : {r[i]}')

'''
watch open orders:
	when they fill:
		place 1% sell for 50% of total amount
		watch price till 0.5% futher rise 
			place stop-loss at original + 0.5%
			every 0.5% rise, lift stop-loss by 0.5%
Exemplo n.º 5
0
 def test__get_uri_when_unsigned_no_parameters(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertEqual(sut._BiPy__get_uri(bipy.BiPy.ENDPOINT_PRICE, False),
                      self.RESULT_GET_URI_UNSIGNED_NO_PARAMETERS)
Exemplo n.º 6
0
 def test__get_uri_when_signed(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertRegexpMatches(
         sut._BiPy__get_uri(bipy.BiPy.ENDPOINT_ALL_ORDERS,
                            True,
                            symbol='TRXBTC'), self.REGEX_GET_URI_SIGNED)
Exemplo n.º 7
0
 def test__sign_request(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertEqual(sut._BiPy__sign_request(self.RESULT_PARAMETER_LIST),
                      self.RESULT_SIGNED_PARAMETER_LIST)
Exemplo n.º 8
0
 def test__get_parameters(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertEqual(
         sut._BiPy__get_parameters(symbol='TRXBTC',
                                   timestamp=1550964774431),
         self.RESULT_PARAMETER_LIST)
Exemplo n.º 9
0
 def test__get_headers(self):
     sut = bipy.BiPy('key', 'secret')
     self.assertEqual(sut._BiPy__get_headers(), {'X-MBX-APIKEY': 'key'})