Пример #1
0
    def run(self, resp, candlesticks):
        """
		raise ValueError
		raise urllib3.exceptions.ProtocolError
		raise requests.exceptions.Chunked EncodingError
		"""
        for line in resp.iter_lines(1):
            if self.has_price(line):
                recv = from_byte_to_dict(line)
                self.execute_strategy(recv, candlesticks)

            #一定時間ごとに注文or決済が反映されたかを確認する
            if self.checking_freq == self.count:
                print(f'heart beat(span): {self.count}')
                #注文が反映されたか
                if self.trader.test_is_reflected_order() is True:
                    #WAIT_ORDER -> POSITION
                    self.trader.switch_state()

                #決済が反映されたか
                if self.trader.test_is_reflected_position() is True:
                    #WAIT_POSITION -> ORDER
                    self.trader.switch_state()
            self.count = 0 if self.checking_freq == self.count else (
                self.count + 1)
Пример #2
0
	def set_order(self, kind, notify):
		if kind is not None:
			resp = self.pricing.get_pricing_information(self.instrument)
			msg = from_byte_to_dict(resp.content)
			self.pre_price = float(msg['prices'][0]['bids'][0]['price'])
			self.kind = kind
			if notify is True:
				notify_from_line(f'Order[{self.kind}] : {self.pre_price}')
Пример #3
0
	def has_heartbeat(self, msg):
		if msg:
			msg = from_byte_to_dict(msg)
			if msg["type"] == "HEARTBEAT":
				return True
			else:
				return False
		else:
			return False
Пример #4
0
	def has_price(self, msg):
		if msg:
			msg = from_byte_to_dict(msg)
			if msg["type"] == "PRICE":
				return True
			else:
				return False
		else:
			return False
Пример #5
0
	def run(self, resp, candlesticks):

		"""

		戦略を元に売買を実行する

		Parameter
		---------
		resp : requests.response
			ストリーミングでの接続を行うためのレスポンスデータ
		candlesticks : dict
			取り扱うローソク足の種類と本数を格納した辞書型

		Exception
		---------
		ValueError
		urllib3.exceptions.ProtocolError
		requests.exceptions.Chunked EncodingError

		"""

		for line in resp.iter_lines(1):
			if self.has_price(line):
				recv = from_byte_to_dict(line)
				self.execute_strategy(recv, candlesticks)

			#一定時間ごとに注文or決済が反映されたかを確認する
			if self.checking_freq == self.count:
				print(f'heart beat(span): {self.count}')
				#注文が反映されたか
				if self.trader.test_is_reflected_order() is True:
					#WAIT_ORDER -> POSITION
					self.trader.switch_state()

				#決済が反映されたか
				if self.trader.test_is_reflected_position() is True:
					#WAIT_POSITION -> ORDER
					self.trader.switch_state()
			self.count = 0 if self.checking_freq == self.count else (self.count + 1)
Пример #6
0
	def set_close(self, notify):
		resp = self.pricing.get_pricing_information(self.instrument)
		msg = from_byte_to_dict(resp.content)
		self.post_price = float(msg['prices'][0]['bids'][0]['price'])
		if notify is True:
			notify_from_line(f'Close : {self.post_price}')